The sheer overwhelming gall it must take to direct a sequel to Stanley Kubrick’s The Shining – as vaunted a horror masterpiece as any committed to celluloid – is probably only measurable in tonnage. But not only did Mike Flanagan pull it off, he’s made a masterfully horrifying motion picture in its own right. Doctor Sleep is a stunning and frightening film about trauma and substance abuse, it’s a worthy successor to The Shining, and as if that weren’t enough, it’s also a complex work of thoughtful film criticism.

Stephen King’s original novel for The Shining was adapted rather loosely into Kubrick’s 1980 film. In both versions, the Torrance family – Jack (Jack Nicholson), Wendy (Shelley Duvall) and Danny (Danny Lloyd) – venture to the Overlook Hotel in the dead of winter and fall prey to supernatural influences, which turn Jack against his family by preying on his weakness for alcohol. There were obvious deviations from the events of the novel, but perhaps the biggest difference is that Kubrick’s interpretation offers little sympathy to Jack Torrance and his personal plight. He was always a powder keg, and the Overlook Hotel lit his long fuse.

Doctor Sleep picks up decades later, when Danny, or rather “Dan” (Ewan McGregor), has fallen into the same pattern of substance abuse as his father. Hitting rock bottom, and only using his “Shining” when the demons from the Overlook come back to haunt him, he eventually finds some solace in a small town where his past is largely forgotten. He goes to Alcoholics Anonymous meetings, he takes a job working as an orderly at a nursing home, and his uncanny ability to tell which patients are about to die – and his lovely way of guiding them peacefully to their final rest – has earned him the nickname “Doctor Sleep.”

But Dan isn’t the only person in the world with powers, and a group of psychics who kill and feed off the shine of other people are roaming the country. Their prey is usually small children, and they constantly need a fix. Led by the aptly-titled Rose the Hat (Rebecca Ferguson, who does indeed wear a hat) they chance upon a young girl named Abra Stone (newcomer Kyliegh Curran) who shines brighter than anyone else in the world. And the only way Abra could possibly survive is to contact her anonymous telepathic pen pal, Dan, and bring him back into the larger world of the supernatural, where he can finally face his fears – and the legacy of “The Shining” – once and for all.

Doctor Sleep impeccably recreates scenes from Kubrick’s The Shining, but smartly reframes them as young Danny’s perspective on those shocking events. The original film is effectively Dan’s tragic, traumatic memories of his father’s rampage, without any of the sympathetic context King afforded Jack Torrance in his original story. Dan’s own journey through substance abuse is now a way, unhealthy though it obviously is, to connect to his father on a level he never could when Jack was still alive.

Flanagan, who also adapted the screenplay, insidiously keeps Kubrick’s film canonical while making room for King’s original vision. Although that does require Flanagan to make major changes to Doctor Sleep’s plot, the adjustments create a space where this new film can explore the legacy of Kubrick’s The Shining, its connections to King’s larger literary tradition, and the very nature of adaptation itself. Revisions and reinterpretations do not, in Flanagan’s world, annihilate original texts. Every version of The Shining illuminates the same tale from new angles, including this one.

Of course, Doctor Sleep isn’t a typical sequel. It uses The Shining as a launching point but weaves an extremely different tale. The action sprawls across America and yet the story stays intimate, focused entirely on Dan, Abra and Rose as their paths begin to gradually cross. There’s death, there’s carnage, there’s even a shoot out, but there are too many possibilities in Doctor Sleep’s universe for the film to rigidly follow just one genre and feel satisfying. There are moments when it’s clearly a nightmare-driven haunted house film, moments when it’s a character-driven drama about addiction, and moments when it’s a mythology-driven expansion of the world King merely hinted at in the original.

Those elements could have been formless, and by all rights it could even have been dull, but cinematographer Michael Fimognari (The Haunting of Hill House) keeps finding new ways to make simple moments dynamic and let familiar images from The Shining get under our skin in whole new ways. Director Mike Flanagan also edits the movie, and impressively keeps the pacing brisk while giving the story and characters all the space they need to push the story forward organically, with their understandable choices, and never with cheap cinematic artifice.

The film evokes Kubrick’s aesthetic without becoming entirely Kubrickian. The director of The Shining created clinical and objective spaces for his characters to act in, and reveal their true selves to the watchful world. The director of Doctor Sleep tweaks that shooting style and tilts the camera as necessary, bringing us inside of the cast’s heads into their psyches.

The cast is a treasure. Ewan McGregor owns his vulnerability and turns it into shaky strength. Rebecca Ferguson gives an upsettingly cruel performance, driven by selective morality and cunning. Kyliegh Curran makes a rare debut, full of complex inner turmoil and young, godlike power. And the supporting cast is full of surprises, creating an impressive ensemble of characters both familiar and novel, whether they have one scene or a large number.

It’s dense, it’s complicated, it’s haunting. Is it scary? Not as much as The Shining, but that’s a high bar, and the result of a unique environment. The Shining was a film borne of elegant simplicity, a family in a haunted house, which evoked universal anxieties about addiction, abuse, mental illness, in the grand old tradition of the classical ghost story. Doctor Sleep isn’t a conventional horror movie. It dances from genre to genre, grabbing you and dragging you from one beautiful and horrifying scene to another. It may not keep you up at night wondering what each strange noise is, but it may keep you up at night marveling at how it felt, what it all means… and whether The Shining will ever again be the same.