If it’s legal to smoke weed with your friends in two years, you can thank Silicon Valley tech money, Colorado and the emerging cannabis industry.

An organized and well-funded alliance is behind Proposition 64, the Adult Use of Marijuana Act, with proponents outspending opponents 70-to-1 in an effort to turn the tide in the state’s war over weed.

With nearly $18 million in backing thus far, the detailed 62-page ballot measure is a far cry from California’s last failed effort — 2010’s Proposition 19, a paltry four-page initiative that managed to anger both stoners and law enforcement officials.

“Not that long ago, this would be a fringe effort, and all the money would be on the ‘no’ side,” said Corey Cook, dean of the School of Public Policy at Boise State University, who follows the marijuana debate. “Now the money is on the ‘yes’ side.”

If the initiative passes, the state won’t go up in a big puff of smoke — there will still be laws, regulations and taxes — but it could create a dramatically altered landscape for cannabis.

An ounce of marijuana in your purse would be perfectly legal. So would eight grams of “concentrate.” You could grow up to six plants inside your home, keeping what you harvest. And you would no longer have to buy weed from sketchy strangers or fake an illness to get a “medical marijuana” card. Instead, you could visit a retail shop or a private smoking lounge. (Smoking pot in public will still be against the law.)

A politically powerful duo — tech billionaire Sean Parker and Lt. Gov. Gavin Newsom, a candidate for governor in 2018 — have linked up to advocate for Proposition 64.

The measure also is supported by members of the nation’s burgeoning marijuana industry, like the Newport Beach-based Ghost Management Group, which donated $750,000 and invests in pot-focused technology, hardware and software businesses such as WeedMaps, the Yelp for medical marijuana shoppers.

California — the spiritual home of the Grateful Dead, Cheech & Chong and the TV show “Weeds” — in 1996 became the first state to give the green light to medicinal marijuana.

But efforts to legalize recreational pot have stalled as four other Western states — Colorado, Washington, Oregon and Alaska — and the District of Columbia moved forward with legalization. And while there have been substantial problems — such as children becoming sick by eating cannabis-infused “edibles” — the sky didn’t fall.

“Overall support for marijuana legalization seems to have been increasing. This is evident in opinion polls and in the increasing number of states that have decriminalized, medicalized or legalized marijuana,” said Jeffrey Miron, an economist at Harvard University and the libertarian Cato Institute.

State legislators, however, are scrambling to keep road safety laws on pace with the new marijuana laws. Colorado, where weed became legal in January 2014, still hasn’t figured out whether the state’s roads are less safe. But in Washington state, marijuana use has been identified as a growing factor in fatal crashes.

And Colorado’s laws on labeling and child-resistant packaging have been unable to stop an increase of young kids ending up in the emergency room after accidentally consuming marijuana, although pharmaceuticals and household products still account for most toxic toddler exposures, according to a study in the medical journal JAMA.

A new USC Dornsife/Los Angeles Times poll found that 58 percent of California voters believe marijuana use should be legal. So does California Sen. Dianne Feinstein. Prominent physicians like Dr. Stan Glantz, an anti-tobacco activist at UC San Francisco, cite evidence of health risks like cancer, heart attack, stroke, brain function and addiction, warning that legalized marijuana could “just replace a criminal justice problem with a public health problem.”

Gov. Jerry Brown hasn’t taken an official position, but he once half-joked that California could lose its competitive edge if too many residents get high. “The problem with anything, a certain amount is OK. But there is a tendency to go to extremes,” he said in a 2014 interview. “If there’s advertising and legitimacy, how many people can get stoned and still have a great state or a great nation?”

The “no” campaign says Proposition 64 is just a brazen move to enrich the cannabis industry.

“This is all about making money,” said Andrew Acosta, a lobbyist for the opposition. “The marijuana industry is much more organized and much more prevalent than before. They’re looking at this as a real investment.”

Here’s another complication: Whether the measure passes or not, marijuana will still be illegal under federal law. It’s classified as a Schedule 1 narcotic, along with heroin — which scares away serious institutional investors, credit card companies and major banks.

Opponents to legalization, however, are facing challenges on a scale they have not seen before.

They’ve raised a mere $254,385 — less than half the sum they had to fight Proposition 19 six years ago.

In contrast, former Facebook president and Napster co-founder Parker has donated more than $3.8 million of the $17.9 million raised by supporters.

The foundation’s board of directors includes prominent Silicon Valley players like Tom Van Loben Sels of the Palo Alto-based tax consulting firm Apercan Partners and Divesh Makan of Iconiq Capital, an exclusive billionaires club that acts as an investment advisory office and a venture capital fund.

Proposition 19, which lost by seven percentage points, was conceived by one man: pot-shop owner Richard Lee of Oakland. It was “a kamikaze effort,” said Dale Sky Jones of Oakland’s Oaksterdam University, dubbed “the Harvard Business School of marijuana” by weed wags.

Short on time and money, the 2010 measure offered just a general framework, not specifics. It didn’t have a clear tax plan.

Six years in the making, Proposition 64 was the result of dozens of statewide meetings, negotiations between sparring factions and weeks of drafting.

“We stared at it from so many different directions,” Jones said. “Collaboration and compromise — very necessary and always messy. That’s how Prop. 64 got born.”

Lessons have been learned from the other states, then adapted to fit the size and complexities of California, said Chris Lindsey of the Marijuana Policy Project and Lynn Lyman of the Drug Policy Action.

“No two states are alike,” Lindsey said. “But every state that passes a marijuana-related law has the benefit of the state that has gone before them.”

The measure levies a 15 percent state excise tax, a $9.25 per ounce tax on all commercially cultivated flowers and leaves and a sales tax — plus whatever taxes cities and counties might levy — which could generate up to $1 billion in annual revenue, according to the state Legislative Analyst’s Office. It also gives local control to cities and counties, so they can decide if, how and where they want retail shops.

But Proposition 64’s biggest advantage over previous efforts is major state regulation — right around the corner: In January, California will make history by moving away from an unregulated “gray” medical marijuana marketplace to a formal state-run regime, created by the new California Medical Marijuana Regulation and Safety Act.

The law creates a new Bureau of Marijuana Control, which will work with the Department of Consumer Affairs, Department of Public Health and Department of Food and Agriculture. Among other things, it requires accurate labeling, appropriate childproof packaging and comprehensive lab testing on products. The same bureau could also regulate recreational use, proponents say.

Even after all this planning and fundraising, Proposition 64 may not — despite its “Get It Right, California!” slogan — be perfect, said Jason Kinney, a columnist for the yes campaign. But, he noted, the measure allows the Legislature to make changes.

“There are things that are going to happen that we are not expecting,” he said, “and we want to be prepared.”

PROPOSITION 64

What it would do: The measure will legalize recreational marijuana and establish a 15 percent sales tax as well as a cultivation tax of $9.25 per ounce for flowers and $2.75 per ounce for leaves, with exceptions for qualifying medical marijuana sales and cultivation.

What supporters say: The measure would use ‘best practices’ from other states where marijuana is legal, generating tax revenue and decreasing law enforcement costs.

What opponents say: The measure would result in more highway fatalities and would allow marijuana growing near schools and parks.

How much money is being raised? Proponents collected $17.7 million as of Sept. 8. The opponents have raised $254,385.

Source: California’s Secretary of State’s Office