Deadly clashes between Syrian and Turkish forces are again testing the delicate relationship between President Recep Tayyip Erdogan and his Russian counterpart Vladimir Putin, though they have become masters at managing their competing interests.
Once bitter rivals, Erdogan and Putin grew far closer after the failed coup in Turkey in 2016, when the Russian president took the opportunity to express his full support at a time when Ankara's Western allies were more lukewarm in their support.
Despite being on opposing sides of the conflicts in both Syria and Libya, they have also found it expedient to keep negotiations under their control as much as possible, leaving Western powers at arm's length.
Still, it remains a tricky balancing act, particularly in Syria, where Turkey backs several opposition groups while Russia is the key supporter of Bashar Assad’s regime.
A Syrian offensive in the last opposition bastion of Idlib has sent another huge wave of refugees towards Turkey's borders.
Clashes on Monday led to eight Turkish soldiers and civilians being killed, followed by at least 13 Syrian troops in retaliatory fire -- the deadliest exchanges between the two armies since Turkey deployed into Syria in 2016.
Erdogan directed most of his anger at Damascus, but also criticized Moscow for failing to enforce the peace agreements supposed to prevent a full-blown Syrian offensive in Idlib, and warning it would not wait for a Russian green-light for further retaliation.
"This escalation in Idlib will test relations between Erdogan and Putin. We can no longer speak of a simple honeymoon between these two strongmen," said Emre Kaya, of the Edam think-tank in Istanbul, according to Agence France Presse.
Erdogan cannot ignore Russia's direct role in the current Idlib offensive, he added, given that Syrian units are trained and equipped by Moscow.
In the end, the interests of the two sides appear irreconcilable.
The Syrian regime is determined to retake the last rebel-held area, while Ankara refuses to countenance an offensive that has already displaced more than half a million people, according to UN monitors.
Erdogan said Wednesday that he was giving Damascus until the end of the month to pull back from areas around its 12 military observation posts in Idlib, which were set up under a 2018 deal with Russia.
Two of those posts are now behind Syrian regime lines, Erdogan said.
The episode has highlighted the complexity of ties between Russia and Turkey, whose rivalry stretches back into their imperial pasts and has been characterized by centuries of mistrust.
The most recent nadir came in 2015 when Turkey shot down a Russian fighter jet that had strayed into its airspace.
But analysts say it is unlikely things will deteriorate to that level again in the near future, since they have become increasingly reliant on each other across sectors ranging from energy to trade to defense.
"Ankara and Moscow are constrained to cooperate and maintain good relations, since the two countries are economically interdependent," said Jana Jabbour, of Sciences Po university in Paris.
"The two countries know how to separate immediate tensions from their cooperation in key sectors," she said, adding that they always emphasized "realpolitik and pragmatism" in their dealings with each other.
Erdogan made the point himself on Tuesday, saying he saw no reason to "trigger a serious confrontation with Russia" given their "numerous strategic initiatives".
He specifically stated that recent events would not endanger Turkey's controversial decision to purchase the S-400 missile defense system from Russia, which has drawn the ire of Ankara's NATO allies.
Despite seeming to move away from its Western partners, Turkey insists it is only seeking an independent position between Moscow and the West to maximize its room for maneuver.
The clashes in Idlib were a rare opportunity for Washington to offer unequivocal support to Ankara.
"It offers an important occasion for a rapprochement between Turkey and the United States, and perhaps other NATO allies," said Kaya.
Nevertheless, "there are divergent ideas between Ankara and Washington on the way forward for the region, with the priority for Ankara being to avoid the arrival of another wave of refugees while Washington prioritizes the extermination of terrorists," Kaya added.