Turkey's foreign policy has been a moveable feast recently -- from pushing for Syrian President Bashar al-Assad's fall and largely ignoring ISIS, to an about-face on both.
"Turkey is becoming increasingly entangled in the Syria quagmire," Fadi Hakura, a Turkey expert and associate fellow at London-based Chatham House, told CNN. "As Turkey becomes more involved in the implosion of Syria, we are seeing the instability there crossing over the border and impacting security."
At the start of the Syrian civil war, Turkey under President Recep Tayyip Erdogan backed the rebels, who were Sunni Muslim, against the regime of Assad, who is Alawite.
"Erdogan was one of the main players who took sides in the Syrian conflict to accelerate the downfall of Assad in Syria," Hakura said. "He brought Turkey deeper and deeper into the conflict, which has produced the negative blowback we see today in Turkey."
Turkey had left ISIS alone, and ISIS largely left Turkey alone in terms of attacks, though fighters and supplies were routed through the country. By the time Turkey decided to take more precautions, ISIS had established many footholds and supporters.
Turkey launched its biggest military offensive in Syria last summer, backing opposition forces to drive ISIS out of a strategic area along the border and block further advances by Syrian Kurds allied with Turkish separatists. The advance drew approval from Russia and air support from the United States.
The Kurds, an ethnic group in the Middle East, have increasingly influenced developments in the region, fighting for autonomy in Turkey, and playing a prominent role battling ISIS in the Syrian conflict.
President Recep Tayyip Erdogan had made peace with Turkey's Kurdish population a few years ago, but then started to strike Kurdish forces across the border in Syria. Snap elections hurt the Kurdish vote and restored Erdogan's grip on government. And by 2016, the familiar violent insurgency of Kurdish groups was back.
The militant Kurdistan Worker's Party, or PKK, have mostly targeted military and police personnel, but the Kurdish Freedom Hawks (TAK), a splinter nationalist group, recently carried out a deadly attack targeting an Istanbul soccer stadium.
"One of the problems with the any potential ceasefire with the PKK is an emotional issue," Simon Waldman, a visiting research fellow at King's College London and the co-author of The New Turkey and Its Discontents, told CNN's Ian Lee. "When you look at the PKK and the attacks they've committed, especially when they target security personnel, the police and armed forces...it's very difficult emotionally for Turkey's politicians to have some sort of ceasefire."
The Kurdish issue can be handled effectively by way of an ambitious program of human rights and democracy, Hakura said, emphasizing that this tact was essential to improving security in Turkey.
"During times of increased democracy, the Kurdish issue became less and less pronounced in Turkey's profile," Hakura told CNN. "If Turkey resolves the Kurdish question within a democratic framework, it will prevent outside, regional players from taking advantage of these divisions."
Turkey's pervasive political and social polarization has contributed to an atmosphere where attacks are more likely.
"The political and social culture is so abrasive, fragmented, and divided, along ethnic, sectarian, and ideological lines, that it has created an environment where these violent incidents can take place," Hakura told CNN.
Internal struggles within the government are also at a tipping point, with supporters of Fethullah Gulen, Erdogan's ally-turned-rival who now lives in the United States, being blamed for a bloody failed coup in June.
Instead of using the coup to bring about unity, the government adopted policies that re-energized divisions in Turkish society and political culture, Hakura said.
"The more divided you are, the more opportunities you create for regional players to take advantage of them," Hakura said. "Promoting internal unity will strengthen Turkey's stability and security in one of the most volatile parts of the world."
Waldman told CNN that Turkey's post-coup purges have left a security vacuum in the country at a critical moment.
"I don't think at this present juncture Turkey can confront multiple terrorist groups at the same time," Waldman said. "Turkey's military and security services are facing purges. There are thousands of personnel who have been, if not detained, suspended from their jobs. This has left a vacuum in their ability to confront terrorist threats."
"As a result, dealing with two significant terrorist groups at the same time is an incredible burden. What is needed for Turkey is a pragmatic policy approach in fighting terrorism," Waldman added.
Erdogan's growing closeness with Russia and abandonment of the Syrian Sunni rebels he'd once supported could also have created new opponents and enemies.
Russia has said it has no conclusions yet on the motive behind the assassination of Ambassador Andrey Karlov by a man shouting about Aleppo, the northern Syrian city held by rebels that was besieged, bombed and finally retaken by Russian-backed Syrian forces. The Kremlin has pushed back
against Turkey's allegations that the Gulen movement was behind the assassination.
"You've got a Turkish state that's clearly under a lot of pressure, dealing with a lot of issues at the same time," Raffaello Pantucci, director of international security studies at the Royal United Services Institute, told CNN. "As a result, you can wage attacks in Turkey with greater ease, and you're more likely to succeed."
And whatever the internal and external politics of Turkey, there will always be the geography.
Turkey's position at the intersection of Europe and Asia has long made it the place for the clash or melding of cultures. Turkey was established as a secular if majority Muslim nation, and while religion began to play a more important role under Erdogan, there are still many places that celebrate Western freedoms -- like the Reina nightclub, which ISIS apparently condemned as a place where "Christians were celebrating."
Even more relevant now, perhaps, is its 500-mile border with Syria -- essentially an open border that has allowed fighters and resources to flow to Syria for years -- as well as refugees to flood out -- but also now allowing in those who wish harm inside Turkey.
"One of the main problems Turkey has at the moment is that they're sitting next to a major civil war, where many insurgent groups are using Turkey as an entry point," Pantucci told CNN.
Pantucci suggests that Turkey has become an easy target in large part because of its location.
"The tempo of attacks is increasing because the Turks are dealing with multiple problems at the moment. Not only are they seeing attacks by ISIS, but the other groups feeding the fight in Syria," Pantucci says. "In Turkey, you're looking at a security environment that is going to be quite difficult in the immediate future."