Image copyright Reuters Image caption Certain details about the rescue are only now coming to light

After 17 days underground, all the Thai boys and their football coach have safely escaped from the Tham Luang cave complex.

A team of Thai and international divers mounted a dangerous and complicated rescue to bring the boys out, and details of the bid are still emerging now.

BBC correspondent Jonathan Head has answered some of the core questions about the boys, the rescue attempt, and what happens next.

Why did the kids go so deep into the cave?

We will not know that until we hear from them and their assistant coach, Ekkapol "Ake" Chantawong.

On that Saturday they were scheduled to play a match, which was cancelled, according to head coach Nopparat Kanthawong. He scheduled a training session instead.

The boys were keen cyclists so on the Facebook chat group through which they communicated with the parents, coach Ake suggested they cycle to the football field.

There was no suggestion there that they would go on to the caves.

Image copyright Facebook/ekatol Image caption A Facebook photo shows the coach with some of the young footballers

Saturday was the 16th birthday of Pheeraphat 'Night' Sompiengjai, and a local shop said the boys spent more than 700 baht (US$22) on food to celebrate, a large sum in this area.

Coach Nop describes Ake as being very kind-hearted and devoted to the boys. He thinks the boys persuaded him to go with them into the caves. The caves are well-known in the area and had been explored by the boys before.

The best guess is they went quite deep, which is easy when they are dry, got caught by rising flood water, and were forced to go even deeper.

What kind of communication have the children had with their parents and why are they not being allowed to see them?

The official explanation is they are weak from their ordeal and potentially vulnerable to infection.

These are now very precious lives in Thailand. A massive effort has been made to get them out alive. The Thai authorities are taking no chances.

Media playback is unsupported on your device Media caption The boys give peace signs as they recover in hospital

Perhaps they also wanted to avoid the excitement of seeing their parents again. Thais are generally less physical than westerners. Hugging is unusual.

And the parents are from poor, marginal communities, used to being told what to do by officials, and probably grateful for the lengths the government went to in rescuing them. They would not protest.

They were allowed to see them through windows, and are gradually being allowed in, wearing gloves and facemasks, to stand in the same room.

Will coach Ake face any disciplinary proceedings?

At this stage that seems unlikely. The parents say they have forgiven him, and they are grateful for the efforts he is reported to have made to keep their spirits up in the caves, in particular through meditation, which he learned during 12 years as a monk.

Coach Nop said Ake may be asked to go back to being a monk for a while, something Thais typically do as a kind of penance, or to replenish or cleanse themselves spiritually.

Such a move would make a lot of sense to Thais, and he would likely be allowed to resume life as normal after that.

Also Thailand typically does not have a 'blame culture', where a culprit must be found for any misadventure. There is a more fatalistic acceptance of things going wrong, less public clamour for accountability.

How did they survive so long with so little food, and lose so little weight?

The boys were in the caves nine days before they were found. They may have had a little food from what they bought to celebrate Night's birthday. They are passionate football players, very fit, and with the training they have had a tight-knit team.

This would have helped them ration their food carefully and support each other, perhaps with songs.

Media playback is unsupported on your device Media caption Child psychiatrist: "It will be a challenge for these children to go back to normal life"

Coach Ake taught them to meditate, say Thai navy divers, and gave them more food than he ate. He also told them to drink water dripping from the rocks, rather than polluted ground water.

During their last six to eight days they were being fed, initially high-protein gels, but later more normal food, which might have allowed them to start putting on a little weight before coming out.

Were they in the dark the whole time?

Most of the time. They went in with cheap torches, which would not have lasted long. It is likely they were in the dark for most of the first nine days of their ordeal.

Once they were found a Thai army doctor and at least three divers stayed with them, equipped with good torches. Even so they were mostly in the dark, and had to wear sunglasses when they were first brought out.

Image copyright Thai Navy SEALs/Getty Images Image caption Rescuers brought them food, light and letters from their parents to help them cope

Were they sedated in any way?

The Thai authorities are being very coy about this.

Prime Minister Prayuth Chan-ocha said they had been lightly sedated. But the BBC has spoken to a number of people involved in the operation who say the boys were heavily sedated, and only semi-conscious.

The logic for this would be the fear their rescuers had that they would panic when wearing diving equipment for the first time in darkness and swirling cave water, endangering the lives of all of them.

The two British cave divers who led the rescue effort, John Volanthen and Richard Stanton, are believed to have asked for Australian Richard Harris, a cave diver and anaesthetician, to assist in preparing the boys.

How they carried semi-conscious or very drowsy boys through the technically challenging early stages of the journey out, with a lot of diving in narrow passages, we do not know.

At times they may have been strapped to a diver's body. Later they were strapped on to a stretcher and suspended from a rope pulley system attached to the cave roof.

The entire operation was complex, innovative and very bold. Nothing like it has been attempted before. Some of those involved described the tasks undertaken by the core divers, who carried the boys out, as superhuman.

Who has paid for this operation?

The Thai government, for most of it.

It is likely that the contribution by other countries, like the 30 US air force personnel who went to help, would have been funded by their own governments as a gesture of good will.

Many Thai businesses supported with transport and food. Thai Airways and Bangkok Airways offered free flights to some of the foreign divers coming in.

Media playback is unsupported on your device Media caption Thailand cave rescue: Meet the volunteer helpers

Could the Thais have done this on their own?

No, and few countries could. Cave diving is a very specialised skill, and expert cave rescuers are even rarer.

Thailand was fortunate that an experienced caver Vern Unsworth has explored the Tham Luang cave complex extensively, and lives nearby.

He was on the scene the day after the boys disappeared, and suggested that the Thai government needed to invite expert divers from other countries to help.

The Thai navy divers who went down initially struggled, because both their experience and equipment were for sea diving, which is very different. They were driven out of the caves by rapidly rising flood water, and finding the boys seemed a hopeless cause.

Once foreign divers arrived, from many different countries, the Thai authorities allowed them to devise first the search, and then the enormously complex rescue. It was a huge logistical operation involving hundreds of people, building guide rope and pulley systems, putting in power and communication cables.

It is to Thailand's credit that it was organised so well, and there was no attempt to diminish the foreign contribution.

Since we published this Q&A, we have received many more questions from readers about the rescue. The BBC's Jason Boswell and Howard Johnson have answered some of them.

David Thrussell asks: Who raised the alarm and suggested that they may be in the caves?

On the evening the boys went missing, Nopparat Khanthavong, another coach of the Wild Boars team, began receiving phone calls from worried parents. He called the missing coach, Ekapol Chanthawong, and some of the boys, but there was no answer. Eventually he got hold of Songpol Kanthawong, a 13-year-old member of the team whose mother picked him up after training.

The boy told him that his teammates had gone to explore the Tham Luang caves. Coach Khanthavong then raised the alarm.

Maeda Masami from Japan asks: How did the divers navigate in the zero visibility conditions?

Cave divers will always put in a reference, or guide, line when they first swim into a cave. The line is unspooled from a reel as they extend further into the cave and will be tied off on rocks at regular intervals.

The divers can then follow this line in and out of the cave or use it to install additional stronger lines or ropes so they can hold on and navigate despite terrible visibility. Even if they lost their masks they can navigate by touch and feel along the rope.

Tumalip Ericson asks: Why did they say that Elon Musk's mini-sub wouldn't fit through the narrow gap in the rescue?

What the head of the Thai rescue operation actually said was that the mini-submarine provided by Elon Musk was not "practical" with the mission. The exact reason why wasn't given.

Several expert cave divers told the BBC that one of the potential problems with the design put forward by Mr Musk's team might have been that the "submarine" is a rigid inflexible tube.

Cave passages are often not straight and smooth, so if there was a bend it may have been difficult for divers to try navigate the tube.

Imagine trying to manoeuvre a long couch into a small room through an even smaller door, but in the dark and with a limited air supply.

The divers would have wanted every piece of equipment as streamlined and as flexible as possible to navigate the uneven walls and bends of cave passages.

However the mini-sub may be of future use in places that are not as restricted - for example in sunken or capsized ships. Experts say the design should continue to be worked on as the mini-sub may be valuable under a different set of circumstances.

Mr Musk responded to the Thai authorities by tweeting an email from one of the British caving experts who played a key role in the rescue urging the inventor to build the capsule as quickly as possible.

Mr Musk also said that "SpaceX engineering is absolutely certain that mini-sub can do entire journey & demonstrate at any time".