How does a magnet actually work?
Magnetism comes from electrons, and specifically from a quantum property called spin — the everyday picture of a magnet as containing tiny arrows is closer to correct than most simplifications, though what the arrows are is genuinely strange.
The origin. Every electron behaves as a tiny magnet, because of its intrinsic spin and, to a lesser extent, its motion around the nucleus. In most atoms these effects cancel out — electrons pair up with opposite spins, and the atom has no net magnetism. In a few elements, notably iron, cobalt and nickel, the arrangement of electrons leaves unpaired spins, so each atom is magnetic.
Why that is not enough. Most materials with unpaired electrons are only weakly magnetic, because their atomic magnets point randomly and cancel. What makes iron special is a quantum effect called exchange interaction, which makes neighbouring atoms energetically prefer to align with each other. Whole regions — domains, typically microscopic — spontaneously line up.
Magnetised or not is simply a question of whether the domains agree. In an unmagnetised iron bar, domains point in all directions and cancel. Apply an external field and domains aligned with it grow at the expense of others; in a hard magnetic material they stay that way when the field is removed, giving a permanent magnet. In a soft material like the iron in a transformer, they relax back, which is what you want there.
Why heat destroys it. Above a material-specific temperature — the Curie point, 770°C for iron — thermal agitation overwhelms the alignment and the material abruptly stops being ferromagnetic. Dropping or hammering a magnet also disrupts domains, which is why magnets weaken with rough handling.
Why magnetism and electricity are the same thing. A moving charge produces a magnetic field, and a changing magnetic field produces a current — the basis of every motor and generator. Relativity shows the two are aspects of a single electromagnetic field seen from different frames of reference.
Why there are always two poles. No isolated magnetic pole has ever been found; cut a magnet and you get two complete magnets.