You’ll need a little ancient Greek here.
The –demic suffix comes from demos, which means ‘the people’, ‘the community’. Demos is the root of democracy (‘rule by the people’).
The epi- bit comes from the Greek for ‘upon’, ‘at’, ‘close to’. Think of the epicentre of an earthquake.
Pan-, on the other hand, means ‘universal’. Pandemonium is total confusion or chaos; pantheism is the belief that the divine is present everywhere in the universe.
An epidemic is a disease that touches a fairly localised group; a pandemic reaches far beyond the local.
One would therefore say There was an epidemic of meningitis among high-school students in the downtown core, but The world was severely affected by the Spanish flu, AIDS and COVID-19 pandemics.
The earliest use of pandemic appears to be 1666 (a year of plague in London); epidemic goes back further – to 1603 in its current form, to the late fifteenth century as epidemy.