The sudden takeover of Afghanistan by the Taliban ahead of the withdrawal of U.S. troops from the country has left China facing a precarious mix of opportunity and risk as it prepares to deal with the new power brokers in Kabul.
Only hours after the Taliban took control of the Afghan capital, the Chinese Foreign Ministry reacted by saying Beijing was ready for "friendly cooperation" with Afghanistan and intended to assume "a constructive role" in the war-torn country's reconstruction.
"On the basis of fully respecting the sovereignty of Afghanistan and the will of all factions in the country, China has maintained contact and communication with the Afghan Taliban and played a constructive role in promoting the political settlement of the Afghan issue," ministry spokeswoman Hua Chunying said on August 16.
The scenes of the chaotic evacuation from Kabul by Western forces were also a boon for Chinese propagandists, with state-run media using the images to further a narrative to both domestic and international audiences of American decline and Washington's unreliability.
But the diplomatic outreach to Kabul and schadenfreude Beijing feels from the U.S. withdrawal and clunky evacuation mask a deep uncertainty that China faces in Afghanistan as it scrambles to prepare for a reshaped geopolitical map and a new era of security risks in South and Central Asia on the heels of the Taliban's military victory.
Beijing's Top Priority
China shares a tiny 76-kilometer border with Afghanistan and has taken a laid-back approach to its neighbor, although the U.S. military withdrawal and fall of the elected Afghan government are poised to change that.
Beijing has economic interests in the country, with a particular eye on its vast mineral wealth, but China's main interest is that conflict doesn't spill beyond Afghanistan's borders.
Central to those worries are how to curb regional instability and eliminate any potential for Afghanistan becoming a safe haven for terrorist groups, especially Uyghur militants in the country. An early test for the new era of the Taliban's relationship with China will be if the militants ban the East Turkestan Islamic Movement (ETIM) -- a Uyghur group that Beijing blames for unrest in its western Xinjiang Province -- from operating on Afghan soil.
While many analysts dispute the severity of the threat posed by Uyghur groups to China, it is seen as a major threat by Beijing -- with counterterrorism being central to the Chinese Communist Party's justification for its crackdown in Xinjiang, where it is believed to have interned more than 1 million Uyghurs, Kazakhs, and other Muslim minorities.
The Taliban have been distancing themselves from Uyghur groups and it will also be closely watched by other outside powers -- such as India, Russia, and the United States -- to see if the militant group will allow Afghanistan to be used as a base for operations by terrorist groups.
Beyond that narrow set of objectives, Beijing is looking to limit its exposure in Afghanistan. Chinese policymakers see the country as a very high-risk environment and remain more focused on limiting risks rather than chasing opportunities.
Beijing has already laid the groundwork for this new reality, with Foreign Minister Wang Yi hosting Taliban leadership at the end of July.
China and the Taliban have a complicated, decades-old relationship. While both sides distrust the other, Beijing has stepped up its engagement of the militants since 2014 -- in part due to the interlocutor role donned by Pakistan as a Chinese ally and the Taliban's main patron -- and they have managed to find common ground.
China has no particular affinity for any political faction in Afghanistan. Prior to its collapse, Beijing also had a strong working relationship with Kabul and Afghan government forces also sought to monitor and target Uyghur militant groups at China's request.
As long as the Taliban can protect China's interests in Afghanistan, it will be able to reap the benefits of its pragmatic cooperation with Beijing.
Should the Taliban prove that it can be a more reliable partner in protecting China's security concerns than the Western-led Afghan government was, Beijing could put its political and economic muscle behind the group and help them in their quest for international legitimacy as Afghanistan's new government.
What About Afghan Resources?
Afghanistan is estimated to have rare earth metals worth trillions of dollars that can be used in everything from electronics to electric vehicles, satellites, and aircraft.
China's state-owned Metallurgical Group Corporation secured a $3 billion, 30-year concession in 2008 to mine Mes Aynak, a huge copper deposit south of Kabul, and the China National Petroleum Corporation holds a tender for oil fields in the north.
But these projects are at a standstill due to security concerns, which are likely to increase as Afghanistan settles into a tenuous political situation following the Taliban's takeover of Kabul.
While China would like to tap into Afghanistan's lucrative natural resources and also extend its economic footprint through the massive Belt and Road Initiative (BRI), the difficult security environment means those remain long-term goals with no clear timeline.
Is The Taliban Takeover A Win for Beijing?
It's not that simple.
While the Taliban have indicated they are willing to cooperate with China and assuage its concerns, their victory likely means more instability in Afghanistan and the wider region, whether it be continued fighting, refugee flows to neighboring countries, or stepped-up terrorist activity across Central and South Asia.
Beijing remains cautious about extending the BRI into Afghanistan, but the vast infrastructure project is already deeply rooted across Kazakhstan, Kyrgyzstan, Pakistan, and Tajikistan. Chinese investment and infrastructure projects in those countries have been a pathway to greater influence and China remains worried that getting sucked into Afghanistan's security vacuum could undermine its wider goals.
Chinese interests and personnel have recently been targeted in Pakistan, which is one of the focal points of the BRI.
A bus carrying Chinese workers in Pakistan was bombed on July 14, killing 13 people, nine of which were Chinese, and has since been attributed to attackers operating from inside Afghanistan.
This was followed by another attack on Chinese workers in Karachi on July 28.
For now, though, China will be watching to see what kind of government emerges in Afghanistan and how the Taliban wields its power across the country.
So far, Beijing has successfully laid the groundwork to protect its interests, but with the situation in Afghanistan still volatile, China will remain in a wait-and-see mode for the time being.