* US, Russia call on Turkey to show restraint
* Erdogan spokesman signals open-ended cross-border campaign
* Thousands flee Afrin but road to Aleppo shut - monitor
* US seeks to prevent offensive spreading east to Manbij
* Turkey sees Kurdish YPG militia as security threat
Turkey seeks to avoid any clash with US, Russian or Syrian forces but will take any steps needed for its security, a Turkish minister said on Tuesday, the fourth day of its air and ground offensive against Kurdish forces in northwest Syria.
The United States and Russia both have military forces in Syria and have urged Turkey to show restraint in its campaign, named Operation Olive Branch, to crush the US-backed Kurdish YPG in the Afrin region on Turkey's southern border.
The operation has opened a new front in Syria's multi-sided civil war and could threaten US plans to stabilise and rebuild a large area of northeast Syria - beyond President Bashar al-Assad's control - where the United States helped a force dominated by the YPG to drive out Islamic State fighters.
Ankara has said the operation will be swift, but President Tayyip Erdogan's spokesman signalled on Tuesday an open-ended campaign, saying it would end only when some 3.5 million Syrian refugees now living in Turkey could safely return home.
Turkey's military, the second largest in NATO, conducted air strikes and artillery barrages against targets in Afrin, and its soldiers and allied Syrian rebels tried to push into the Kurdish-held district from west, north and eastern flanks.
With heavy cloud hindering air support in the last 24 hours, advances have been limited and Kurdish fighters have retaken some territory. Turkish troops and the Syrian fighters have been trying to take the summit of Bursaya Hill, overlooking the eastern approach to Afrin town.
The Syrian Observatory for Human Rights, a Britain-based war monitor, said 23 civilians had been killed in Turkish shelling and air strikes, and thousands were fleeing the fighting.
However, Syrian government forces were preventing people from crossing government-held checkpoints to reach the Kurdish-held districts of nearby Aleppo city, it said.
US Defense Secretary Jim Mattis said on Tuesday Turkey's offensive was distracting from efforts to defeat Islamic State.
Ankara says the jihadist group is largely finished in Syria and that the greater threat comes from the YPG, which it sees as an extension of a Kurdish group that has waged a decades-long separatist insurgency inside Turkish own borders.
Erdogan has said Turkey aims to destroy YPG control not just in the Afrin enclave but also in the mainly Arab town of Manbij to the east.
"Terrorists in Manbij are constantly firing provocation shots. If the United States doesn't stop this, we will stop it," Foreign Minister Mevlut Cavusoglu was reported as saying on Tuesday.
"Our goal is not to clash with Russians, the Syrian regime or the United States, it is to battle the terrorist organisation," broadcaster Haberturk quoted him as saying.
"I must take whatever step I have to. If not, our future as a country is in jeopardy tomorrow... We will not live with fear and threats," Cavusoglu said.
He later tweeted that a lieutenant had become the second Turkish soldier to be killed in the operation. The Observatory said 43 rebel fighters fighting alongside the Turks had also been killed, as well as 38 on the Kurdish side.
Erdogan's spokesman, Ibrahim Kalin, said the military operations would continue until Syrian refugees in Turkey "return home safely and the separatist terror organisation has been cleansed from the region".
The Kurdish-led administration of northeastern Syria appealed for a mass mobilisation in defence of Afrin. "We call on all our people to defend Afrin and its pride, and contribute in all the related activities," it said, without elaborating.
Washington's central goal in the region is to prevent Turkey from driving Syrian Democratic Forces (SDF), the US-backed umbrella group that is dominated by the YPG, out of Manbij, US officials say.
Unlike Afrin, where no US forces are stationed, there are some 2,000 US military personnel deployed in the eastern region of Manbij, which extends for 400 km (250 miles) along Turkey's border.
YPG spokesman Nouri Mahmoud said Turkish shelling on Monday had killed three people in the Syrian border town of Ras al-Ayn, pointing to the risk of widening hostilities along the frontier.
Ras al-Ayn is located in Kurdish-controlled territory some 300 km (190 miles) east of Afrin. It was one of several locations in northeast Syria targeted in cross-border attacks from Turkey on Monday, Mahmoud said.
The United States hopes to use the YPG’s control in northern Syria to give it the diplomatic muscle it needs to revive UN-led talks in Geneva on a deal that would end Syria’s civil war.
Ankara has been infuriated by the US support for the YPG, which is one of several issues that have brought ties between Washington and its Muslim NATO ally close to breaking point.
"The future of our relations depends on the step the United States will take next," Cavusoglu said.
Turkey, which carried out a seven-month military operation in northern Syria two years ago to push back Islamic State and YPG fighters, will continue to act where it thinks necessary, he said.
"Whether it is Manbij, Afrin, the east of the Euphrates or even threats from northern Iraq, it doesn't matter," he said. "If there are terrorists on the other side of our borders, this is a threat for us."