Same colours push apart. Different colours pull together.
Or tap a round spot beside the track to put a magnet there. Tap again to flip it, and again to take it away.
Poles. Every magnet has a north (N) and a south (S) pole. Like poles repel; unlike poles attract. Here each end of a car carries its own small magnet, and its outward-facing pole is the colour you see (red = N, blue = S). In real bar magnets the two ends of one magnet are always opposite; the toy lets you flip each end separately so you can try every combination.
Force and distance. The pull or push gets weaker as the magnets move apart. We use a simple law: F = K / rn with r the distance between the poles. For two single "point" poles n = 2 (double the distance, a quarter of the force: the "Medium" button). "Short" uses n = 3 and "Long" uses n = 1 so you can see the difference. Two real small bar magnets far apart fade even faster (about n = 4), so the toy law is a simplification, but the idea "closer is much stronger" is true.
Motion. Each car follows Newton's second law, m a = Fmagnets - Ffriction. Only the part of the force that points along the track can move the car; magnets on the side of the track also pull it forwards or backwards as it passes. A tiny softening length (0.12 m) stops the force from becoming infinite when poles touch.
Coupling. Two cars "couple" when unlike poles meet, the attraction holds them together and they stop moving relative to each other.
Float mode makes the wheel friction about ten times smaller, like a maglev train that does not rub on the track. In this toy the cars only look like they hover; real maglev trains lift with magnets and need active control, because a set of fixed magnets alone cannot hold something floating stably (Earnshaw's theorem).
The check. "Check the maths" measures the force the simulator really produces at 7 distances and fits a straight line on a log-log graph (its slope is the exponent). It then shoots a car at a repelling magnet and compares how close it gets with the number you get from energy conservation (work done by the force = starting kinetic energy).
Simplifications. Cars move in a straight line, poles are points, we ignore the far pole of each magnet, and no heating or magnetic materials are modelled.