THIS year marks the 40th anniversary of the start of the democratic wave that swept over Latin America and turned military dictators into political flotsam. It is an anniversary tinged with gloom. Democracy is in retreat worldwide, with scholars identifying more than two dozen countries that have reverted to authoritarianism in this century. Many worry for its future in Latin America, too.

In fact, democracy has held up surprisingly well in the region. There are only two clear cases of regress. Venezuela and Nicaragua have abolished term limits and their elected presidents now rule as dictators. Two other countries are question-marks. In both Honduras and Bolivia, incumbent presidents have got the courts to set aside term limits. Both rule as autocrats. Even so, in Bolivia Evo Morales, a successful president since 2006, may struggle to win an election due in 2019.

Ecuador, where Rafael Correa ruled in a similar fashion for a decade until 2017, might have been on that list. Mr Correa’s successor, Lenín Moreno, seemed at first to be a placeholder. But he has proved to be his own man. On February 4th Ecuadoreans approved in a referendum, by 64% to 36%, the reimposition of a two-term limit for all elected officials. This blocked Mr Correa’s future return.

A bigger worry than regress in Latin America is political decay—“when political systems fail to adjust to changing circumstances” because of opposition from entrenched stakeholders, as Francis Fukuyama, a political scientist, puts it. Worryingly, that is the case in Costa Rica, the region’s oldest and seemingly one of its strongest democracies.

Neither of the two parties that forged this democracy and ruled from 1948 until 2014—the National Liberation Party (PLN) and the Social Christians—has candidates in the run-off election for the country’s presidency, scheduled for April 1st. Rather, the contest will feature Fabricio Alvarado, an evangelical pastor and gospel singer whose main proposal is opposition to gay marriage, and Carlos Alvarado (no relation), whose Citizens’ Action Party (PAC) has been in power since 2014. It won only ten of the 57 seats in the new legislative assembly in the elections on February 4th.

Fabricio, who was his party’s sole legislator until those elections, starts the run-off as the favourite. His rise is circumstantial: it owes everything to an opinion by the Inter-American Court of Human Rights last month that Costa Rica should legalise gay marriage. Only 32% of Costa Ricans agree (though that is up from 17% in 2012), according to LAPOP, a regionwide poll based at Vanderbilt University in Tennessee.

But the political malaise in Costa Rica goes much deeper. Support for the political system, measured on a composite index drawn up by LAPOP, has fallen from 87% in 1983 to 62% in 2016. Corruption is one reason. But this was far worse in the 1970s, observes Kevin Casas Zamora, a political scientist and former vice-president of Costa Rica. “It’s a very easy explanation for very complex ills,” he says.

Costa Rica is in many ways a successful country. It has opened up to globalisation, diversifying its economy with new industries, such as medical devices, ecotourism and renewable power. But politicians have failed to deal with rising crime, income inequality and poverty. That is partly because they have failed for many years to approve an increase in tax revenues, which at 14% of GDP are low for the country’s level of development. And that in turn is because of the fragmentation of politics (there are now seven parties in the assembly). There are simply too many veto-wielders.

In Latin America, even as the new is born the old tends not to die. The social-democratic PAC wars with the PLN but has failed to kill it off: with 17 seats, the PLN will be the largest party in the new assembly. Costa Rica suffers a vicious circle in which the voters seek new political actors who fare as badly as the old ones, says Mr Casas. The current president, Luis Guillermo Solís, was a once-fresh face who failed to fix the budget or reform taxes.

Costa Rica’s problems are a sign of the times in the region. Evangelical Protestants are a rising political force in several countries, as “culture wars” open up a new policy cleavage. That applies in Brazil, Guatemala and Peru and bodes ill for the rights of women and gay people. Political fragmentation is on the rise, especially in Brazil and Colombia. Old-style parties have become empty shells but in many countries have yet to be replaced.

Yet electorates are much more demanding because Latin American societies have changed dramatically. Political systems are struggling to evolve in tandem. Democracy is very much alive in the region. But it is not wholly well.