When the window is not square, you don't have a cube, but a paralelogram.
Your style is
<figure class="left"
style="width: 227px;
height: 402px;
-webkit-transform: rotateY(-90deg) translateZ(113.5px);">4
</figure>
<figure class="top"
style="width: 227px;
height: 227px;
-webkit-transform: rotateX(90deg) translateZ(113.5px);">5
</figure>
That means that the distance between top and bottom is 402px (the height of the faces).
So, the translateZ of top and bottom should be the half of that (201 px) instead of 113.5 px as for the other sides.
Right now, your top face is ok, so may be the better solution, instead of translating both top and bottom 201px, would be to translate the bottom 402px - 113.5px (the height of the faces minus the translation of the top
I did the following changes:
var bottomTranslate = $(window).height() - cubeWidth;
$("#cube .bottom").css({
"-webkit-transform": "rotateX(-90deg) translateZ(" + bottomTranslate + "px)"
});
and the result is this
Why does the top panel work ?
You are taking as center of the parallelepiped a point that is the center of a cube having the dimensions of the maximum inner cube, and alligned to the top.
That means the placing the faces at the same distance of the center will work for the lateral faces (in vertical projection, the parallelepiped is a cube); will work for the top face (it's alligned so that this will work), but will fail for the bottom
Why when you set a transform to the cube in Javascript the buttons stop working ?
The buttons work by setting different classes to the cube div. This classes have precomputed transforms in the CSS, like this:
#cube.show-right {
transform: translateZ(-100px) rotateY(-90deg);
}
If you set a transform directly on the cube style, this has higher priority and changing the class is useless.
May be you could just set the dimensions of the cube (that are set only with javascript) a little bit smaller; or change all the dynamically applied CSS styles ...