Fellow 996 targa owner here, adding my twopenneth.
I second (or third) the recommendation for Iain ‘deMort’ from Precision Porsche - what he doesn’t know about Targa roofs isn’t worth knowing! You can either email him or he’s a frequent poster on the 911uk forums.
Last year I had a problem where my glass hatch wouldn’t shut. It started when my battery went flat while the tailgate was open (went to start it, it barely turned over then alarm went off!). Once power was restored, I think the car then thought the tailgate was closed. The problem was resolved by a friend holding the tailgate down in the closed position while I locked and unlocked the car.
I am wondering whether yours is the inverse problem to mine, ie the hatch thinks it’s open and therefore ignores the ‘open hatch’ request.
From memory there are micro switches in the central latch which determine if the hatch is open or not. Before playing around with these I wonder whether disconnecting and reconnecting the battery might help to reset / recalibrate itself?
The only other thing I can think of is that your car might think the sunroof is open due to a faulty sensor (as you know you can’t open the hatch when the roof is even partially open). Not sure where the sensor for this is though
As and when you can open the hatch check the position of the rubber bungs in each bottom corner: these regulate how high the glass pops up when you open it.
I would start simple and take it from there. Sounds like you can now open the hatch so that’s a start!
Please let us know how you get on.
Thanks