The twitter thread links to this article about stable equilibria explaining some of the physics
https://physicstoday.scitation.org/doi/10.1063/PT.3.4373
which in turn links to this paper, E. N. Gilbert's How Things Float, which gives much more detailed mathematical explanation
PDF: http://111.90.145.71/scimag/get.php?doi=10.2307/2325023&key=...