Even before the polls closed in New Hampshire, Hillary Clinton knew she was in for a very bad night.
The establishment worrywart caucus was freaking out, and the media was rife with speculation of an imminent staff shake-up. Was she once again being set up for a fall, a lumbering front-runner about to be toppled by a charismatic outsider?
Her answer: Get me a bigger plane.
Robby Mook, her penny-pinching campaign manager, blanched. But Clinton insisted that she did not want her aides trickling back to the Brooklyn campaign headquarters, one by one, nursing their dejection. Everyone would fly together.
As 30 or so aides boarded, Clinton and her husband, former president Bill Clinton, stood at the top of the stairs, shaking each one's hand and thanking them.
It was not just a gracious gesture. Clinton wanted to send a signal, one that would be understood internally, even if it took the rest of the political world awhile to catch on. She and her team had a plan. She believed in it. They were sticking to it.
Hillary 2.0 would be very different from her 2008 operation, which had run aground in part because her campaign had failed to master the fundamentals. All over the map, they had been outmaneuvered; even where Clinton won, Barack Obama's more nimble and sophisticated team had somehow managed to squeeze out extra delegates.
Like Mook, Marlon Marshall had been a part of that failed effort.
When he joined the 2016 campaign as its director of state campaigns and political engagement, Marshall recalled, "one of the first things that Robby and I talked about was, what is our delegate strategy?"
Sen. Bernie Sanders of Vermont proved to be a formidable opponent. His anti-establishment message was in tune with the disgruntled left, and he raised money by the boatload. The first sign came in September, when he raised more than $25 million - just $3 million less than she did.
They also knew that the money and the enthusiasm of his supporters meant that Sanders could stay in the fight even as Clinton built up her delegate lead - and methodically snuffed out any realistic chance he had of securing the nomination.
The real surprise was how things played out on the other side.
Clinton's advisers had expected the Republicans, with their enormous field of candidates backed up by super PACs, to also have a drawn-out battle.
Although her campaign chairman, John Podesta, had been predicting privately since last summer that Donald Trump would be the GOP standard-bearer, none of her advisers expected him to clinch it as suddenly and decisively as he did.
After Texas Sen. Ted Cruz beat Trump in Wisconsin, Clinton's advisers even held a planning session to get up to speed on how a contested Republican convention would work and figure out what that meant for them.
Instead, when Cruz dropped out in early May, Clinton was effectively running two campaigns at once - the final stages of a primary race and the opening ones of a general election.
Clinton has never been a dazzling campaigner. Not one for mega-rallies, she prefers small, scripted settings where she can discuss the policy intricacies of heroin addiction, mental health treatment, college debt or gun control - all the while keeping her campaign press corps at arm's length.
There have also been times when her tone-deafness could be spectacular.
In March, during a CNN town hall in Ohio, she boasted that she was the "only candidate which has a policy about how to bring economic opportunity using clean renewable energy as the key into coal country," and added: "We're going to put a lot of coal miners and coal companies out of business."
Those words came back to haunt her in West Virginia. "I do feel a little bit sad and sorry that I gave folks the reason, or the excuse, to be so upset with me, because that is not what I intended at all," she told an out-of-work miner who confronted her about that comment.
Meanwhile, old questions about her character have been revived by an FBI probe into the security issues raised by her unauthorized use of a private email system while she was secretary of state.
And Democrats, unlike Republicans, are not generally receptive to do-overs by their failed candidates. They prefer to turn the page.
So it was both poignant and ironic that the day Clinton would celebrate making history as the first woman to clinch a major party's nomination was also the eighth anniversary of her concession to Obama.
That speech is remembered mostly for the line in which she declared that she had put 18 million cracks - the number of votes she had gotten - in "that highest, hardest glass ceiling."
But there was also what, in retrospect, sounded like a declaration that she would be back.
"Life is too short, time is too precious and the stakes are too high to dwell on what might have been," Clinton said. "We have to work together for what still can be."
"What have you done for Iowa today?" read the message Mook had scribbled on a whiteboard in Brooklyn. Whenever someone would erase it, he would write it again.
The way they ran Iowa was to be the test of whether Clinton and her team had really learned from their mistakes.
And in the end, it was also a caution. They barely squeaked by Sanders, who had gotten a late start there and who did not have anything close to Clinton's organization.
His huge rallies, and the fire he lit with young people in particular, stoked worries that Clinton might be in for a replay of 2008.
"We said from the beginning it was going to be close, that we weren't going to take anything for granted and that we were going to have to compete for every single supporter" in Iowa, recalled Matt Paul, her state director. "All of those things turned out to be true."
Still, a win was a win, and it was also a little bit of insulation against Sanders's 22-point blowout eight days later in New Hampshire.
Conceding in New Hampshire, Clinton was already looking forward to South Carolina and Nevada, both of which have more racially diverse populations than the first two states.
"Crack down on corporations that game the system. Stop other countries from taking advantage of us with unfair trade practices," she said, in a nod to Sanders's populist lines.
"But even all that is not enough," she added. "We also have to break through the barriers of bigotry. African American parents shouldn't have to worry that their children will be harassed, humiliated, even shot because of the color of their skin. Immigrant families shouldn't have to lie awake at night listening for a knock on the door. LGBT Americans shouldn't be fired from their jobs because of who they are or who they love."
It was within the minority communities that she would gain traction. Her campaign had considered Nevada's caucuses what one aide called "a coin flip," but she won by a surprisingly comfortable five points.
And in South Carolina, the margin was a staggering 48 points.
Averaging across all the primaries, Clinton won 78 percent of African American voters, to Sanders's 21 percent, and Latinos by 60 percent to his 39 percent. Among whites, he narrowly edged her out, 49 percent to 48 percent.
The age disparity was also significant - and worrisome for Clinton, who needs younger voters to rally around her this fall, as they did for Obama.
Sanders won Democrats ages 18 to 29 by a 43-point margin in primary season. The two candidates ran close to even among voters in their 30s and 40s. Clinton carried older voters handily, winning the 45-to-64 age group, which made up 40 percent of the Democratic primary electorate, by an average of 28 points.
But Mook's mantra remained the same: It's all about the delegates.
After his loss in South Carolina, Sanders barely contested delegate-rich states in other parts of the Old South, concentrating instead on places where he could beat Clinton - such as Oklahoma.
That made sense in some way, in that it maintained the appearance of momentum and kept his supporters' enthusiasm going.
"They were going for wins, instead of spreading out their resources to narrow the margins everywhere," a key calculation, given the Democrats' system of proportionally allocating delegates, said one top Clinton campaign aide, giving a frank assessment in return for anonymity.
"It was a strategy for staying in the race. It wasn't a strategy for winning," the aide added.
At one point in April, Sanders could count seven victories out of the previous eight contests. But that string of wins did little to cut into Clinton's delegate lead, thanks to the way the Democrats' proportional system works. In Wyoming, for instance, he got 56 percent of the vote, but he and Clinton came out with seven delegates each.
Yet Sanders's superior financial resources required Clinton's campaign to make some calculations of its own.
Clinton had to be careful, for instance, in deciding where to buy television advertising. Instead of running spots in the expensive Dallas market, for instance, the campaign bought time in Waco, which was cheaper and had the potential to yield more delegates. Macon, Georgia, made more sense than Atlanta because the campaign could reach into more congressional districts while spending less.
"Even though no one would have fathomed it, we ended up being the leaner, meaner campaign and were more efficient," said spokesman Brian Fallon.
In accumulating delegates, Mook thought there were three big milestones: March 1, a.k.a. Super Tuesday, when there were contests in a dozen states and territories, including Texas and Georgia; March 15, another big round, including Florida, Ohio and Illinois; and a smaller trove on March 26, which would make her lead all but insurmountable.
In retrospect, those contests turned out to be as decisive as she had hoped. As of last weekend, Clinton held a lead of roughly 290 pledged delegates - nearly half of which could be attributed to Texas and Florida alone.
But there were also miscalculations, the biggest of which was Michigan. Just days before the March 8 primary, public surveys had Clinton up by double digits; Sanders ended up winning by a point and a half.
Clinton strategists do not have an explanation for what went wrong. They say their internal polls had the race much closer. But they also acknowledge that they made a mistake by concentrating their efforts in Detroit and Flint, while neglecting the rest of the state. It was a mistake they vowed not to repeat.
By the beginning of May, they faced a delicate dilemma. Clinton did not want to appear dismissive of Sanders or the fact that there were more primaries to go. But with the GOP contest over, they could not afford to wait any longer to get on a general-election war footing. The campaign started quietly staffing up in the battleground states and now has state directors, as well as communications and organizing operations, in 10 of them.
One of the things that has worried some Democrats is the question of how a by-the-book candidate like Clinton would deal with someone as wildly unconventional as Trump.
When violence broke out ahead of a Trump rally in Chicago in March, forcing him to cancel, he took to television to encourage his fans to blame Sanders's supporters.
Clinton remained silent for hours, and her initial response was tepid. It was not until the next day that she accused Trump of setting the tone that encouraged the melee. "If you play with matches, you're going to start a fire you can't control," she said in St. Louis.
But she found her footing more quickly the night of the Pennsylvania primary.
Trump, with the GOP nomination in hand, had been vowing to recalibrate his style and become more presidential. His chief strategist, Paul Manafort, had assured members of the Republican National Committee in a closed-door briefing that the real estate mogul had merely been playing a part in the primary, that Trump would begin "evolving into the part that you've been expecting. The negatives will come down, the image is going to change."
That was exactly what Clinton and her team expected as well - and it worried them. But so far, those fears haven't been realized.
In the car on the way to the airport in Philadelphia, they heard of Trump's latest fusillade.
"Frankly, if Hillary Clinton were a man, I don't think she'd get 5 percent of the vote. The only thing she's got going is the woman's card," Trump said. "And the beautiful thing is, women don't like her. Look how well I did with women tonight."
On the short flight to Teterboro, New Jersey, they deliberated what to do. Should she express outrage? Should she dispute the fairness of what he had said?
As it happened, the campaign's digital staff had already prepared a video of one of Clinton's often-used lines, which she had repeated that night: "If fighting for women's health care and paid family leave and equal pay is playing the woman card, then deal me in."
"That," communications director Jennifer Palmieri told the others on the plane, "is our only response."
In retrospect, Palmieri said, "that was the night he became the Republican nominee. It was important to freeze that moment in time." The next two days saw the biggest online fundraising of the entire campaign.
In San Diego last week, Clinton eviscerated Trump in a speech billed as a foreign policy address. Her technique was to use Trump's own words to make the case against him.
Her allies cheered.
"It put a lot of Democratic bed-wetting on pause," said one campaign official. "Now they can visualize how we will take the fight to him."
Campaign officials said they are already planning a similar speech focused on the economy.
But they also insist that they cannot count on the Republican nominee to be his own undoing.
"We can't go into it thinking our opponent will excite our base. We have to give people a reason to vote for us, too," Marshall said. "We have an opportunity to go out there and earn it."
Clinton has already made history by locking up the nomination. And she has shown that she can learn from her own mistakes. Now comes the biggest chance of all, and this time, there will be no margin for error.
• The Washington Post's Anne Gearan in New York, Abby Phillip in Los Angeles and Scott Clement in Washington contributed to this report.