How to recognize which output is used as input for a new transaction
A vin contains both a txid and a vout.  As you've correctly identified, the txid part is the transaction that contains the unspent transaction output (UTXO) being used for this input.  The vout part is a zero-based index for which output on the transaction is being used.

For example, if vout is 0, this input points to the first output of the transaction.  If vout is 3, it points to the fourth output.  Think of the these parts of the vin structure as being an address for a particular UTXO on the blockchain.