Explainer: Why Spain's election is so open, and how it may pan out

MADRID (Reuters) - Spain is readying for one of its most tightly contested national elections in decades, with the result too close to call and at least five parties from across the political spectrum with a chance of being in government.

Sunday’s ballot is set to mark a number of firsts: the first coalition government since Spain’s return to democracy in the late 1970s, the first far-right lawmakers since 1982, and the first campaign since the financial crisis not centered on the economy.

Lengthy coalition talks are expected to follow the vote, feeding into a broader mood of political uncertainty gripping Europe.

Campaigning ends at midnight on Friday, and polling stations will close at 8:00 p.m. (1800 GMT) on Sunday. The count should be all but finalised by midnight.

Here’s what’s at stake:

WHO WILL WIN?

No party will win enough seats to form a government on its own, and opinion polls - the last of which was published on Monday before two televised debates between the leaders of four of the five main parties - point to a deeply fragmented parliament.

Prime Minister Pedro Sanchez’s Socialists are in the lead and tipped to win just under 30 percent of votes, according to a poll of polls by newspaper El Pais.

That would give them the best chance of leading a coalition government, but as they would need to team up with one or more allies, there is no guarantee this would work.

Several other scenarios - including a right-wing coalition or a repeat election - remain possible, and it could be months before a new prime minister is chosen.

For now, a range of possible outcomes are all within opinion polls’ margin of error.

WHY IS THIS SO COMPLEX?

Final polls put the proportion of undecided or wavering voters as high as four in ten. [nL8N21R35X]

Pollsters have also been struggling to predict how well new far-right party Vox will fare, though all agree it will get lawmakers, the first of that political hue in almost four decades. [L8N21T1MH]

The impact of Monday’s and Tuesday’s election debates, from which Vox was excluded on legal grounds, is a further unknown. Many political analysts say the candidate who performed best was Pablo Iglesias, leader of anti-austerity party Podemos - which had been losing a lot of ground in opinion polls. [nL8N21G6BX]

The 350 deputies in Spain’s lower house are elected in 52 constituencies, whose size varies widely. As the number of contenders has increased, forecasting the winners has got tougher, particularly in small rural areas.

Parties unused to coalition-building are also unlikely to strike any post-election deal in Madrid that might jeopardize their chances in local and regional ballots due on May 26.

Furthermore, most parties are either undergoing internal upheavals or have new leaders, meaning much could still change in terms of strategy and alliances.

Spaniards will also elect 208 representatives to the Senate, which has a low political profile and has been controlled by the conservative PP since 2011.

WHO WILL BE PRIME MINISTER?

Under the most optimistic scenario for the Socialists, Sanchez could stay on as prime minister with just one ally, Podemos. [nL5N21Z3DT]

But opinion polls show the Socialists and Podemos are likely to need the backing of smaller, nationalist parties, possibly from Catalonia, which would replicate the combination that allowed Sanchez to become prime minister in June.

Concessions the smaller parties would seek in return - and pressure from right-wing parties already accusing Sanchez of being a “traitor” for being open to dialogue with Catalan secessionists - make any such alliance a tough though not impossible ask.

According to final polls, the three rightist parties combined - the PP, center-right Ciudadanos and Vox - would not have a parliamentary majority. But that is also a margin-of-error call.

One scenario of a likely majority would be between Ciudadanos and the Socialists. But Ciudadanos chief Albert Rivera has ruled out a deal with Sanchez who - while not excluding the option altogether - said on Tuesday such a pact was not part of his plans either.

As the clear poll leader, Sanchez is looking to retain as much leeway as possible to explore alternative options, none of which appear ideal.

One outcome does seem certain, however: confirmation of the end of the two-party system that began with Spain’s return to democracy and started unraveling in 2015.

WHAT ARE THE MAIN ISSUES FOR VOTERS?

The campaign has focused on identity and values, relegating the economy to a rare subsidiary role. [nL5N21X2RR]

Catalonia’s independence drive, which has polarized the nation as well as the region, is a high-profile factor, especially with 12 of its former leaders standing trial. [nL5N20S4Y7] [nL5N2070XP]

PP, Ciudadanos and Vox are competing for the anti-separatist vote but the Socialists, after refusing to give in to Catalan demands to secure their backing for the budget, will also aim to use the issue to their advantage. [L5N22410A]

With the rise of Vox and with PP veering to the right and the Socialists campaigning on a progressive stance, the parties are differentiating themselves on issues ranging from women’s rights to the removal of former dictator Francisco Franco’s remains from a grand mausoleum. [nL8N21F7CO] [nL5N20T284]

All the main parties have traded accusations of corruption, while the economy, forecast to grow a relatively robust 2.2 percent this year, has been a largely peripheral campaign issue.

WHY SHOULD MARKETS AND THE EU CARE?

Spain has had a succession of minority or caretaker governments over the past three years, meaning structural reforms have been delayed.

And, while the Socialists have managed to adopt some economic measures including an increase in pensions and minimum wages, their rolling over of the 2018 budget means a number of tax hikes will not enter force, making it harder to cut the deficit from 2018’s 2.48 percent of economic output. [nL8N21G1RO]

Additional reporting by Belen Carreno; Editing by Andrei Khalip and John Stonestreet