Aaron Campbell was looking for cannabis when he entered the flat and discovered Alesha MacPhail sleeping in her bed.
For the duration of his trial he had denied ever meeting the six-year-old, let alone being responsible for her abduction, rape and murder.
But as Campbell, 16, faced a criminal psychologist, who was preparing a pre-sentencing background report, he finally admitted one of the most horrific crimes in Scottish legal history.
The detail of his account was chilling.
It was known Campbell left his home on the Isle of Bute after a party as he wanted to get "stoned".
He had previously bought cannabis from Alesha's father and had been to the flat where he lived on Ardbeg Road, Rothesay.
The jury heard that a key had been left in the door in the early hours of 2 July last year.
What remained a mystery was why Campbell took Alesha from her bed?
It has now emerged that in the 12 months prior to the murder the teenager thought about "doing something excessive" including rape.
And when he set eyes on the child he saw it as a "moment of opportunity".
Campbell told the psychologist: "At any other time in life, murder wouldn't have been the conclusion. If I was a year younger I don't think I would have done it.
"All I thought about was killing her once I saw her."
There were emotional scenes in the public gallery at the High Court in Glasgow as more horror was heaped on Alesha's family.
They heard the schoolgirl was initially "drowsy" but as Campbell carried her out of the flat and along the shoreline she became more awake.
Alesha asked who he was and where they were going.
Campbell told her he was a friend of her father and that he was taking her home.
He even gave the child his top as she was cold.
The details of what happened at the end of their journey were, mercifully, not aired in court.
But as Campbell was sentenced it was disclosed he told the psychologist he was "mildly amused" police took two days to arrest him after Alesha's body was discovered.
The teenager also admitted he had to "zip his mouth" to stop himself laughing during the trial.
Perhaps the most disturbing revelation he volunteered was that he was "quite satisfied with the murder".
It was an astonishing about-turn for a killer who had initially lodged a special defence of incrimination in which he blamed 18-year-old Toni McLachlan, the partner of Alesha's father.
This was particularly cruel as she was old enough to be named in the media while he remained anonymous, until that restriction was removed after the verdict.
Prosecutor Iain McSporran QC branded the schoolboy a "confident liar" who had spun a web of deceit.
When Campbell was convicted by a unanimous jury verdict last month he did not show a flicker of emotion and remained impassive in the dock.
He wore the same blank expression as he was ordered to spend a minimum of 27 years in prison and warned he may never be released.
Lord Matthews described him as a "cold, callous, calculating, remorseless and dangerous individual".
Campbell had first appeared on the police radar shortly after midnight on 3 July last year
The previous morning Alesha's naked body had been discovered in the grounds of a former hotel on the Isle of Bute.
It was Campbell's own mother who contacted detectives after reviewing footage captured by the CCTV cameras outside the family home on Ardbeg Road, about a mile outside Rothesay, the main town on the island.
After being sworn in as the first defence witness Campbell said he had lived on Bute since the age of four or five with his parents and younger sister.
A previous police statement shown on the court screens confirmed he was born in Shrewsbury, Shropshire, on 7 May, 2002.
His father Christopher, 42, was a supervisor in the oil industry and often worked away from home.
Campbell's QC, Brian McConnachie, questioned the accused about his relationship with his mother Janette, 54.
He said they argued, normally when she was drinking.
Asked if she had a alcohol problem, Campbell said: "I would say so. I don't know about now but certainly back then."
Mr McConnachie later described his client's upbringing as "less than ideal" but stressed there were no mitigating factors which could explain his appalling crime.
Campbell had spent Saturday 30 June camping on Ettrick Bay to mark the first weekend of the school holidays.
The following day he used Snapchat to invite 15 friends to a party at his home, a seven-bedroom detached property which looks onto the Firth of Clyde.
That night the teenager told the court he drank a bottle of Mad Dog fortified wine and shared a bottle of Echo Falls wine with a friend.
He said: "I got drunk. I was not sick. I was just having a good time."
But as the party drew to a close, at about 00:30 on 2 July, his mood changed.
Campbell admitted: "I was quite upset as my mum had been arguing with me most of the night."
A close friend found him in an emotional state and recalled he was "suicidal".
The 16-year-old friend said Campbell blamed his mother's drinking for his mood.
He told the jury: "I felt quite worried for him."
The friend eventually managed to calm Campbell down before they parted company.
At the time of his arrest last summer the teenager claimed he was only smoking the Class B drug once a month.
Campbell named Alesha's father, Robert MacPhail, and his girlfriend, Toni McLachlan as two of the people who had supplied him with "weed".
But in February 2018 he fell out with Mr MacPhail, 26, over the quality of his product.
This resulted in an unpaid debt of £10.
Given Campbell's dealer was 10 years his senior, the episode was presented to court as yet another example of the teenager's arrogance.
In the early hours of 2 July Campbell tried to contact Mr MacPhail via Facebook Messenger.
He said: "Then I remembered I still owed him a tenner so I messaged Toni instead."
Neither responded so he headed for the flat the couple shared with Mr MacPhail's parents, which was a five-minute walk away.
He was armed with a kitchen knife but discarded it on the shore when he realised he could easily gain entrance to the property.
On his return the first bedroom he encountered at the top of the hall was Alesha's.
'Friends with benefits'
Campbell appears to have been comfortable in the company of girls and claimed he was sexually active.
In evidence he named two teenagers he had been "talking to" during his fifth year.
When his advocate, Mr McConnachie, asked what the term meant, he explained: "It is kind of like the transition period between being friends and being boyfriend and girlfriend."
In the winter of 2017 he told the court he became involved with Alesha's father's girlfriend, Toni McLachlan.
He said: "Toni and I began seeing each other, not in a going out sort of way.
"I guess I would call it friends with benefits."
Campbell claimed the sexual relationship enabled Miss McLachlan to frame him by planting his DNA at the crime scene from a used condom.
Lord Matthews later described his account as a "cruel travesty of the truth" and told the court Miss McLachlan was "completely innocent".
Campbell owned a Playstation 4 and, according to his mother, was "addicted" to gaming.
From the age of 12 he wanted to be a YouTube star and posted footage on his channel, including clips of a nightmarish game called Slender Man.
Its focal point is a tall, faceless character who lives in the woods and stalks children.
Another, psychological horror PT, involved exploring a haunted house.
On the videos Campbell is seen playing games and commentating on what is happening.
After his conviction YouTube said it had taken down the footage as a mark of respect for Alesha and her family.
At school Campbell had a large circle of friends and his strongest subjects were maths and physics.
He planned to go to university and his dream was to design games.
The teenager was also a fan of parkour and posted videos online in which he showed off his skills on a trampoline.
To keep fit he lifted weights at home and in the gym.
He was strong for his age and, under questioning by Mr McSporran, said he could bench press 50kg.
The QC then told the court Alesha, who has just finished her second year at primary school, weighed 22kg.
The distance between her grandparents' home and the secluded spot where she was found would have taken up to 17 minutes to cover on foot.
Crucially, the post-mortem examination recorded 117 injuries on the child's body but not a single mark on her feet.
The prosecutor said: "Alesha was carried to where she died. Toni could not have carried her. You could have."
Campbell replied: "I have no experience of carrying people. I have never carried weights for such a distance before."
Fantasy kill chat
The trial heard from Campbell's friends that he had a dark sense of humour.
The jury was shown a transcript of a Facebook Messenger chat which had been initiated by a female friend after she watched a crime documentary.
During the conversation in 2017 Campbell wrote: "Might kill 1 day for the lifetime experience."
When he was asked about the comment during his evidence, he said: "I think in the next message I said it would be more like a short lifetime experience because it would ruin your life if you killed someone. It would be a stupid thing to do."
The morning after the murder Miss McLachlan messaged Campbell and asked him to keep an eye out for Alesha as she was missing.
The killer replied: "Oh damn. Am sure she's not went too far x".
That afternoon he filmed a video in his house which ended with his reflection being revealed in a bathroom mirror.
It was then shared with a Snapchat group with the caption: "Found the guy that done it."
As he sentenced Campbell, Lord Matthews highlighted the footage.
He told the the teenager: "Your attitude was clearly demonstrated by the evidence that you posted an image of yourself in a mirror while making a joke that you had found where the murderer was hiding.
"The arrogance and callousness of that is breathtaking."
Before officers arrived at his home, the court heard Campbell's iPhone was used to Google "How do police find DNA?"
Asked how he presented himself, Det Con Gavin McKellar replied: "Confident. He was quite confident."
Mr McSporran inquired if the accused seemed overawed or anxious.
The officer said: "Not at all."
His alibi was that he had gone out to buy cannabis from another teenager and at no point did he mention meeting up with Miss McLachlan.
Mr McSporran questioned why he gave the police a story that could easily be disproved.
Campbell answered: "I guess I am not very good at lying."
He was arrested on 4 July and driven to Helen Street police station in Govan, Glasgow.
Throughout his nine-day trial he could not be named as he was under 18.
After his conviction media outlets, including the BBC, launched a successful legal bid to reverse the court order which had protected his identity.
During the hearing the court was told the teenager had a history of self harm, anxiety and depression and he had been previously tested for attention deficit hyperactivity disorder.
He does not suffer from any mental health disorders of syndromes but Lord Matthews later observed Campbell was "completely lacking in victim empathy".
The teenager will be held at HM Young Offenders' Institute Polmont, near Falkirk, until he turns 21.
He will then be transferred to the adult prison system where he will not be eligible for parole until 2045.
But before he was led from the dock, the judge told him: "Whether you will ever be released will be for others to determine but as matters stand a lot of work will have to be done to change you before that could be considered.
"It may even be impossible."