Image copyright US Navy Image caption The USS Carl Vinson, seen here in a file image, is one of the US naval "super carriers"

The immense nuclear-powered US aircraft carrier Carl Vinson has powered into Vietnamese waters, the first such visit since the end of the Vietnam War. The BBC's South East Asia correspondent Jonathan Head looks at how the rise of China lies behind this.

The influence of the United States in Asia is much diminished these days, but it still has one spectacular card it can play.

That comes in the form of the deployment of a carrier strike group, a naval flotilla centred on one of 11 giant "super-carriers", floating nuclear-powered air bases more than 300m long, carrying enough air power to flatten a small city.

The presence of a US carrier group can send a message of deterrence, as in the case of North Korea, or of support. The USS Carl Vinson's arrival in Danang this week is a visible gesture of commitment by Washington to the country with which it fought a terrible war just two generations ago.

An absence of recrimination

The US-Vietnam rapprochement dates back to the restoration of diplomatic relations in 1995. Since then there has been a steady improvement in ties, through trade, cultural exchanges, diplomacy and military co-operation.

Image copyright Getty Images Image caption China is one of a number of countries who lay claim to parts of the South China Sea.

Disagreements over the harsh treatment of political and religious dissidents in Vietnam have not been allowed to interrupt this progression, and there is a remarkable absence of recriminations over the past.

The fact that the USS Carl Vinson is docking just a few kilometres from the beach where US combat troops first landed in Vietnam in 1965, and not far from some of the bloodiest battlefields of the war, presents a poignant historic backdrop to this visit, but in no way overshadows it. This is the culmination of a quiet, careful courtship.

The rise of China is what drives it, for the Americans and for the Vietnamese.

Despite the better-known history of the US-Vietnam conflict, Vietnamese resentment of its giant neighbour goes back much further, embedded in the folk memory of a millennium of Chinese domination in ancient times.

Vietnam shares a border more than 1,000km (620 miles) long with China, through which more than $90bn (£65bn) in trade passes, but which in 1979 was the scene of a short war in which thousands of troops died on both sides.

Image copyright AFP Image caption The relationship between Vietnam and China foundered in the 1970s over relations with Cambodia's Chinese-backed Khmer Rouge regime.

The two Communist Parties once enjoyed a fraternal camaraderie - as close as lips and teeth, they used to say. Then they fell out during the Sino-Soviet split in the mid-1970s - Vietnam choosing the Soviet Union as a patron - and over Vietnam's invasion of Cambodia in 1978 to oust the Chinese-backed Khmer Rouge regime.

That adversarial relationship only changed after the collapse of the Soviet Union in the late 1980s forced Vietnam's communist leadership to rethink their position in the world and establish a foreign policy based, they said, on friendship regardless of ideological allegiances.

At that time they put a lot of diplomatic effort into rebuilding bridges with China. But their differences over the South China Sea remained a problem; both countries claimed parts of the Paracel and Spratly Islands, and have on occasion fought over them.

Keeping the US engaged

Strong anti-Chinese sentiment lies just below the surface in Vietnam, and is easily stirred up. In 2014 protests over China's deployment of an oil rig into disputed waters set off violent protests in Vietnam targeting what they believed were Chinese-owned factories.

It was against a backdrop of increasing Chinese assertiveness in the South China Sea after 2002 that Vietnam began reaching out to its former American foe. That was when China agreed to a Declaration of Conduct with the Association of South East Asian Nations (Asean), four of whose members claimed islands in the disputed waters, which was supposed to halt island grabs and construction on coral atolls.

But that has not stopped China building air bases, missile bunkers and radar stations to fortify its hold on the islands.

Image copyright AFP Image caption Firms with Chinese characters in their logos or signs were targeted in the protests in 2014

Distracted by wars in Iraq and Afghanistan, it was only in a landmark speech by Secretary of State Hillary Clinton at Asean in July 2010 that the US expressed its interest in maintaining freedom of navigation in the South China Sea, and in having disputed adjudicated through international law. Following that speech, the Obama administration announced a "pivot" back to South East Asia.

Moving closer to Vietnam was a core part of that. In 2016, during a state visit to Hanoi, President Barack Obama announced the lifting of all restrictions on sales of military equipment to Vietnam, ending the last legacy of the Vietnam War.

Vietnam was also party to the Trans-Pacific Partnership, a proposed free trade group of 12 countries championed by President Obama as a way of projecting US influence and values in a region where it had been losing ground to China. So the decision by President Donald Trump to abandon the TPP was a blow to Vietnam, a strong beneficiary from the deal. Undeterred, Prime Minister Nguyen Xuan Phuc made sure he was the first South East Asian leader to visit President Trump in Washington in May last year, and then hosted him during the APEC summit in November.

Keeping the US engaged is still a priority for Vietnam, part of a sophisticated and subtle web of diplomatic initiatives aimed at making its friendships as close as they can be without antagonising its all-important relationship with China.

Image copyright Reuters Image caption President Obama in May 2016 announced that the Vietnam arms embargo would be lifted

The US does not yet have a strategic partnership with Vietnam. But the US military has been exploring new areas of co-operation with its Vietnamese counterparts.

So far these have largely been in non-traditional aspects of defence, like peace-keeping and disaster response. There has been no talk yet of the kinds of joint military exercises the US conducts with allies like Japan, South Korea and the Philippines, nor has Vietnam shown any interest yet in acquiring significant US military hardware. Such a move might be viewed as a provocation by China, something the current communist leadership in Vietnam will choose to avoid.

The presence of a US aircraft carrier in Danang, one which will be conducting so-called "freedom of navigation" passages through the disputed areas of the South China Sea, also sends a potentially provocative message to China - but only a symbolic one.

To date US expressions of concern over China's actions in the sea have had no discernable impact on the construction of military facilities there.

The US carrier strike group looks impressive, but it is not clear what it can actually do to restrain China. Even as Vietnam's top brass enjoy watching the full might of the superpower they once fought now paying court as a would-be ally, they must remain mindful of the continuing historic shift in the balance of power in their region away from the United States, in favour of China.