Statistical Mechanics of Phases