Phase transition of photons and gravitons in a Casimir box