Hope this answers your questions...
When heat is added to a substance, the atoms and molecules begin to vibrate faster. As that happens the gap between them increases. Opposite happens when cooled, atoms and molecules begin to vibrate slower and the gap between each other decreases. Thus the motion and spacing between atoms signifies the state of matter of the substance.