Anne Hathaway headlines a movie that’s got a lot to say about the perils of fame.Women of a certain age (that is, my age) feel like they grew up alongside Anne Hathaway, because, well, we did. We were awkward teens together when she made “The Princess Diaries” in 2001. We felt ourselves to be put-upon entry-level hirelings right when “The Devil Wears Prada” came out in 2006. We understood her broken-down narcissistic addict in “Rachel Getting Married,” because who couldn’t? And we watched the Hathaway backlash, pegged to public perception that she was trying too hard, and worried that people saw us the same way.Now we’re 40-ish. We know for sure that Gen Z considers millennials to be cringe, and, thankfully, we no longer feel the need to care. The greatest gift of reaching middle age is having settled into yourself, and that is apparently what Hathaway, age 41, has done. She has been through the celebrity wringer (and more) and come out the other side looking radiant, with a long list of credits in movies that swing from standard commercial fare to auteurist masterpieces.This is perhaps why it’s so satisfying to see her name come first — alone, before the title credit — in “The Idea of You,” which is on its surface a relatively fluffy little film. Based on the sleeper hit novel by Robinne Lee, “The Idea of You” is plainly fantasy, in the fan fiction mold, that poses the question: What if Harry Styles, the British megastar and former frontman of One Direction, fell madly in love with a hot 40-year-old mom? In this universe, the Styles character is Hayes Campbell (Nicholas Galitzine), the British frontman of a five-member boy band called August Moon.Hathaway plays Solène Marchand, an art gallery owner whose arrogantly useless ex-husband, Daniel (Reid Scott), buys v.i.p. meet-and-greet tickets for their 16-year-old daughter, Izzy (Ella Rubin), and her two best friends, all of whom were huge August Moon fans … in the seventh grade. The event is at Coachella, and Daniel is set to take the teenagers but backs out at the last second, citing a work emergency. Solène reluctantly agrees to take them, and while at the festival, mistakes Hayes’s trailer for the bathroom. They meet, it’s cute, and you can guess what happens next.Or can you? It was clear about 10 minutes into the movie that what was required for enjoyment was to surrender to the daydreaming, and so, with very little internal protest, I did. How could I resist? Solène is smart, competent, kind and secure; she has great hair and a great wardrobe; and most important, she seems like a real person, even if the situation in which she finds herself greatly stretches the bonds of credibility. More than once, I was struck by how authentically 40 Solène seemed to me — a woman capable of making her own decisions, even ones she thinks might be ill-advised — and how weirdly rare it is to see that kind of character in a movie. She has a kid, and friends, and a career. She reads books and looks at art, and she is flattered by this 24-year-old superstar’s attention but takes a long time to come around to the idea that it may not be a joke.Solène also feels real shame and real resolve in the course of the winding fairy tale story, which predictably has to go south. But most of all, she’s in a movie that doesn’t try to shame her, or patronize her, or make her appear ridiculous for having desires and fantasies of her own. She’s just who she is, and it’s simple to understand her appeal to someone whose life has never been his own.Directed by Michael Showalter, who wrote the adapted screenplay with Jennifer Westfeldt, “The Idea of You” succeeds mostly because of Hathaway’s performance, though she and Galitzine spark and banter pleasurably (and he can dance and sing, too). It tweaks the novel in a number of ways — Hayes is older than the book’s character, for one thing — and also seems to implicitly know it’s a movie, and that movies have a strange relationship with age-gap romances.In fact, that’s one of its strengths. Several times, characters remark on the double standard attached to people’s judgment of Solène and Hayes’s relationship, hypothesizing that in a gender-swapped situation, people would be high-fiving the older man who landed the hot younger star. Sixteen years looks like a lot on paper, but in the movies, at least, it is barely a blip.That musing is interesting enough, if a familiar one. More fascinating in “The Idea of You” is its treatment of the cage of celebrity. Hayes seems mature compared with his bandmates and the girls who follow them around, but he’s also clearly stuck in some kind of arrested development. And I do mean stuck: He is self-aware enough to tell Solène, plaintively, that he auditioned for the band when he was 14 and not much has changed beyond his level of fame. He wants a life beyond the spotlight, badly.And that’s just what he can’t get. Neither can Solène, nor, eventually, anyone around her. The idea of living a quiet life might obviously be out of reach, but the added elements of tabloid news and rabid fans unafraid to treat Hayes as if they know him make things far worse. The film starts to feel a little like the tale of a monster, but the monster is parasociality, encouraged by the illusion of intimacy that the modern superstar machine relies on to keep selling tickets and merch and albums and whatever else keeps the star in the spotlight.It’s probably coincidental that “The Idea of You” comes on the heels of Taylor Swift’s latest album, “The Tortured Poets Department,” on which she strongly implies that her carefully cultivated fandom has made her love life a nightmare. But spiritually, at least, they’re of a piece — even if the origins of the film’s plot seem as much borne of parasociality as a critique of it. And that makes Hathaway’s performance extra poignant. She’s been dragged into that buzz saw before. And somehow, she’s figured out how to make a life on the other side of it.The Idea of YouRated R for getting hot and heavy, plus some language. Running time: 1 hour 55 minutes. Watch on Prime Video. More