Republicans across Texas breathed a deep sigh of relief Tuesday night when Sen. Ted Cruz eked out a victory over Beto O’Rourke, who ran the most competitive statewide campaign a Texas Democrat has run in decades.

But Republicans in the Lone Star State shouldn’t take much comfort from the win. Yes, Cruz held on to his Senate seat, and yes, every GOP incumbent running in a statewide race won reelection. Nevertheless, a closer look at their margins of victory, along with massive voter turnout and structural changes in the electorate, tells a troubling tale for the future of the GOP in Texas.

The reality is that the Republican Party is losing ground in Texas, whose fast-growing population is increasingly willing to vote for Democrats, especially in the state’s large cities and suburbs. It’s easy to see this dynamic at play in the Cruz-O’Rourke race. Cruz won by less than 3 points, and only captured a couple hundred thousand more votes than O’Rourke out of a record-setting midterm turnout of more than 8.2 million voters. Compare that to 2012, when Cruz won by more 1.2 million votes and coasted to victory with a 16-point margin.

Even more ominous for Texas Republicans is where Cruz lost to O’Rourke. Tarrant County, which encompasses Fort Worth and is America’s most conservative large urban county, went for Cruz by 16 points in 2012, with Cruz winning nearly a million more votes than his Democratic opponent that year. Long considered a GOP stronghold, Tarrant County is the only one of the Texas’s five largest counties that hasn’t backed a Democratic presidential candidate in the past decade. (In 2016, it went for Trump by more than eight points.)

But on Tuesday, O’Rourke narrowly carried Tarrant County, edging out Cruz by less than 4,000 votes. A similar dynamic played out in central Texas, where O’Rourke won Hays and Williamson counties, which border the deep-blue state capital of Austin in Travis County, but traditionally have been Republican strongholds. Cruz won both in 2012 by sizeable margins, but on Tuesday O’Rourke won both, carrying Hays County by more than 15 points.

It Wasn’t Just The Cruz-O’Rourke Race

The U.S. Senate race wasn’t the only surprise for the Texas GOP. In every statewide race, Republican incumbents who won by double-digit margins in the 2014 midterms saw those margins tighten, sometimes dramatically. Lt. Gov. Dan Patrick, Attorney General Ken Paxton, and Agriculture Commissioner Sid Miller all won by 20-point margins four years ago. On Tuesday, Patrick and Paxton won by less than five points, and Miller won by less than 4.

In congressional races, not all Republican incumbents survived. In Texas’s Seventh House District, which includes parts of Houston and its eastern suburbs, Democrat Lizzie Pannill Fletcher, a first-time candidate, handily defeated nine-term Republican incumbent John Culberson. Perhaps the largest congressional upset was in the Dallas-area 32nd House District, where Republican incumbent Pete Sessions lost to former Obama administration official and Baylor linebacker Colin Allred.

Both of these races demonstrate how Texas’s shifting demographics pose a challenge for the Texas Republican Party. Democrats’ hold on urban areas is tightening, with every major urban county in the state now firmly in the hands of the Democrats. In some cases, Democratic dominance is overwhelming. In Harris County, home to Houston, one of the largest metro areas in the country, every single elected office is now held by a Democrat.

It’s easy for Republicans to mock the Democratic mantra that “demographics are destiny,” especially since Democrats keeping losing statewide races in Texas. But to ignore the changes underway across the state would be naive. Despite the stereotype among coastal elites that Texas is a backwater of oil fields, cattle ranches, and gun-loving cowboys, Texas is a diverse, urban state. Seven of the country’s 15 fastest-growing cities are in Texas, and the state’s booming economy continues to draw in new residents from all over the country and the world, accelerating its urbanization and diversification.

Meanwhile, reliably Republican rural areas are emptying out. With Democrats ascendant in Texas’s cities, and beginning to make inroads in the suburbs, Texas Republicans won’t be able to count on rural, exurban, and suburban voters to keep them in office. They will have to begin competing for Texas’s major cities if they want to win future statewide races.

How Texas Can Stay Red

To do that, the state’s Republican Party will have to rouse itself and rebuild what was once a formidable statewide organization. O’Rourke made headlines by visiting all 254 counties in Texas, and the state GOP would be wise to emulate O’Rourke in this regard and begin building a presence in Democratic bastions from El Paso to Brownsville to Dallas to Houston.

Above all, the Texas Republican Party needs to reach out to Hispanic voters in a sustained and sincere way. Texas Republicans have always done relatively well among Hispanics, at times winning 40 percent or more, but with a fast-growing Hispanic population and a president who often seems hostile to immigrants, they’ll have to do better in the future.

O’Rourke was certainly a uniquely appealing Democrat for Texas, and his name on the ballot doubtless helped to bring voters out in record numbers for a midterm. But combined with these other structural factors, Texas Republicans should have heard alarm bells on Tuesday night, even as they celebrated yet another electoral victory.

The fact is, Texas can turn blue. Key parts of the state are even now turning blue. As troubling as that might be for Texas Republicans, it’s a prospect that Republicans and conservatives nationwide should also be worried about. Texas is and always has been an exaggerated version of America, where prosperity and opportunity exist alongside dramatic upheaval and uncertainty. Its model of low taxation and light regulation stand as a counterweight to the California model of ruinously high taxes and crushing regulation. In a very real way, Texas and California represent two possible futures for America.

But if the Texas GOP can’t figure out how to win urban and suburban voters, and persuade Hispanics that the GOP is their natural political home, then the Lone Star State will eventually turn blue—and as Texas goes, well, you know the rest.