For Mostafa, a gay Egyptian man in his mid-20s, seeing rainbow flags flying at an open-air rock concert in the Arab world's most populous nation was thrilling. But he had a feeling it wouldn't end well.
Dozens of people have been arrested and put on trial in Egypt in the ensuing crackdown. Some were also beaten and subjected to invasive physical exams, spreading panic in lesbian, gay, bisexual and transgender circles.
Many of Mostafa's friends are deleting their profiles on cellphone dating apps and scrubbing their social media accounts, which police have long used to ensnare people suspected of being gay or transgender. Some who were at last month's concert have gone into hiding. There has even been talk of fleeing the country.
"The problem is that no one can tell the limit of this crackdown and how far it might go," said Mostafa, a community activist who asked to be identified by one name, for fear that he too might be swept up by police. "There was an incredible amount of hate speech by the media and by people on social media. Everyone I know is depressed and fearful."
It's not the first time that the Egyptian authorities have gone after gay and transgender people. In one particularly notorious case, 52 men were put on trial at once after a high-profile raid on Cairo's Queen Boat nightclub in 2001.
The "Arab Spring" uprising that toppled Egyptian strongman Hosni Mubarak a decade later brought some respite for the city's embattled LGBT community, whose members were able to socialize more openly at house parties and bars.
But that respite came to an abrupt end after the military takeover that brought President Abdel Fattah Sisi to power in 2013. Hundreds of gay and transgender people have been rounded up, part of a broad crackdown that has seen political dissidents jailed, public protests harshly put down and the country's once vibrant civil society quashed.
Still, human rights activists say the scale of this latest assault on Egypt's LGBT population is unprecedented. At least 65 people were detained around the country in three weeks, according to a local rights group, the Egyptian Initiative for Personal Rights. Of those, 20 were sentenced to prison terms ranging from six months to six years, and four were released. Cases against the rest are pending.
Almost every day brings word of new arrests, according to the group's lawyers, who are scrambling to keep up with the caseload.
They include Mohamed Alaa, a 21-year-old law student who was photographed at the concert waving a rainbow flag, and Sara Hegazy, 28, the only woman identified so far among the detainees. Both are being questioned by state security prosecutors who usually investigate terrorism cases.
Homosexuality is not specifically outlawed in Egypt, but authorities there have a history of using a 1961 law that prohibits "debauchery" to target the population. The accusations against Alaa and Hegazy are more serious. They include membership in an illegal organization, a charge also used against the government's Islamist opponents.
"The Egyptian authorities tend to view challenge to authority in any sense in a deeply uncharitable fashion — and seem to have interpreted the raising of the rainbow flag very much in that way," said H.A. Hellyer, a nonresident fellow at the Atlantic Council, a Washington think tank.
The crackdown began after a Sept. 22 concert in Cairo by the Lebanese indie-rock group Mashrou' Leila, whose lead singer, Hamed Sinno, is one of the few openly gay performers in the Middle East.
It was a special show for the band, which was twice barred from performing in Jordan over accusations of not respecting the country's traditions and beliefs. More than 30,000 people attended, and several of them raised rainbow flags.
"Cairo! This was one of the best shows we've ever played!" the band said on its Facebook page. "So much love!"
Excited fans shared photographs and video of the rainbow flags on social media. The backlash was swift and brutal.
Influential TV talk show hosts and newspaper columnists denounced the flag wavers as "sexual deviants" and suggested they were part of a foreign-backed plot to destabilize the country.
Al Azhar University, the center of Islamic learning in this mostly conservative Muslim country, said it would be organizing sermons and lectures to "fortify youth against these deviant thoughts." St. Mark's Coptic Orthodox Cathedral announced a conference on what it termed a "volcano of homosexuality."
Responding to the public outcry, Egypt's top prosecutor, Nabil Sadek, ordered an investigation into the flag waving.
Days later, Egypt's media regulatory body issued an order prohibiting coverage that promotes or legitimizes homosexuality, which it labeled a "sickness and disgrace." It also barred homosexual people from appearing in the media, unless it is to repent. The pro-government musicians union announced it would no longer issue permits to foreign performers unless they obtain security clearance.
"Perhaps certain officials are embarrassed that they didn't catch this beforehand," said Timothy E. Kaldas, a nonresident fellow at the Tahrir Institute for Middle East Policy in Washington. "It's not exactly hard to know Mashrou' Leila's politics on LGBT issues … and they approved the concert."
"The question is," Kaldas said, "to what extent is this the government responding to pressure, and to what extent is it also an opportunity to distract the population from its other failings?"
Despite signs of economic revival, the cost of living has skyrocketed in Egypt, and salaries and pensions have not kept pace. Unemployment remains punishingly high, especially among the young; corruption is rampant, and terrorist attacks are on the rise.
The first suspect was taken into custody the day after the concert. Police used a fake profile on a dating app to lure the 19-year-old man to a place where officers were waiting, then searched his phone for incriminating material.
"By coincidence, they found photos of the concert," said Dalia Abdel Hameed, who heads the gender program at the Egyptian Initiative for Personal Rights. "So they spun the narrative that they had arrested him as one of the flag bearers."
He was sentenced to six years in prison on charges of debauchery and inciting debauchery.
"Most of the people arrested had nothing to do with the concert or the flag," Abdel Hameed said. "These were men who were frequenting gay-friendly cafes or using dating apps or sometimes even arrested for looking or acting too gay in the street." Alaa and Hegazy were tracked down a week later through images from the concert shared on social media.
In a poignant video posted before his arrest, Alaa expressed dismay at the vitriolic response to his gesture, including death threats from his home village. Though he is not gay, according to his lawyers, he said he had borrowed a flag from another audience member to support the band's lead singer. (The video has since been taken down.)
Hegazy, who denies she was one of the flag wavers, told her lawyers that she was sexually harassed and beaten in a holding cell on her first night in custody after police informed fellow inmates about the reason for her arrest.
At least five men were subjected to anal exams to determine whether they had had gay sex — a practice that leading rights groups including Amnesty International and Human Rights Watch say amounts to torture.
The five members of Mashrou' Leila were on a plane bound for the United States when news broke about the arrests. At first, they said, they stayed silent out of fear that a statement from them might further inflame Egyptian authorities. But on Oct. 2, they issued a statement denouncing the "demonization and prosecution of victimless acts between consenting adults."
"It is sickening to think that all this hysteria has been generated over a couple of kids raising a piece of cloth that stands for love," the band said.
Mostafa, the gay activist, is wondering whether the time has come for him to leave Egypt. Many gay and transgender people who have the means have already done so.
But for all the hatred directed against his community, he said, there has also been an outpouring of support on social media.
"That would not have been the case a few years ago," he said. "Despite the tactics becoming more brutal, there is dialogue around the issue."
A special correspondent in Cairo contributed to this report.