Quite a piece of work. I will try to understand it.
A small correction:
margin-[top,bottom]: width of containing block, except for page context where it
^^^^^ height (I suppose).
Well, not according to the spec:
(my patch does not deal with the block-width / page-height issue correctly btw).