:root {
--boxcolor: #0ff7;
--rotate-speed: 30s;
--bounce-speed: 2s;
}
body {
background-color: #000;
min-height: 100vh;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
font-size: 75px;
perspective: 10em;
perspective-origin: 50% calc(50% - 2em);
}
.scene {
position: relative;
transform-style: preserve-3d;
animation: scene-rotate var(--rotate-speed) infinite linear;
@keyframes scene-rotate {
to { transform: rotateY(360deg); }
}
}
.ball {
width: 1em;
height: 1em;
border-radius: 50%;
background: lightblue;
position: absolute;
left: -.5em;
bottom: 1em;
background-image: radial-gradient(
circle at top,
lightblue, 50%, #000
);
animation:
ball-bounce var(--bounce-speed) infinite ease-out,
scene-rotate var(--rotate-speed) infinite linear reverse;
@keyframes ball-bounce {
0%, 100% { bottom: 0.5em; }
50% { bottom: 3em; animation-timing-function: ease-in; }
}
}
.ball-shadow {
position: absolute;
width: 100%;
height: 100%;
background-image: radial-gradient(#0007, #0000 50%);
animation: ball-shadow var(--bounce-speed) infinite ease-out;
@keyframes ball-shadow {
0%, 8%, 93.5%, 100% { transform: scale(1); opacity: 1; }
50% { transform: scale(2);
opacity: 0.5;
animation-timing-function: ease-in; }
}
}
.cube {
width: 2em;
height: 2em;
position: absolute;
bottom: -1em;
left: -1em;
animation: cube-height var(--bounce-speed) infinite linear;
@keyframes cube-height {
0%, 100% { height: 1.5em; }
8%, 93.5% { height: 2em; }
}
.front, .right, .back, .left {
position: absolute;
width: 100%;
height: 100%;
background: var(--boxcolor);
box-shadow: 0 0 0.5em #000a inset;
}
.front { transform: translateZ(1em); }
.right { transform: rotateY(90deg) translateZ(1em); }
.back { transform: rotateY(180deg) translateZ(1em); }
.left { transform: rotateY(270deg) translateZ(1em); }
.top {
position: absolute;
width: 2em;
height: 2em;
background: var(--boxcolor);
transform: translateY(-50%) rotateX(90deg);
box-shadow: 0 0 0.5em #000a inset;
}
.bottom {
position: absolute;
width: 2em;
height: 2em;
background: var(--boxcolor);
filter: brightness(20%);
bottom: 0;
transform: translateY(50%) rotateX(90deg);
box-shadow: 0 0 0.5em #000;
}
}
.floor {
position: absolute;
transform:
translate(-50%, -50%)
rotateX(90deg);
top: 1em;
width: 15em;
height: 15em;
background-image:
radial-gradient(#0000, #000a 75%),
repeating-conic-gradient(from 45deg,
#111 0deg 90deg,
#222 90deg 180deg);
background-size: 100%, 1em 1em;
}