SEOUL: North Korean leader Kim Jong Un's visit to China -- his first overseas trip since inheriting power in 2011 -- is the most tangible and dramatic step so far in a four-way diplomatic dance.
It comes with Kim due to hold a summit next month with South Korea's Moon Jae-in, and ahead of a planned meeting with US President Donald Trump -- events that give both Pyongyang and Beijing new incentives to repair their battered relationship, analysts say.
China wants to regain its influence in what it sees as its back yard, and protect its interests.
"Order is restored under heaven," tweeted veteran Korea-watcher Aidan Foster-Carter, adding that upcoming summits would be different in tone and content now Kim and Xi Jinping have met.
Kim's meeting with the Chinese president brings Beijing back onto a stage where it had played a key role for decades as Pyongyang's diplomatic guardian and its chief source of aid and trade.
For the North, it is a chance to rekindle a relationship it has seemingly deliberately allowed to cool -- and the prospect of an insurance policy if talks with Washington do not go well.
The rapprochement has been brought about by the same events that have driven Pyongyang's detente with Seoul and Washington: the North's nuclear advances, Washington's hardline rhetoric and the growing impact of sanctions on the economy.
An atmosphere of cooperation fostered by the Winter Olympics in the South catalysed the process.
But the appointment of the hawkish John Bolton as national security adviser has heightened fears that the US might resort to military action if Trump is disappointed by his meeting with Kim.
The US and North Korea still have wildly diverging views of the North's nuclear programme, said Beijing-based independent political commentator Hua Po, adding the summit could go "a lot of different ways".
If the negotiations fail, he said, Kim will "want China's understanding and support".
"Therefore, Kim must come and communicate with China," Hua told AFP.
Pyongyang is looking to stay one step ahead in the diplomatic dalliance, added Kim Han-kwon, a professor at the Korea National Diplomatic Academy.
"North Korea is trying to secure another bargaining chip by showcasing improved ties with China," he said.
- North Korea playbook -
Relations between Beijing and Pyongyang were forged in the blood of the Korean War, when Mao Zedong's forces saved Kim Il Sung from defeat, but China has grown increasingly frustrated with its neighbour's nuclear and missile antics.
It has shown a new willingness to enforce tougher UN sanctions, including restrictions on oil supplies to the isolated regime.
Cheong Seong-Chang, senior fellow at the Sejong Institute, said: "Considering the deterioration of North Korea's economy from international sanctions, China is the country that the North most urgently needs to mend ties with."
But it's not a one-way street.
Beijing fears the collapse of the regime in Pyongyang and the instability it would bring, potentially sending waves of refugees into China and heralding the possibility of US troops stationed on its border in a unified Korea.
And the flurry of diplomatic progress on the peninsula, orchestrated by the South's Moon, has threatened to sideline Beijing.
China wants to see reduced tensions, said Bill Bishop, publisher of the Sinocism China Newsletter, but also wants to be the only country with leverage over its nuclear-armed neighbour.
"China doesn't want a nuclearised peninsula but they also don't want any steps toward unification," Bishop told AFP.
"They're concerned about being left out, with the North Koreans cutting a deal with the Americans that doesn't necessarily reflect Chinese interests."
And there is historical precedent for the meeting.
Christopher Green, an analyst at the International Crisis Group, pointed out that Kim's father and predecessor Kim Jong Il travelled to Beijing to meet with the then Chinese leader Jiang Zemin in 2000, ahead of the first inter-Korean summit.
"North Korea is playing its diplomatic cards professionally, and moreover in order," tweeted Green.
Like his son, he added, for the first six years of his rule the older Kim stayed in North Korea "securing his rule domestically, often violently" before starting to meet foreign leaders.
"That is the playbook Kim Jong Un is following."