best way to detect if vehicle is running
Most cars have 2 12V lines, a permanent one (12V from the battery) and switched, which is active after half a key turn in older cars, and after the ignition button activation in newer cars.
You can use a voltage divider and connect it to a digital IO to detect it. Also, add a varistor to it, car voltage lines have nasty spikes which can easily fry your electronics.

Detecting whether a motor is running or not, you need to sample the 12V line and see if it is above 12V. Usually, the alternator generates 13 to 14V.