If only clouds and rain had hung over the beach on Dec. 11 in Costa Rica, like the forecast had predicted, none of this would have happened.

Sure, Doug Cotty and his fiancée, Michele Arias, might still have decided to hang out on Playa Chamán, and might still have spotted the baby olive ridley sea turtles nesting in the sand.

But the Charlotte couple would never have needed to borrow a bottle of sunscreen from the hotel staff. She never would have needed to take off her engagement ring to apply that lotion and never would have tucked the ring into the front pocket on Cotty’s tank top for safe keeping.

Yet, within moments, as the couple hurried to join the growing group of tourists marveling at the turtles, Cotty did something he never would have done if it had been cloudy and rainy: he stripped off his tank top, hung it from a tree branch and slathered himself with sunscreen.

And suddenly, the ring he’d put on her finger just three days earlier — a custom-made piece built around a one-carat diamond in his mother’s family for generations — was no longer in his pocket.

At least a half hour passed before Arias’ stomach tied itself into a knot as she realized they’d lost track of the treasured token. Another hour passed before they gave up digging in the scorching-hot sand, Arias with blisters on her knees and feet. Another hour before both became resigned to the fact that someone had probably spotted it and snatched it. Another before Arias was able to stop crying.

The next day, they flew back to Charlotte in a daze. They were happy to be engaged and trying to look on the bright side, but there’s no question the loss stung. So too did the fact that Cotty hadn’t had the ring appraised or insured. As did forking over $4,400 for a new stone a few weeks later.

Then on Jan. 9 — nearly a month after it dropped onto the sand in a foreign country — Arias received a Facebook message from a man she’d never met before. Five words and six exclamation points: “I just found your ring!!!!!!”

“You are KIDDING!!!! Omg seriously?!?!” she replied.

“It is in my hand,” he wrote.

But how?

Two days after the ring disappeared, Arias posted a plea to a Facebook group for residents of Costa Ballena, the southern Pacific region of Costa Rica that includes Playa Chamán, explaining their misfortune and asking people to spread the word.

“We are hoping someone found it and is holding onto it so we can possibly get it back,” she wrote.

It was basically a Hail Mary, and it yielded predictable responses that congratulated them on their engagement, oohed and ahhhed over the pretty ring, expressed sympathy for their loss and promised to keep an eye out.

But one comment stuck out: “David Harris has been known to recover things.” Arias had no idea what that meant, and though she was tagged in the post, she never responded.

Harris is a 67-year-old American expat who spent more than two decades as a firefighter in Atlanta — where, he says, one of his specialties was using underwater metal detectors as leader of a rescue diving team. In 2005, he sold everything and retired to Central America to live out his days surfing and photographing nature and wildlife.

After an exchange of messages with Arias on Facebook, on Jan. 9, Harris says he woke up, put on a pot of coffee, and was struck by the sudden feeling that he should go take a look on the beach. So he dusted off his metal detector, headed to the store to buy new batteries, then went to the location she’d described to him.

“I probably had searched for 20 minutes, maximum,” he said. “I picked up several Costa Rican coins, and of course a lot of beer caps and nails and stuff — which, on a metal detector, is a really dull thud kind of a noise. Then I got this really high-pitched ping. And I thought, ‘This might not be her ring, but this is damn sure somebody’s property. Something that’s valuable.’ ”

So he started digging. He had to dig a hole nearly a foot deep to get to it.

“When I looked down, the sun was up and shining, and the ring was sitting still in some sand, but it was sitting straight up and down,” Harris says. “And that center stone was like a beacon.”

He grabbed it and made a scene — hooting and hollering and jumping up and down as a group of small children nearby eyed him curiously.

Upon reading his message, Arias burst into a smile. “Complete and utter shock, and disbelief,” Arias says.

She was considering flying back down to get it when — in another struck of luck — a close friend told Arias that her parents were vacationing in Costa Rica and would be happy to bring it home with them. She wasn’t able to fully exhale until 40 days after losing it, and 11 days after Harris found it — when she slipped the ring back onto her finger.

She tried to send Harris $500 for his trouble. He said, “I appreciate that, but I don’t sell people’s own property to them.”

As for the new diamond they ordered as a replacement? It’s en route to Arias’ house.

“But thankfully, they have a 30-day return policy,” Arias said, laughing. “So yes, I will be returning it.”