Rough or hunting idle on a Miata is usually unmetered air, a weak spark event, or a dirty idle-air path, and pulling codes first tells you which camp you are in. A misfire code sends you one way; a clean scan with a wandering idle sends you another.
Work it methodically
…