Turkey's biggest cities have witnessed a spate of deadly bombings and a bloody attempted coup.
For so long a beacon of stability between Europe and the Middle East, Turkey has entered a period of high tension.
It has long fought Kurdish militants in its restive east. Now it is trying to prevent Islamist militant violence spreading from Syria and is cracking down on suspected supporters of the failed July 2016 coup.
How dangerous is the current crisis?
Turkey's main population centres of Ankara and Istanbul have endured a wave of deadly bomb and gun attacks, as well as a failed coup that saw tanks on the streets and fighter jets targeting parliament.
In a matter of months, Istanbul has seen rebel soldiers take over the bridges across the Bosphorus, a double bombing outside Besiktas football stadium, and a gun attack blamed on jihadist group Islamic State (IS) targeting New Year revellers at an exclusive nightclub on the waterfront.
Ankara has witnessed the assassination of its Russian ambassador. Other cities such as Izmir in the west and Kayseri in central Turkey have been targeted too.
The human cost has been immense. At least 270 people died on 15 and 16 July 2016, when Turkey's government survived an internal rebellion blamed on a movement led by a US-based Islamic cleric.
Thirty-nine people lost their lives on New Year's Eve in the Reina nightclub.
Until recently, the bloodshed was largely confined to the mainly Kurdish areas of the east and south-east, where the Turkish military has battled the militant Kurdistan Workers' Party (PKK) for decades.
But the conflict in Syria and turbulence in domestic politics has created new tensions. And a ceasefire with Kurdish militants proved short-lived.
The message for Turks is clear: that the risk of violence is not limited to the border and it is on several fronts.
Is Turkey safe for tourists?
Turkey is no longer the safe destination that made it one of the world's biggest tourist draws. The coup is over but since July 2016 the country has been under a state of emergency. And yet the main tourist resorts on the coast have avoided the violence seen elsewhere.
France has urged its citizens to exercise great vigilance while travelling and in tourist areas; the UK says that while it is generally safe to travel to Turkey, additional safety precautions should be taken. The US warns its citizens of "increased threats from terrorist groups throughout Turkey".
Tourists are not a target for Kurdish militants but they are for IS, which targeted Istanbul airport last June because it has become one of Europe's busiest transport hubs, attracting almost 42 million passengers in 2015.
According to one calculation, Turkey suffered 269 attacks in 2016. Turks themselves have become afraid of going to shopping centres and open spaces, and yet they remain defiant in the face of violence.
"I think we are seeing a downward spiral towards more violence," warns Prof Menderes Cinar of Baskent University in Ankara.
Turkey's tensions: Read more
Why is Turkey challenged on so many fronts?
Turkey sees itself targeted by three groups of "terrorists": IS, Kurdish militants and coup-plotters.
Since the failed 15 July coup, Turkey's government has detained thousands of suspected sympathisers in the security forces. Officials say 41,000 people have been arrested and 100,000 dismissed from jobs in public life.
The focus of the crackdown is a shadowy movement described as a "parallel state", said to owe its allegiance to cleric Fethullah Gulen, who is in self-imposed exile in the US.
But as the purge continues, so too do Turkey's internal security threats.
A long-running internal conflict with Kurdish militants had been quiet for a couple of years, until an IS suicide bomber targeted a rally of young Kurdish activists near the Syrian border at Suruc in July 2015.
Violence in the main cities tended to target party offices, particularly those of the left-wing and pro-Kurdish HDP (Peoples' Democratic Party). The banned Marxist DKHP-C has periodically carried out attacks on police and Western embassies.
But then the ceasefire collapsed. In one year, more than 600 members of the Turkish security forces were killed in attacks blamed on the militant PKK.
A splinter group, the TAK (Kurdistan Freedom Hawks), carried out a string of bloody attacks that killed civilians as well as police and soldiers in Ankara. On 13 March 2016, 37 people died when the TAK targeted a busy transport hub in Ankara and 44 were killed in December when two bombs exploded near police outside Besiktas's Vodafone Arena in Istanbul.
For many Turks, the PKK is no different from its offshoot.
But some of the deadliest and highest-profile attacks have been blamed on IS:
- October 2015: More than 100 people died, many of the Kurds, in a double bombing on a peace rally near Ankara station
- January and March 2016: Suicide bombers murdered tourists from Germany, Israel and Iran in attacks on Istanbul
- June 2016: Forty-five people were killed in a coordinated attack targeting Turks and foreign visitors alike at Ataturk airport in Istanbul
- August 2016: A suicide bomber was blamed for murdering 54 people at a wedding party in the southern city of Gaziantep. Twenty-nine of the victims were children
- 1 January 2017: Gunman kills 39 people at the Reina nightclub in Istanbul
Why is IS targeting Turkey?
Much of the IS violence inside Turkey in recent months, such as the Gaziantep attack, can be put down to reprisal attacks for the Ankara government's policy on Syria.
Although Turkey has long backed Syrian rebels, it has become a major player in the conflict in recent months. In August 2016, Turkey launched a campaign against IS in northern Syria and there has been fierce fighting as it tries to seize control of the group's stronghold of al-Bab.
Together with Russia it organised a halt to fighting in Aleppo, and then a nationwide ceasefire in late December.
But Turkey had initially been a reluctant participant in the Syrian conflict. PKK leader Cemil Bayik even accused President Recep Tayyip Erdogan of "protecting IS", to stop Kurds advancing against the jihadist group and carving out their own territory in Syria.
Turkey did nevertheless agree in 2014 to take part in the US-led operation against IS and was seen as part of the Nato alliance targeting its bases in Iraq and Syria.
It then sealed off the jihadists' supply of militants crossing over the previously porous border with Syria.
Why has violence erupted with Kurdish militants?
When IS bombed a rally of Kurdish peace activists in Suruc in 2015, there was a clear benefit in seeing Turkey drawn into renewed domestic conflict with Kurdish militants.
Turkey's security forces have since become bogged down in a military campaign against the PKK in the east and south-east. Curfews were imposed on towns and cities for months in 2016 as the Turkish military hunted down Kurdish militants.
Kurdish communities live on both sides of the Turkish border with Syria and have long battled the spread of IS.
But Turkey has no interest in seeing Kurdish territorial gains across its border and part of the incentive to seize al-Bab from IS was to prevent Syrian Kurds from increasing their hold in the area. Turkey has vowed to prevent the creation of a contiguous Kurdish autonomous region along its border with Syria.
Turkey is particularly worried by the rise of the Syrian Kurdish Popular Protection Units (YPG) militia and its political arm, the Democratic Union Party (PYD).
"Turkey is feeling a very serious existential threat from the PYD and PKK," says Burhanettin Duran, executive director of Turkey's pro-government Seta research institute. "It's a very solid fact that the PYD and the PKK are the same."