LET’S hear it for Taiwan. Late last month its highest court ruled that the law allowing marriage only between a man and a woman was invalid. Sexual orientation, it said, is “an immutable characteristic that is resistant to change”—rebutting a widespread view across Asia that homosexuality is a curable disease. Barring same-sex couples from marrying violated the right to be treated equally, the court concluded. It gave parliament two years to change the law. If it fails to do so, gay couples will be able to go ahead and register as married anyway.

For Chi Chia-wei, the case’s most ardent backer, it has been a long fight. He was a teenager when he came out to his family in 1975. When he made a public declaration of his homosexuality in 1986, Taiwan was still under martial law; he was arrested and jailed. Nineteen years after the Netherlands became the first country to legalise same-sex marriage, Taiwan has become the first in Asia. Which will be second?

Certainly not Afghanistan, where sexual acts between men are punishable by death. Indonesia does not have a national law against sodomy. But that did not help two young men caught by vigilantes having sex in Aceh province, which was allowed to adopt sharia law in 2001 as part of a deal to end an insurgency. They were whipped in public, as a crowd jeered and filmed the spectacle on their smartphones. A member of the Acehnese clerics’ council told the crowd that the canings were thoughtful, educational and “do not violate human rights”.

The way gay people are treated in Asia is confusingly diverse. Three main factors affect it. The first is the degree of civic freedom a jurisdiction enjoys, in the form of a thriving democracy and a strong civil society. The second is the degree of social openness—ie, how accepting is society of sexual minorities? Last comes religious tolerance: how aggressively do religious institutions object to deviation from sexual norms?

It is not hard, therefore, to understand why Afghanistan is such an awful place to be gay. Civil society remains fragile or, in Taliban-controlled areas, non-existent. Society is largely governed by traditional norms. And Afghan clerics are fiercely conservative. By contrast, Thailand may be socially accepting, but the generals have hollowed out politics and pinioned civil society.

Taiwan scores strongly in two areas. Its civil society is Asia’s most vibrant, and social acceptance of gays has grown rapidly in recent years. In 2001 nearly three-fifths of Taiwanese were against same-sex marriage. Today, polls suggest that half support it, and another quarter do not have strong views. Yet even in Taiwan, acknowledging same-sex relationships faced resistance. Christian groups helped to stall a bill by threatening to turf out any legislator who favoured gay marriage. Taiwan’s president, Tsai Ing-wen, was an advocate of gay rights on the campaign trail but is timid on the subject in office.

Even stronger Christian conservatism colours another ex-dictatorship with a vigorous civil society: South Korea. There, national security is used to justify some illiberal impulses. Civilian law protects gays from discrimination, but in the armed forces, where there is conscription, sexual relations between men are deemed to be “reciprocal rape” and subject to up to two years in prison. Last month a captain broke down in the dock after being given a suspended six-month sentence. Human-rights groups accuse the army of “hunting down” gay soldiers—more than 30 have been investigated this year. Almost three-quarters of South Koreans in their 20s see gay issues as a matter of human rights, and many have protested against the army’s actions. But their elders remain conservative. South Korea’s new president, Moon Jae-in, although a progressive in other respects, said in a presidential debate that he “opposed” homosexuality.

Some think Singapore may be number two. In nine years attendance at its annual “Pink Dot” event has swollen from 2,500 to perhaps 30,000. Gay Singaporeans bring relatives along, and the involvement of non-gay groups, says Paerin Choa, a lawyer and one of the organisers, does a lot for the cause. Singaporean businesses are increasingly open-minded. After the government ruled that foreign firms could not sponsor political rallies, 120 local ones replaced the donations that multinationals had previously made. Yet sex between men remains illegal under section 377A of the penal code. Counting as “outrages on decency”, it is sandwiched between “sexual penetration of a corpse” and “sexual penetration with living animal”. What is more, religious conservatives agitate against a review of the code. Disapproving Christians and Muslims meet on a Facebook page called “We are Against Pink Dot in Singapore”—an unusual union in itself.

India, the biggest democracy, will win no prizes, having a conservative society, a Hindu-nationalist party in power and a colonial-era law against gay sex almost identical to Singapore’s. China does a bit better. In 1997 it decriminalised “hooliganism”, which was a euphemism for gay sex. But television is banned from showing “abnormal” relationships. In late May China’s biggest lesbian dating app, with 5m users, was suddenly shut down.

Special permissive region

What about Hong Kong? Homosexuality was decriminalised in 1991, though same-sex couples are recognised only in the territory’s domestic-violence ordinance. An anti-discrimination law applies only to government employees, with some multinationals adopting their own codes. Yet Hong Kong does pretty well in all three areas. Homosexuality is not taboo among the young. Civil society is vibrant. And though a striking number of politicians are Christian, they tend to be in the territory’s democratic camp. Joshua Wong, a devout 20-year-old who rose to prominence in the “umbrella protests” of 2014 in favour of universal suffrage, is a good example. One of the people whose ideas he campaigns against is his father, a prominent anti-gay activist.