Emma Balfour walked into my life in the summer of 2003. Our paths collided on Ocean Beach, the 3-mile stretch of gray sand and graffiti-spattered seawall marking the western edge of the city.

It was a cold day and the beach was buried in dense fog, the kind of fog that makes you feel as if you are lost in some strange dream. It was in this bleak landscape that the child appeared, wearing a red sweatshirt, blue jeans rolled up to her calves, no shoes. She was carrying a small yellow bucket. Although she was only 6 or 7 years old, she appeared to be alone. She had long black hair, blue eyes, dimples.

She bent down, picked something out of the sand and laid it gently in the bucket.

"Hi," I said.

"Hi." Her voice was sweet and raspy, completely unguarded.

"What are you collecting?"

"Sand dollars," she said seriously, holding out the bucket for me to examine. At the bottom lay a single, perfect sand dollar.

I reached down and touched it admiringly. "Lovely."

"I know!" she said, returning to her search.

I continued walking slowly, turning around every few steps to glance at her. I kept waiting for an adult to appear. None did.

Then something caught my eye -- a shape in the sand, a dark crescent several feet away. I went to examine it. It was a dead seal pup, partially covered by sand.

A minute or two later, I turned back toward where the girl had been, but she wasn't there. She had disappeared into the fog. If I had not talked with her and heard her raspy voice, if I had not felt the rough sand dollar with my own fingers, I might have believed I had dreamt her up.

I never saw her again. But something had happened; this stranger had walked into my imagination, and she would not go away. For the next few weeks, I thought of her several times a day. Finally, having nowhere else to go, she stepped into a novel. I had not planned to write this novel. In fact, having recently completed my first, I was rather determined not to write another one. But there she was, the mysterious girl on the beach, demanding my attention.

Three years and almost 400 pages later, I had figured her out. I knew what she was doing at Ocean Beach, why she vanished and what happened to her afterward. I had given her a name, Emma Balfour, and I had uncovered her secret history. In the process, I had uncovered secrets about San Francisco as well -- the mass grave beneath the swank Lincoln Park Golf Course, for example, and the broken tombstones that make up parts of the gutter at Buena Vista Park. I had come to understand my neighborhood, the Outer Richmond, and its previous life as the Outside Lands, once home to sand dunes and bordellos. I discovered that the windmill at the northwestern edge of Golden Gate Park, where I often take my toddler son to play, once pumped the water that turned the desolate sand dunes into lush greenery.

By the end of my fictional journey, I had also learned a thing or two about myself, for the places we love are a key to our own inner workings. My husband grew up in the Bay Area, left for seven years and returned. I am one of the many who grew up somewhere else, arrived and immediately recognized San Francisco as home. But I never really knew my adopted city until I began seeing it through the eyes of my characters. Its hills and hideaways, its woods and water, lend to it a magic and mystery that is missing from the flat Gulf Coast landscape of my childhood. And while the balmy waters and gentle waves of the Gulf of Mexico beckon swimmers, the wild Pacific in these northwesterly climes does just the opposite. It is a place for rugged surfers armed with wetsuits and surfboards, not swimsuit-clad children with floatees. The beach itself is strewn with glass and garbage and the ashes of illegal bonfires. Not long ago, a homeless man was found dead on Ocean Beach, suffocated by the shifting sand. When I take my son there to play, I always have an eye out for potential dangers.

Which is perhaps why the girl stayed with me: She was a version of myself from nearly three decades before, but in a drastically altered context. On one hand, I felt a bit jealous. How different my life would have been had my parents chosen to stay in the Bay Area, where my father's naval ship was stationed during Vietnam, instead of returning home to Alabama. On the other hand, she called to mind buried fears about raising a child in the city.

It is possible that Emma -- not the actual girl on the beach but the one she became, in my novel and in my imagination -- was a product of my own deepest fears, as so many of our stories are. A child vanishes into the fog -- truly, a parent's worst nightmare. Like a Wes Craven flick or an amusement park house of horrors, the stories we read, and the stories we tell, serve as a repository for the unthinkable. By way of story, we relegate the terrible to the realm of the imagination. And then we rely on the flimsiest of things -- vigilance and good luck -- to keep it there.