Inside a leaf
The leaf is the plant's solar collector: flat, broad, held into the air to catch light while exchanging gases and not losing too much water. Almost every visible leaf trait is a tradeoff among those three.
The layers
Top to bottom: a waxy cuticle (waterproofing), a transparent upper epidermis (the leaf's outer skin of cells), the palisade mesophyll , the spongy mesophyll, the vascular bundles (veins, bringing water in and sugar out), and a lower epidermis where most stomata sit.
The palisade layer is tightly packed and dense with chloroplasts, the green compartments inside a cell where photosynthesis happens. The spongy layer below it is loose, with air spaces for gas to circulate.

Fig. 7. Light enters through the clear cuticle and epidermis; the palisade layer does most photosynthesis; spongy mesophyll handles gas flow; veins deliver water and remove sugar; stomata below manage gas exchange.
Stomata : the adjustable pores
A stoma is a tiny pore formed by two guard cells, shaped like a pair of curved sausages. When they take in water and swell, their shape and the stiffening of their walls make them bow apart, opening the pore between them; when they lose water they slacken and the pore closes. Essentially hydraulic. (Exactly which part of the wall does the stiffening is still argued over, so don't let anyone tell you it's settled; see Carter et al., 2017.)
Light opens them, to take in CO2. What closes them is water stress: dry air pulling moisture out of the leaf faster than the roots can replace it, or dry substrate signaling the plant to shut down (Hetherington & Woodward, 2003). Warmth on its own does the opposite of what most people assume. A warm leaf with plenty of water tends to open its stomata wider, because evaporation is how it cools itself (Urban et al., 2017). Once the stomata do shut, CO2 can no longer get in and photosynthesis falls even under bright light (Lawson & Blatt, 2014). That's why a plant in a sunny, bone-dry room can be flooded with light and still barely growing, and why the fix is humidity and water rather than shade.

Fig. 8. Guard cells open (left) when full of water, closed (right) when not. The plant trades water loss for CO2 every time it opens.
Strengthen your understanding
Try these in your head first, then open to see.