BRUSSELS (Reuters) - Even as British Prime Minister Theresa May battles critics in her own party, she may be closing in on a Brexit deal which has been stymied by arguments over the Irish border. Here’s how:

An EU flag is draped across the statue of Winston Chruchill in Parliament Square, as EU supporters, calling on the government to give Britons a vote on the final Brexit deal, participate in the 'People's Vote' march in central London, Britain June 23, 2018. REUTERS/Henry Nicholls

IS A DEAL POSSIBLE?

It might be almost done. Negotiators on both sides thought they may have cracked it 10 days ago, EU diplomats told Reuters. The stumbling block seemed to be May calculating that an EU demand for a special “backstop” clause for Northern Ireland could not win support from her own party and allies in parliament -- at least not just for the moment.

WHAT’S THE PROBLEM?

Both sides want to avoid a “hard border” on the island of Ireland -- customs posts that could reignite violence against British rule. Britain says Brexit won’t mean physical customs checks. The EU says it might -- and so it wants London to sign a treaty clause that could leave Northern Ireland inside the EU customs space. May and pro-British Belfast allies reject that as dividing the province from the mainland. Instead, May wants the EU to let all of the UK stay in the customs area for a time.

AND THE SOLUTION?

The EU has tried to ramp up assurances that its “Northern Ireland-only” backstop will not be triggered. Those assurances had previously been simply that a political declaration on the future EU-UK relationship, due to be agreed this year alongside the withdrawal treaty that would smooth Britain’s March exit, would state that a way would be found to avoid customs posts.

But, EU sources tell Reuters, negotiations this month saw the EU offer to strengthen that idea in the withdrawal treaty itself, bending an EU “red line” about pre-empting trade talks as part of an overall package deal to break the deadlock.

They also offered to extend the treaty’s transition period, when nothing will change, by a year to the end of 2021 to help ensure that a customs deal is ready to avoid a hard border. There could also be mechanisms to cooperate on any backstop.

BUT THERE’S STILL A HITCH?

There’s three.

SNAG ONE

The EU sees May’s “all-UK” backstop, keeping all of Britain inside the EU customs union, as a dodge to grab unfair advantage by giving a special deal intended for a small, troubled province to Europe’s third-biggest economy. It will insist on tough talks after Brexit to limit Britain’s access to the EU single market, even if it keeps customs ties that keep Ireland’s border open.

SNAG TWO

Brussels still wants a “Northern Ireland-only” backstop -- in case trade talks fail. It will play down the risk and may offer special joint mechanisms to oversee how the backstop works. But it’s still a problem for May. Her Belfast allies have threatened to vote down her budget next week and there is talk of a party leadership challenge. So she probably needs to wait.

SNAG THREE

The deal effectively keeps Britain in the EU customs union for the foreseeable future. The EU’s terms for accepting May’s “all-UK” solution may prompt accusations she has abandoned a vow to quit the customs union quickly in order to strike trade deals with other countries. EU negotiators, diplomats say, would play along with language to help May deny that it’s a customs union -- but she would have a lot of explaining to do on such a deal.

SO WHAT’S NEXT?

Time will tell. EU officials are waiting to see how May can handle her domestic problems and are prepared to have to wait until December for a deal that can then be ratified by both parliaments. Later than that and there will be more talk of a “no deal” in which Britain lurches chaotically out on March 29.