Final answer:
When a massive star runs out of hydrogen to fuse, its outer layers expand and cool, turning the star into a red giant or red supergiant with a contracting core and expanding outer layers.
Step-by-step explanation:
When a massive star begins to run out of hydrogen to fuse, its outer layers of gas expand and cool. As the central hydrogen is depleted, the star's core begins to contract under its own gravity and heat up, but this contraction is not enough to maintain the star's size. Instead, the intense heat produced ignites hydrogen fusion in a shell surrounding the helium core, leading to an increase in energy output. This additional energy causes the outer layers to expand, while the core itself contracts and heats up, resulting in a more complicated stellar structure with multiple layers of fusion, like an onion.
The star becomes simultaneously more luminous and cooler, and moves upward and to the right on the Hertzsprung-Russell (H-R) diagram, indicating that its surface temperature is cooler even though it's brighter. Over time, massive stars turn into red supergiants, while lower-mass stars like our Sun become red giants. Although the core is contracting, the expansive outer layers make the star much larger and give it a redder, cooler appearance.