.glitch {
  position: relative;
}

.glitch > img:nth-child(2),
.glitch > img:nth-child(3) {
  position: absolute;
  top: 0;
  left: 0;
  clip: rect(0, 0, 0, 0);
}
.glitch.yoda > img:nth-child(2) {
  left: 2px;
  animation: yoda-glitch-anim-1 2s infinite linear alternate-reverse;
}
.glitch.yoda > img:nth-child(3) {
  left: -2px;
  animation: yoda-glitch-anim-2 3s infinite linear alternate-reverse;
}

@keyframes yoda-glitch-anim-1 {
  0%        { clip: rect(153px, 736px, 576px, 0); }
  6.66667%  { clip: rect(335px, 736px, 423px, 0); }
  13.33333% { clip: rect(529px, 736px, 429px, 0); }
  20%       { clip: rect(147px, 736px, 388px, 0); }
  26.66667% { clip: rect(341px, 736px, 165px, 0); }
  33.33333% { clip: rect(323px, 736px, 329px, 0); }
  40%       { clip: rect(276px, 736px, 318px, 0); }
  46.66667% { clip: rect(359px, 736px,  88px, 0); }
  53.33333% { clip: rect(200px, 736px,  94px, 0); }
  60%       { clip: rect(329px, 736px, 265px, 0); }
  66.66667% { clip: rect(553px, 736px, 247px, 0); }
  73.33333% { clip: rect(329px, 736px, 447px, 0); }
  80%       { clip: rect(500px, 736px,  24px, 0); }
  86.66667% { clip: rect( 88px, 736px, 388px, 0); }
  93.33333% { clip: rect(  6px, 736px, 370px, 0); }
  100%      { clip: rect( 47px, 736px,  12px, 0); }
} 
@keyframes yoda-glitch-anim-2 {
  0%        { clip: rect(376px, 736px, 323px, 0); }
  6.66667%  { clip: rect(318px, 736px, 535px, 0); }
  13.33333% { clip: rect(482px, 736px,   6px, 0); }
  20%       { clip: rect( 65px, 736px,  18px, 0); }
  26.66667% { clip: rect(465px, 736px, 353px, 0); }
  33.33333% { clip: rect(288px, 736px, 159px, 0); }
  40%       { clip: rect(412px, 736px, 564px, 0); }
  46.66667% { clip: rect(151px, 736px, 229px, 0); }
  53.33333% { clip: rect(235px, 736px,   6px, 0); }
  60%       { clip: rect(482px, 736px, 329px, 0); }
  66.66667% { clip: rect(341px, 736px,  47px, 0); }
  73.33333% { clip: rect(570px, 736px, 512px, 0); }
  80%       { clip: rect(529px, 736px, 576px, 0); }
  86.66667% { clip: rect(341px, 736px, 353px, 0); }
  93.33333% { clip: rect(435px, 736px, 535px, 0); }
  100%      { clip: rect(535px, 736px, 500px, 0); }
}

.glitch.message > img:nth-child(2) {
  left: 7px;
  animation: message-glitch-anim-1 2s infinite linear alternate-reverse;
}
.glitch.message > img:nth-child(3) {
  left: -7px;
  animation: message-glitch-anim-2 3s infinite linear alternate-reverse;
}

@keyframes message-glitch-anim-1 {
  0%        { clip: rect( 45px, 822px, 170px, 0); }
  6.66667%  { clip: rect( 99px, 822px, 125px, 0); }
  13.33333% { clip: rect(156px, 822px, 126px, 0); }
  20%       { clip: rect( 43px, 822px, 114px, 0); }
  26.66667% { clip: rect(100px, 822px,  48px, 0); }
  33.33333% { clip: rect( 95px, 822px,  97px, 0); }
  40%       { clip: rect( 81px, 822px,  93px, 0); }
  46.66667% { clip: rect(106px, 822px,  26px, 0); }
  53.33333% { clip: rect( 59px, 822px,  28px, 0); }
  60%       { clip: rect( 97px, 822px,  78px, 0); }
  66.66667% { clip: rect(163px, 822px,  73px, 0); }
  73.33333% { clip: rect( 97px, 822px, 131px, 0); }
  80%       { clip: rect(147px, 822px,   7px, 0); }
  86.66667% { clip: rect( 26px, 822px, 114px, 0); }
  93.33333% { clip: rect(  2px, 822px, 109px, 0); }
  100%      { clip: rect( 14px, 822px,   3px, 0); }
} 
@keyframes message-glitch-anim-2 {
  0%        { clip: rect(111px, 822px,  95px, 0); }
  6.66667%  { clip: rect( 93px, 822px, 157px, 0); }
  13.33333% { clip: rect(142px, 822px,   3px, 0); }
  20%       { clip: rect( 19px, 822px,   5px, 0); }
  26.66667% { clip: rect(137px, 822px, 104px, 0); }
  33.33333% { clip: rect( 85px, 822px,  47px, 0); }
  40%       { clip: rect(121px, 822px, 119px, 0); }
  46.66667% { clip: rect( 45px, 822px,  67px, 0); }
  53.33333% { clip: rect( 69px, 822px,   2px, 0); }
  60%       { clip: rect(142px, 822px,  97px, 0); }
  66.66667% { clip: rect(100px, 822px,  14px, 0); }
  73.33333% { clip: rect(168px, 822px, 151px, 0); }
  80%       { clip: rect(156px, 822px, 170px, 0); }
  86.66667% { clip: rect(100px, 822px, 104px, 0); }
  93.33333% { clip: rect(128px, 822px, 157px, 0); }
  100%      { clip: rect(157px, 822px, 147px, 0); }
}

/**

@include textGlitch("example-one", 17, white, black, red, blue, 450, 115);
@include imgGlitch("example-three", 15, 100, 100, 200, 75);
@include svgGlitch("example-four", 30, white, black, red, red, 100, 100, 200, 175);


@mixin textGlitch($name, $intensity, $textColor, $background, $highlightColor1, $highlightColor2, $width, $height) {
  
  color: $textColor;
  position: relative;
  $steps: $intensity;
  
  // Ensure the @keyframes are generated at the root level
  @at-root {
    // We need two different ones
    @for $i from 1 through 2 {
      @keyframes #{$name}-anim-#{$i} {
        @for $i from 0 through $steps {
          #{percentage($i*(1/$steps))} {
            clip: rect(
              random($height)+px,
              $width+px,
              random($height)+px,
              0
            );
          }
        }
      }
    }
  }
  &:before,
  &:after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    background: $background;
    clip: rect(0, 0, 0, 0); 
  }
  &:after {
    left: 2px;
    text-shadow: -1px 0 $highlightColor1;
    animation: #{$name}-anim-1 2s infinite linear alternate-reverse;
  }
  &:before {
    left: -2px;
    text-shadow: 2px 0 $highlightColor2; 
    animation: #{$name}-anim-2 3s infinite linear alternate-reverse;
  }
  
}

@mixin imgGlitch($name, $intensity, $width, $height, $top, $left) {
  
  $steps: $intensity;
  
  // Ensure the @keyframes are generated at the root level
  @at-root {
    // We need two different ones
    @for $i from 1 through 2 {
      @keyframes #{$name}-anim-#{$i} {
        @for $i from 0 through $steps {
          #{percentage($i*(1/$steps))} {
            clip: rect(
              random($height)+px,
              $width+px,
              random($height)+px,
              0
            );
          }
        }
      }
    }
  }
  
  > img {
    position: absolute;
    top: $top+px;
    left: $left+px;
  }
  > img:nth-child(2),
  > img:nth-child(3){
    clip: rect(0, 0, 0, 0); 
  }
  > img:nth-child(2) {
    left: ($left + 2) + px;
    animation: #{$name}-anim-1 2s infinite linear alternate-reverse;
  }
  > img:nth-child(3) {
    left: ($left - 2) + px;
    animation: #{$name}-anim-2 3s infinite linear alternate-reverse;
  }
}

@mixin svgGlitch($name, $intensity, $fillColor, $background, $fillHighlight1, $fillHighlight2, $width, $height, $top, $left) {
  
  $steps: $intensity;
  
  // Ensure the @keyframes are generated at the root level
  @at-root {
    // We need two different ones
    @for $i from 1 through 2 {
      @keyframes #{$name}-anim-#{$i} {
        @for $i from 0 through $steps {
          #{percentage($i*(1/$steps))} {
            clip: rect(
              (random($height)-20)+px,
              $width+px,
              (random($height)+20)+px,
              0
            );
          }
        }
      }
    }
  }
  
  svg {
    position: absolute;
    top: $top+px;
    left: $left+px;
    fill: $fillColor;
    background: $background;
    width: $width+px;
    height: $height+px;
  }
  svg:nth-child(2),
  svg:nth-child(3) {
    clip: rect(0, 0, 0, 0); 
  }
  svg:nth-child(2) {
    fill: $fillHighlight1;
    left: ($left - 2) + px;
    animation: #{$name}-anim-1 2s infinite linear alternate-reverse;
  }
  svg:nth-child(3) {
    fill: $fillHighlight2;
    left: ($left + 2) + px;
    animation: #{$name}-anim-2 3s infinite linear alternate-reverse;
  }
}

*/
