The National Decarbonization Plan, as it’s called, envisions electric passenger and freight trains in service by 2022, which is when Ms. Dobles’s husband, President Carlos Alvarado, finishes his term. Under the plan, nearly a third of all buses would be electric by 2035, dozens of charging stations would be built, and nearly all cars and buses on the roads would be electric by 2050. Unlike many other countries, Costa Rica does not rely on coal to produce its electricity.

Revamping transportation is expensive and so it will require tackling things that have little direct connection to climate change — fixing the country’s fiscal health, for one, to be able to secure big foreign loans to fund such an ambitious project, and lowering unemployment, which is a pressing political demand. It also means addressing the aspirations of its upwardly mobile people.

Stephanie Abarca is one of them. Purse and lunch bag in hand, on her way to work one morning, the 32-year-old Ms. Abarca was 100 percent behind the first lady’s green targets. Of course, Ms. Abarca said, Costa Rica should be a green “pioneer.”

But she faces more immediate problems. For her, getting to work means waking up at 4 a.m. to shower and dress, ride the bus for an hour, walk a few blocks (or run, if the bus is late), and board a slow-chugging, horn-blaring diesel train for another 20 minutes to finally get to her office. Most weeks, after a nearly two-hour commute each way, she is too exhausted for the 6 p.m. yoga class that her employer offers to relieve stress. By Fridays, she is running on fumes.

Her goal : She is saving up to buy a secondhand car, a subcompact Suzuki Swift. It would improve her commute, she said, knowing full well that it would also inject more carbon into the atmosphere. “Everybody wants to have a car,” said Ms. Abarca, a manager at a furniture company. “That doesn’t help.”