Okay, I know this is RPG 101, but I'm having a hard time with it for some reason. Here's the situation:
The PCs are hiding in a cave waiting for the bad guys to arrive. The bad guys arrive. At this point, the PCs are aware of the other group but the bad guys aren't, so the PCs would get a surprise round if they launched an attack.
However, the PCs attempt to sneak closer to the bad guys before attacking (the better to be in range). The wizard makes a poor Stealth roll, meaning the bad guys hear something, but he still has total cover, being in the cave. Only the ranger in the front of the line of PCs is at the mouth of the cave and in the line of sight of two of the five bad guys; the other three can't see anything due to their positioning.
Do the PCs still get a surprise round, since they knew they were sneaking up on enemies and all the enemies know is that they heard something moving inside the cave?
Or does the PCs' movement in the cave, during which time the wizard failed his Stealth check, represent their surprise round (move action), and now it's round one of combat?
Or do the unseen PCs (and bad guys?) get a surprise round at the moment the wizard failed the Stealth check, while the ranger and the two bad guys who see him are waiting for round one?
Or something else entirely?
I get the feeling I'm overthinking this and would appreciate some clarity.