Until recently, Hong Kong was considered a poster child in its handling of the Covid-19 pandemic.
Despite sharing a border with mainland China, where the first cases were reported, Hong Kong kept its infection numbers down and was able to avoid the extreme lockdown measures introduced in parts of China, Europe and the US.
But now, it's been hit by not even a second, but a third, wave of infections. The government has warned its hospital system could face collapse, and it's just had a record high number of new infections in a day.
What went wrong, and what lessons are there for countries juggling both the pandemic, and the economic pain caused by lockdown?
Quarantine exemptions and 'loopholes'
Hong Kong had its first Covid-19 cases in late January, leading to widespread concern and panic buying, but infection numbers remained relatively low and the spread was controlled quite quickly.
It experienced what became known as its "second wave" in March, after overseas students and residents started returning to the territory, leading to a spike in imported infections.
As a result, Hong Kong introduced strict border controls, banning all non-residents from entering its borders from overseas, and everyone who returned was required to undergo a Covid-19 test and 14-day quarantine.
It even used electronic bracelets to track new arrivals and make sure they stayed at home.
That, combined with the widespread use of masks and social distancing measures, worked - Hong Kong went for weeks without a locally transmitted case, and life seemed to be heading back to normal.
So how did the "third wave" - that has led to more than 100 new cases for nine days in a row - arrive?
"It's quite disappointing and frustrating because Hong Kong had really got things very much under control," says Malik Peiris, Chair of Virology at the University of Hong Kong.
He believes there were two flaws in the system.
First, many returnees opted to quarantine for 14 days at home - an arrangement that's common in many countries including the UK - rather than in quarantine camps.
"There is a weakness there because other people in the home are not under any form of restriction, and will still be coming and going," says Prof Peiris.
However, he believes the more serious problem came from the government's decision to exempt several groups of people from testing and quarantine when they entered Hong Kong.
Hong Kong had exempted about 200,000 people, including seafarers, aircrew and executives of companies listed on the stock exchange, from quarantine.
It said the exceptions were needed to ensure normal daily operations continued in Hong Kong, or because their travel was necessary to the city's economic development.
As an international city and trading port, Hong Kong has a high number of air links, and many ships change crews there. The territory also depends on imports from mainland China and elsewhere for food and essential goods.
Joseph Tsang, an infectious diseases specialist and doctor, describes the exemptions as a significant "loophole" that increased the risk of infection, particularly from seafarers and air crew who also visited tourist spots and used public transport.
The government initially said that the quarantine exemptions were not to blame, but later admitted there was evidence that the exemptions were behind the latest outbreak.
They have now tightened rules for air and sea crews - but it can be difficult to enforce. There was alarm earlier this week when a foreign pilot was reportedly spotted sightseeing while awaiting Covid-19 test results.
And balancing public health, practical concerns and the economy can be hard - a union representing pilots at FedEx has asked the company to stop flights to Hong Kong because it says the stricter Covid-19 measures, including mandatory hospital stays for pilots who test positive, create "unacceptable conditions for pilots".
Benjamin Cowling, a professor of epidemiology at the University of Hong Kong, says Hong Kong's experience with quarantine problems could also happen in other countries.
"In the UK, you also have a 14-day quarantine at home, so you would have the same potential issue with leakage."
Meanwhile, New Zealand and Australia have a mandatory hotel quarantine policy, which is "a good concept… although there's the issue of who pays for it", he adds.
Like Hong Kong, the UK also exempts certain travellers from border rules, including drivers of goods vehicles, seafarers and aircrew.
Social distancing measures were lifted
Hong Kong's quarantine exemptions have been around for months, but the third wave didn't hit until July.
Prof Peiris believes this is because of a second crucial factor - social distancing measures were significantly rolled back in June.
"As long as social distancing measures were in place the system could cope - but once measures were relaxed" the imported infections spread rapidly, he says. "It's a lesson for everybody."
Dr Tsang recalls that by late June the government had allowed public gatherings of up to 50 people, while there were celebrations for Fathers' Day and Hong Kong's handover anniversary.
"Many citizens were fatigued after months of social distancing, so when the government said things seemed fine and relaxed restrictions, they started meeting with friends and family.
"I think it's very unfortunate - many factors combined at the same time."
However, Prof Peiris stresses that Hong Kongers had been "extremely compliant" with social distancing and hygiene measures during in the first and second waves - "in fact, they were even a step ahead of government instructions, wearing face masks before they were compulsory."
He believes the reintroduction of social distancing measures now are already having an effect, and hopes that Hong Kong will be back to close to zero local infections within four to six weeks.
At that point, he adds, the challenge will be to stop imported infections - particularly once social distancing measures are lifted.
It's a challenge other countries will also face once they are successful in containing the virus within their borders, because "when you get to low levels of transmission within your population, having unregulated introductions from outside can lead to disaster."
Did the pro-democracy protests spread the virus?
Many of Hong Kong's pandemic struggles will apply to other cities, but the territory has also experienced another crisis - a political one - over the past year.
On 1 July, thousands of people took part in a pro-democracy rally, despite the march being banned by authorities who said it broke social distancing guidelines. Hundreds of thousands also voted in opposition primaries in mid-July, despite the government warning that the primaries could breach a new security law.
Since then, Chinese state media have blamed both events for triggering the third wave of infections, while one politician called it "absolutely irresponsible behaviour".
However, health experts say there is no evidence of them causing the spike in infections.
Prof Cowling says scientists "are able to link together cases to identify chains of transmission, and there are no clusters attributed to those events," while Prof Peiris argues that the events "may have aggravated things slightly, but I don't think it was a major determinant one way or the other".
Meanwhile, Dr Tsang says research has shown that "the strain of coronavirus in the third wave is different from those in previous waves" - in particular, it has type of mutation seen in aircrew and seafarers from the Philippines and Kazakhstan, so he believes the strain was imported.
There have been similar discussions around the world - particularly in light of anti-racism protests sparked by the death of George Floyd - over whether demonstrations can lead to a spike in infections, with some experts suggesting that outdoor events where participants wear masks and take precautions could be lower risk than initially expected.
Could the outbreak affect Hong Kong's elections?
There is widespread speculation that Hong Kong's government could postpone September's elections to Hong Kong's parliament - the Legislative Council - citing the spike in infections.
Several local media reports, quoting anonymous sources, say the government is set to postpone elections by a year.
Opposition politicians have accused the government of using the pandemic as an excuse to delay elections, especially as the opposition had performed strongly in local elections late last year.
However the move has been welcomed by some, including former Legislative Council president Jasper Tsang, who told local media: "The government won't be able to absolve itself of blame if polling stations turn into hotbeds for spreading the virus.
"It's also nearly impossible for candidates to canvass votes given the social distancing rules."
Prof Cowling says that social distancing measures reintroduced by the government have already stopped case numbers from accelerating over the past week.
"I'm not sure it's necessary to delay the elections - certainly not for a year. You could consider delaying them for two weeks or a month, because by then we'd almost certainly have [local infection] numbers back down to zero."
He adds that there are many ways to make elections safer, including increasing the number of polling stations and staff to reduce wait times, ensuring polling stations are well-ventilated, and testing all polling station staff two days before the election.
Governments have taken very different approaches to this - at least 68 countries or territories postponed elections due to Covid-19, while 49 places held elections as planned, says the International Institute for Democracy and Electoral Assistance.
Singapore held its general elections earlier this month - and had its highest turnout in recent years, says Eugene Tan, a law professor and political commentator at Singapore Management University.
"There is never a good time for an election during a pandemic," he says, but the vote went ahead with several safety measures in place and "demonstrates that it is possible to protect public health even as people go about exercising their democratic right to vote."
However, he believes that making a decision on whether to proceed with elections is a tough judgement call for governments, particularly if public trust is low.
"If you delay elections you could be accused of waiting for a more favourable time [for the government] - but if you go ahead you could be accused of playing fast and loose with people's lives. The worst thing would be to have an election, and then have a spike in the number of cases."