Beneath its calm, exquisitely detailed surface, “When Marnie Was There” bubbles with half-formed ideas and undeveloped themes. Suggestion and subtext jostle for attention, and the extent to which they intrude will depend mainly on the age of the viewer. To the tinies, this gorgeously animated adaptation of a 1967 young-adult novel by the British author Joan G. Robinson will seem a simple tale of friendship found and unhappiness banished. Others, however, could experience the story’s sweetly supernatural drift as a veil for gnarlier intimations of child abuse, sexual awakening, ethnic confusion and even mental illness.

Possibly the last feature of its kind from the much-lauded Japanese animation house Studio Ghibli (whose founders, Hayao Miyazaki and Isao Takahata, recently announced their retirement), “Marnie” is psychologically darker and less fantastical than most of the studio’s previousoutput. Its emphasis on the richness of nature and the fortitude of young girls, though, remains intact as Anna, an asthmatic 12-year-old, is sent to live with relatives at the seaside. Orphaned at a young age, Anna is an unusually prickly heroine who derides her anxious foster mother (“She whines like a goat!”) and simmers with self-loathing. Sulking outside the “invisible magic circle” inhabited by her peers, she pours all her emotions — including spikes of violence — into her drawings.

But when Anna meets Marnie, a golden-haired beauty with an unsettling tendency to appear and disappear at odd moments, everything changes. The seemingly abandoned mansion in the marsh where Marnie lives is transformed at high tide by glamorous parties — a glittering world that welcomes Anna as one of its own. Seduced by Marnie’s ardent attentions, she barely notices their ominous undertones or her own lapses in memory whenever her new friend is around. Like a princess in a fairy tale, Marnie moves in stardust and traffics in mystery.

Unfolding in painstakingly realized interiors and painterly landscapes, “Marnie” is a muddled merger of ghost story, fantasy, time travel and coming-of-age. Fighting all of these, however, is a first-love story — a passionate connection between two damaged souls. This becomes quite explicit when Anna, perpetually dressed like a boy, jealously watches Marnie dance with a young man, then questions their mutual devotion. But the director, Hiromasa Yonebayashi (perhaps mindful of appealing to younger children), only flirts with this and other, thornier undercurrents, like the suggestion of Marnie’s abuse at the hands of her forbidding maid and the fury with which Anna responds to the suggestion that her eyes are almost blue.

The result is a movie that’s neither eventful enough for little ones nor ripe enough for teenagers. The conclusion is rushed and poorly staged, yet the damp caul of loneliness that envelops the film’s early scenes feels moving and true. We don’t have to read the book to suspect that its author — who was born in 1910 and lived through two world wars — had, like Anna, more than a theoretical acquaintance with the aftermath of abandonment.

Directed by Hiromasa Yonebayashi; written by Mr. Yonebayashi, Keiko Niwa and Masashi Ando, based on the book by Joan G. Robinson; supervising animator, Mr. Ando; music by Takatsugu Muramatsu; production design by Yohei Taneda; produced by Yoshiaki Nishimura; released by GKids/Studio Ghibli. Released in two versions; in Japanese and dubbed into English. Running time: 1 hour 43 minutes.