The withdrawal of US troops from Afghanistan and seemingly unstoppable march of the Taliban opens a strategic door to China that is laden with both risk and opportunity.
China abhors a power vacuum, especially on its borders, and maintaining stability after decades of war in its western neighbour will be Beijing's paramount consideration.
But if stability requires a Taliban-dominated government, an equal concern would be the support such an administration might provide to Muslim separatists in China's Xinjiang region.
Communist Party leaders in Beijing and the fundamentalist Taliban have little ideological common ground, but analysts say shared pragmatism could see mutual self-interest trump sensitive differences.
"For China, the risk does not come from who holds the power in Afghanistan, but from the risk of persistent instability," Fan Hongda, a Middle East specialist at the Shanghai International Studies University, told AFP.
Afghanistan shares only a small 76-kilometre (47-mile) border with China, at high altitude and without a road crossing point.
But the frontier is a big concern because it runs alongside Xinjiang, and Beijing fears its neighbour being used as a staging ground for Uyghur separatists from the sensitive region.
"China can deal with the Taliban... but they still find the Taliban's religious agenda and motivations inherently discomforting," said Andrew Small, author of The China-Pakistan Axis.
"They have never been sure how willing or able the Taliban really are to enforce agreements on issues such as harbouring Uyghur militants."
For Beijing, a stable and cooperative administration in Kabul would pave the way to an expansion of its Belt and Road Initiative into Afghanistan and through the Central Asian republics.
The Taliban would meanwhile consider China a crucial source of investment and economic support, either directly or via Pakistan -- the insurgents' chief regional patron and a close Beijing ally.
Taliban spokesman Suhail Shaheen told AFP that the insurgents want to "have good relations with all countries of the world."
"If any country wants to explore our mines, they are welcome to," he said. "We will provide a good opportunity for investment."
- 'It doesn't hurt if they invest' -
Beijing has already opened dialogue, having hosted a Taliban delegation in 2019, and this week Foreign Minister Wang Yi hosted talks on regional security in central Asia.
Back-door links with the Taliban through Pakistan have stretched back longer and "allowed China to avoid any major terrorist attack on its projects in Afghanistan", according to Thierry Kellner, a political science professor at the Universite Libre de Bruxelles.
These projects include the giant Aynak copper mine near Kabul, for which a Chinese company secured a potentially lucrative concession in 2007 but where work has long been stalled due to conflict.
Since the Aghan government has failed to provide security in places where Beijing wanted to make big investments, "it now thinks it doesn't hurt if they invest in the Taliban and give them a chance," said political scientist Atta Noori in Kabul.
Beijing has made political capital out of the American troop withdrawal and warned that Afghanistan could again become "the region's powder keg and a haven for terrorism."
Wang has also stressed the need to "bring the Taliban back into the normal political game" in conversations with his Afghan and Pakistani counterparts.
Should the Taliban seize Afghanistan, Beijing sees financial investment as a way to shore up support.
"China never wants to have boots on the ground but loves to get involved economically, making use of the vast mineral resources in Afghanistan," added Noori.
- 'Of course we will talk' -
This could extend to an accord on Xinjiang, where rights groups say a million Uyghurs and other mostly-Muslim minorities have been placed in re-education camps, alongside allegations of forced labour and sterilisation.
China has responded defiantly to a chorus of international condemnation over the camps, which it says are training centres necessary for stamping out Islamic extremism.
As Beijing has steadily poured cash into its close ally Pakistan, Prime Minister Imran Khan has stayed conspicuously silent on Xinjiang, which also borders his country.
By signing deals with the Taliban, Beijing hopes they will also remain publicly neutral on the Uyghur issue.
In an interview with the Wall Street Journal, the Taliban's Shaheen said that "if there are some problems with the Muslims (in China), of course we will talk with the Chinese government."
More pressing problems will keep any influx of Chinese capital on hold for now, said Ayesha Siddiqa, an expert on the Pakistani military and its economic investments.
"Is Afghanistan ready for investment? The answer is no," she told AFP.
"China has been timid so far with throwing money into Afghanistan and it will continue to do so until there is a clearer picture on where Afghanistan is going."