:root {
  --width: 100vw;
  --height: 100vh;

  --bg-color: #001437;
  --bg-mid-color: #000f2c;
  --cube-color: #b8fbc3;
  --top-color: #7898fb;
  --bottom-color: #5ce5d5;
  --cube-bg-color: #b8fbc369;
  --cube-back-color: #79a580;

  --perspective: 500px;
  --matrix-width-multi: 4;
  --matrix-height-multi: 2.5;
  --matrix-border: 25px;
  --matrix-angle: 90deg;
  --matrix-speed: 1s;
  --cube-speed: 7s;
  --cube-border: 4px;
  --cube-edge-multi: 4;

  --matrix-edge: calc(var(--width) / 5);
  --matrix-edge-half: calc(var(--matrix-edge) / 2);
  --matrix-border-half: calc(var(--matrix-border) / 2);
  --matrix-width: calc(var(--width) * var(--matrix-width-multi));
  --matrix-height: calc(var(--height) * var(--matrix-height-multi));

  --cube-edge: calc(var(--matrix-edge) * var(--cube-edge-multi));
  --cube-border-radius: calc(var(--cube-border) * 4);
  --cube-edge-half: calc(var(--cube-edge) / 2);
  --cube-edge-quarter: calc(var(--cube-edge) / 4);
  --cube-edge-half-minus: calc(var(--cube-edge-half) * -1);
  --cube-edge-quarter-minus: calc(var(--cube-edge-quarter) * -1);
  --cube-edge-three-quarter: calc(var(--cube-edge-half) + var(--cube-edge-quarter));
  --cube-edge-three-quarter-minus: calc(var(--cube-edge-three-quarter) * -1);
  --cube-start-pos: calc((var(--matrix-height) + (var(--cube-edge) * 2)) * -1);
  --cube-end-pos: var(--cube-edge-quarter);
}

@keyframes matrix-bg {
  from {
    background-position: 0 0, 0 0, 0 0;
  }
  to {
    background-position: 0 0, 0 0, 0 var(--matrix-pos);
  }
}

@keyframes cube-move {
  from {
    transform: translateZ(var(--cube-start-pos));
  }
  to {
    transform: translateZ(var(--cube-end-pos));
  }
}

@keyframes cube-opacity {
  from {
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
  90% {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@keyframes halu {
  0% {
    perspective: var(--perspective);
  }
  25% {
    perspective: 2px;
    transform: rotateZ(0deg);
  }
  50% {
    transform: rotateZ(360deg);
  }
}

@keyframes off {
  0% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

html,
body {
  margin: 0;
  padding: 0;
  width: var(--width);
  height: var(--height);
  overflow: hidden;
}

.zigzag {
  filter: blur(1px);
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: #8a0303;
  box-shadow: inset 0px 0px 69px 13px rgba(0, 0, 0, 1);
  background: linear-gradient(135deg, #02004b 25%, transparent 25%) -10px 0,
    linear-gradient(225deg, #02004b 25%, transparent 25%) -10px 0, linear-gradient(315deg, #02004b 25%, transparent 25%),
    linear-gradient(45deg, #02004b 25%, transparent 25%);
  background-size: calc(2 * 10px) calc(2 * 10px);
}

.container {
  box-sizing: border-box;
  /* opacity: 0; */
  width: var(--width);
  height: var(--height);
  display: flex;
  overflow: hidden;
  position: absolute;
  align-items: center;
  justify-content: center;
  transform-style: preserve-3d;
  perspective: var(--perspective);
  background-image: linear-gradient(
    to bottom,
    var(--bg-color) 0%,
    var(--bg-color) 45%,
    #000f2c 50%,
    var(--bg-color) 55%,
    var(--bg-color) 100%
  );
  animation: halu 10s ease-out 1s 2 alternate, off 5s step-start 13s;
}

.matrix {
  position: absolute;
  width: var(--matrix-width);
  height: var(--matrix-height);
  background-position: bottom;
  background-repeat: no-repeat;
  background-image: linear-gradient(var(--matrix-bg-angle), transparent 10%, var(--bg-color)),
    repeating-linear-gradient(
      to right,
      transparent 0,
      transparent calc(var(--matrix-edge-half) - var(--matrix-border-half)),
      var(--matrix-color) var(--matrix-edge-half),
      transparent calc(var(--matrix-edge-half) + var(--matrix-border-half)),
      transparent var(--matrix-edge)
    ),
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent calc(var(--matrix-edge-half) - var(--matrix-border-half)),
      var(--matrix-color) var(--matrix-edge-half),
      transparent calc(var(--matrix-edge-half) + var(--matrix-border-half)),
      transparent var(--matrix-edge)
    );
  animation-name: matrix-bg;
  animation-duration: var(--matrix-speed);
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}

.matrix.top {
  top: 0;
  transform-origin: top;
  transform: rotateX(calc(var(--matrix-angle) * -1));
  --matrix-pos: calc(var(--matrix-edge) * -1);
  --matrix-color: var(--top-color);
  --matrix-bg-angle: to bottom;
}

.matrix.bottom {
  bottom: 0;
  transform-origin: bottom;
  transform: rotateX(var(--matrix-angle));
  --matrix-pos: var(--matrix-edge);
  --matrix-color: var(--bottom-color);
  --matrix-bg-angle: to top;
}

.cube {
  position: absolute;
  transform-style: preserve-3d;
  animation: cube-move var(--cube-speed) linear 0s infinite;
  color: var(--bg-color);
  user-select: none;
  font-size: 2rem;
  line-height: 0;
}

.cube > div {
  position: absolute;
  animation-delay: inherit;
  animation-duration: inherit;
  animation-name: cube-opacity;
  animation-fill-mode: backwards;
  animation-iteration-count: inherit;
  animation-timing-function: ease-in-out;
}

.cube:nth-child(4) {
  animation-delay: calc(var(--cube-speed) * 0.25);
}

.cube:nth-child(5) {
  animation-delay: calc(var(--cube-speed) * 0.5);
}

.cube:nth-child(6) {
  animation-delay: calc(var(--cube-speed) * 0.75);
}

.cube > .front,
.cube > .back {
  width: var(--cube-edge);
  height: var(--cube-edge);
  border-radius: var(--cube-border-radius);
}

.cube > .front {
  transform: translateX(var(--cube-edge-half-minus)) translateY(var(--cube-edge-half-minus))
    translateZ(var(--cube-edge-quarter));
  box-shadow: 0 0 var(--cube-border) var(--cube-border) var(--cube-color),
    inset 0 0 var(--cube-border) var(--cube-border) var(--cube-color);
}

.cube > .back {
  transform: translateX(var(--cube-edge-half-minus)) translateY(var(--cube-edge-half-minus))
    translateZ(var(--cube-edge-quarter-minus));
  box-shadow: 0 0 var(--cube-border) var(--cube-border) var(--cube-back-color),
    inset 0 0 var(--cube-border) var(--cube-border) var(--cube-back-color);
}

.cube > .left {
  transform: translateX(var(--cube-edge-three-quarter-minus)) translateY(var(--cube-edge-half-minus)) rotateY(90deg);
}

.cube > .right {
  transform: translateX(var(--cube-edge-quarter)) translateY(var(--cube-edge-half-minus)) rotateY(90deg);
}

.cube > .top {
  transform: translateX(var(--cube-edge-half-minus)) translateY(var(--cube-edge-three-quarter-minus)) rotateX(90deg);
}

.cube > .bottom {
  transform: translateX(var(--cube-edge-half-minus)) translateY(var(--cube-edge-quarter)) rotateX(90deg);
}

.cube > .left,
.cube > .right,
.cube > .top,
.cube > .bottom {
  background-image: radial-gradient(circle, var(--cube-bg-color) 69%, transparent 100%);
}

.cube > .left,
.cube > .right {
  width: var(--cube-edge-half);
  height: var(--cube-edge);
}

.cube > .top,
.cube > .bottom {
  width: var(--cube-edge);
  height: var(--cube-edge-half);
}
