Kim Jong Un knows what he has to do to keep North Korea under his leadership, writes Anna Fifield.
Between American threats of "fire and fury" and North Korea's vow to unleash a "historic enveloping fire" on a US territory, the war of words between Pyongyang and Washington has suddenly raised fears of escalating into an actual war.
It also has brought a rush of speculation about the brinkmanship at play - including trying to understand the moves and motives of the North's leader, Kim Jong Un.
With his unequivocal words, Trump appeared intent on sending a message to North Korea - and to its traditional backer China - that enough was enough, according to Administration officials.
But with Kim, the endgame is all about seeking to stay in power, analysts said.
The 33-year-old leader inherited control of the totalitarian regime from his father and grandfather, who founded North Korea with Soviet and Chinese backing after World War II.
"What Kim Jong Un really wants is to improve his missiles and nuclear weapons and to keep the country under his leadership," said Michael Madden, who runs the North Korea Leadership Watch website.
Although the Western caricature of Kim is of a pudgy madman with a funny hairdo, he has been a textbook dictator, making rational decisions for someone who wants to retain absolute power.
On Thursday North Korea made an unusually specific threat. In a statement attributed to the North Korean army's Strategic Forces commander, Pyongyang threatened to fire four intermediate-range Hwasong-12 ballistic missiles over Japan for by the middle of this month, saying they would land within 30km and 40km of Guam, the US territory in the Pacific that is home to large air force and navy bases.
This threat was not made in response to Trump's "fire and fury" remarks - the wheels of Kim's bureaucracy move more slowly than Trump's - but rather in reaction to the US launching of a Minuteman III intercontinental ballistic missile (ICBM) from the Vandenberg Air Force Base in California on August 2.
A war still remains in no one's interest - especially not in that of the 25 million South Koreans who live within range of North Korea's conventional artillery - but the combination of two tempestuous leaders with nuclear codes has created an atmosphere where anything seems possible.
"The risk in northeast Asia stems from both Trump and Kim Jong Un," said Koo Hae Woo, who was a top official at South Korea's intelligence service until 2014 and now runs the Korea Institute for Future Strategies thinktank.
"Kim is ratcheting up the tension to the maximum level, while President Trump doesn't rule out war as an option," Koo said.
The Kims have kept a tight grip on North Korea internally through a brutal system of repression and fear, and have increasingly kept the outside world at bay by developing nuclear weapons and the means to deliver them. This has traditionally been viewed as a deterrent to fend off the kind of fate that Saddam Hussein suffered in Iraq and Muammar Gaddafi endured in Libya.
Since taking over the reins at the end of 2011, Kim Jong Un has rapidly accelerated the development of North Korea's weapons programme, presiding over three nuclear tests and surprising improvements in its missile technology.
While these weapons might work as a deterrent, it would be suicidal for Kim to actually use them and risk retaliation by the much more powerful American military.
"Kim Jong Un is not trying to pick a fight," Madden said.
An American analyst who is in contact with senior North Korean officials, Madden said that Pyongyang was well aware that Trump had a habit of speaking - or tweeting - off the cuff.
"North Koreans are not taking this seriously. They're saying that Trump is saying these kinds of things because he hasn't 'consolidated his power' yet," he said - using a line that American experts usually use to describe questionable things that Kim does.
Cheong Seong Chang, a North Korean leadership expert at the left-leaning Sejong Institute in the South, agreed with Madden that Kim does not want actual conflict with the US.
"North Korea is not developing ICBM technology to start a war with the US," Cheong said. "This is all about preventing the US from intervening in any military conflict on the Korean Peninsula. It wants to influence American decisions. The US does not want to be criticised for risking American lives to protect its allies."
Others see a ploy by North Korea to ratchet up the tensions and make the most progress on its weapons program before sanctions bite and it is forced to return to the negotiating table.
"The US will only agree to talk with the North if it thinks a physical clash is imminent," said Koo Hae Woo, who was a top official at South Korea's intelligence service until 2014 and now runs the Korea Institute for Future Strategies thinktank. "The North is not aiming for a clash but increasing the tension to create an environment for negotiation."
But behind the assessment of Kim as a rational, if brutal, leader with a master game plan lies a worrying precedent.
Rational leaders of new nuclear states with a small number of weapons tend to be most reckless in their early years, said Van Jackson, an expert on North Korean security issues at Victoria University in New Zealand.
"There's a temptation to see how much juice they can squeeze out of these weapons that they've spent so much money and effort making," he said, adding that this created more pressure, not less, to demonstrate nuclear capability.
The closest analogue to the North Korea situation is Pakistan, he said. Rather than following the Cold War model of mutually assured destruction, Pakistan has adopted a strategy of "asymmetric escalation" - being able to use a nuclear arsenal against a conventional attack.
"The fact that Kim Jong Un is rational doesn't necessarily lead to good outcomes," Jackson said. "Rationality takes us to a more dangerous place right now."