/* A copy of the extension's src/features/themes/twitch-effects.css, for the home page, which
   wears a theme the way Twitch does. One thing is changed: the pictures the extension writes
   into an address are files here, because this site's Content-Security-Policy allows no
   data: addresses. styles.css says where the home page differs from Twitch's. What follows
   is the extension's own file. */

/* Motion for the seasons and the specials: snow, petals, waves, leaves, lights and bats. The
   Theme animations setting turns it off, and so does asking your computer for less motion.

   It's made to cost next to nothing. Nothing here is an element or a script: each layer is a
   pseudo-element holding one picture that repeats, and only its transform or opacity changes, so
   the browser moves a finished picture around without drawing or laying anything out again.
   steps() makes that happen 25 times a second however fast the screen is, and at the same
   moments for every layer, so the page is put together again 25 times a second and not once for
   each layer. That's what the times and steps are picked for: a layer that drifts takes steps of
   its time / 16 / 0.04s, and one that slides or turns its time / 0.04s. A new layer should keep to
   all of that.

   The layers sit behind Twitch's page, so they show where a page is empty, like Browse, and
   through the sidebar, which goes see-through for it. They never cross the video or chat. Lights,
   bats and gulls are in the top bar, between its background and what's on it.

   The pictures are the SVG files in assets/effects/. */

/* Down one tile, swaying twice on the way. --skek-fx-y is the tile's height, or minus it to go
   up, --skek-fx-x how far it drifts sideways, which is nothing or the tile's width, and
   --skek-fx-sway how far it sways. */
@keyframes skek-fx-drift {
  0% { transform: translate3d(0px, 0px, 0); }
  6.25% { transform: translate3d(calc(var(--skek-fx-sway) * 0.707 + var(--skek-fx-x) * 0.0625), calc(var(--skek-fx-y) * 0.0625), 0); }
  12.5% { transform: translate3d(calc(var(--skek-fx-sway) + var(--skek-fx-x) * 0.125), calc(var(--skek-fx-y) * 0.125), 0); }
  18.75% { transform: translate3d(calc(var(--skek-fx-sway) * 0.707 + var(--skek-fx-x) * 0.1875), calc(var(--skek-fx-y) * 0.1875), 0); }
  25% { transform: translate3d(calc(var(--skek-fx-x) * 0.25), calc(var(--skek-fx-y) * 0.25), 0); }
  31.25% { transform: translate3d(calc(var(--skek-fx-sway) * -0.707 + var(--skek-fx-x) * 0.3125), calc(var(--skek-fx-y) * 0.3125), 0); }
  37.5% { transform: translate3d(calc(var(--skek-fx-sway) * -1 + var(--skek-fx-x) * 0.375), calc(var(--skek-fx-y) * 0.375), 0); }
  43.75% { transform: translate3d(calc(var(--skek-fx-sway) * -0.707 + var(--skek-fx-x) * 0.4375), calc(var(--skek-fx-y) * 0.4375), 0); }
  50% { transform: translate3d(calc(var(--skek-fx-x) * 0.5), calc(var(--skek-fx-y) * 0.5), 0); }
  56.25% { transform: translate3d(calc(var(--skek-fx-sway) * 0.707 + var(--skek-fx-x) * 0.5625), calc(var(--skek-fx-y) * 0.5625), 0); }
  62.5% { transform: translate3d(calc(var(--skek-fx-sway) + var(--skek-fx-x) * 0.625), calc(var(--skek-fx-y) * 0.625), 0); }
  68.75% { transform: translate3d(calc(var(--skek-fx-sway) * 0.707 + var(--skek-fx-x) * 0.6875), calc(var(--skek-fx-y) * 0.6875), 0); }
  75% { transform: translate3d(calc(var(--skek-fx-x) * 0.75), calc(var(--skek-fx-y) * 0.75), 0); }
  81.25% { transform: translate3d(calc(var(--skek-fx-sway) * -0.707 + var(--skek-fx-x) * 0.8125), calc(var(--skek-fx-y) * 0.8125), 0); }
  87.5% { transform: translate3d(calc(var(--skek-fx-sway) * -1 + var(--skek-fx-x) * 0.875), calc(var(--skek-fx-y) * 0.875), 0); }
  93.75% { transform: translate3d(calc(var(--skek-fx-sway) * -0.707 + var(--skek-fx-x) * 0.9375), calc(var(--skek-fx-y) * 0.9375), 0); }
  100% { transform: translate3d(var(--skek-fx-x), var(--skek-fx-y), 0); }
}
/* Sideways by one tile. */
@keyframes skek-fx-slide {
  to { transform: translate3d(var(--skek-fx-x), 0, 0); }
}
/* One ray's turn, so the turn after it looks the same. */
@keyframes skek-fx-turn {
  to { transform: rotate(20deg); }
}
@keyframes skek-fx-twinkle {
  from { opacity: 0.3; }
  to { opacity: 1; }
}
/* Across the top bar in the first two fifths of the time, then out of sight for the rest. */
@keyframes skek-fx-cross {
  0% { transform: translate3d(100vw, 0, 0); }
  10% { transform: translate3d(75vw, 5px, 0); }
  20% { transform: translate3d(50vw, -4px, 0); }
  30% { transform: translate3d(25vw, 4px, 0); }
  40%, 100% { transform: translate3d(-320px, 0, 0); }
}

@media (prefers-reduced-motion: no-preference) {
  /* The sidebar lets the layers show through. Its color is the theme's raised one, which at half
     strength over the page comes out close to the panels beside it. !important because Twitch's
     own rule for it has that. */
  html[data-skek-on~='themeAnimations']:is([data-skek-theme='winter'], [data-skek-theme='spring'], [data-skek-theme='summer'], [data-skek-theme='autumn'], [data-skek-theme='christmas'], [data-skek-theme='halloween']) .side-nav {
    background-color: rgb(from var(--skek-t-raised) r g b / 0.5) !important;
  }

  /* What every layer behind the page shares. */
  html[data-skek-on~='themeAnimations']:is([data-skek-theme='winter'], [data-skek-theme='spring'], [data-skek-theme='summer'], [data-skek-theme='autumn'], [data-skek-theme='christmas'], [data-skek-theme='halloween']) body::before,
  html[data-skek-on~='themeAnimations']:is([data-skek-theme='winter'], [data-skek-theme='spring'], [data-skek-theme='summer'], [data-skek-theme='autumn'], [data-skek-theme='christmas'], [data-skek-theme='halloween']) body::after,
  html[data-skek-on~='themeAnimations']:is([data-skek-theme='winter'], [data-skek-theme='summer'])::before {
    content: '';
    position: fixed;
    z-index: -1;
    pointer-events: none;
    will-change: transform;
  }

  /* What falls or rises: a tile taller than the window by one of itself, moved by that much. */
  html[data-skek-on~='themeAnimations']:is([data-skek-theme='winter'], [data-skek-theme='spring'], [data-skek-theme='autumn'], [data-skek-theme='christmas'], [data-skek-theme='halloween']) body::before,
  html[data-skek-on~='themeAnimations']:is([data-skek-theme='winter'], [data-skek-theme='spring'], [data-skek-theme='autumn'], [data-skek-theme='christmas'], [data-skek-theme='halloween']) body::after,
  html[data-skek-on~='themeAnimations'][data-skek-theme='winter']::before {
    inset: calc(-1 * max(var(--skek-fx-y), 0px)) calc(-1 * (var(--skek-fx-sway) + max(-1 * var(--skek-fx-x), 0px))) calc(-1 * max(-1 * var(--skek-fx-y), 0px)) calc(-1 * (var(--skek-fx-sway) + max(var(--skek-fx-x), 0px)));
    --skek-fx-x: 0px;
    animation: skek-fx-drift var(--skek-fx-time) linear infinite;
  }

  /* Winter and Christmas: snow, nearest first. Winter has a third layer far away. */
  html[data-skek-on~='themeAnimations']:is([data-skek-theme='winter'], [data-skek-theme='christmas']) body::before {
    --skek-fx-y: 360px;
    --skek-fx-sway: 16px;
    --skek-fx-time: 16s;
    background-image:
      radial-gradient(circle at 34px 62px, rgb(255 255 255 / 0.9) 0 2.4px, transparent 5.5px),
      radial-gradient(circle at 208px 28px, rgb(255 255 255 / 0.8) 0 2px, transparent 4.6px),
      radial-gradient(circle at 300px 190px, rgb(255 255 255 / 0.9) 0 3px, transparent 6.5px),
      radial-gradient(circle at 120px 250px, rgb(255 255 255 / 0.75) 0 2.2px, transparent 5px),
      radial-gradient(circle at 250px 330px, rgb(255 255 255 / 0.85) 0 1.8px, transparent 4.2px);
    background-size: 360px 360px;
    animation-timing-function: steps(25);
  }
  html[data-skek-on~='themeAnimations']:is([data-skek-theme='winter'], [data-skek-theme='christmas']) body::after {
    --skek-fx-y: 260px;
    --skek-fx-sway: 10px;
    --skek-fx-time: 22.4s;
    background-image:
      radial-gradient(circle at 20px 30px, rgb(255 255 255 / 0.7) 0 1.3px, transparent 3px),
      radial-gradient(circle at 150px 70px, rgb(255 255 255 / 0.75) 0 1.6px, transparent 3.4px),
      radial-gradient(circle at 230px 150px, rgb(255 255 255 / 0.65) 0 1.2px, transparent 2.8px),
      radial-gradient(circle at 80px 180px, rgb(255 255 255 / 0.7) 0 1.5px, transparent 3.2px),
      radial-gradient(circle at 190px 235px, rgb(255 255 255 / 0.6) 0 1.2px, transparent 2.8px),
      radial-gradient(circle at 45px 120px, rgb(255 255 255 / 0.6) 0 1px, transparent 2.5px);
    background-size: 260px 260px;
    animation-timing-function: steps(35);
  }
  html[data-skek-on~='themeAnimations'][data-skek-theme='winter']::before {
    --skek-fx-y: 190px;
    --skek-fx-sway: 6px;
    --skek-fx-time: 32s;
    background-image:
      radial-gradient(circle at 15px 20px, rgb(255 255 255 / 0.5) 0 0.8px, transparent 1.6px),
      radial-gradient(circle at 95px 50px, rgb(255 255 255 / 0.55) 0 1px, transparent 1.8px),
      radial-gradient(circle at 150px 110px, rgb(255 255 255 / 0.45) 0 0.8px, transparent 1.6px),
      radial-gradient(circle at 60px 140px, rgb(255 255 255 / 0.5) 0 0.9px, transparent 1.7px),
      radial-gradient(circle at 120px 165px, rgb(255 255 255 / 0.45) 0 0.7px, transparent 1.5px),
      radial-gradient(circle at 30px 90px, rgb(255 255 255 / 0.4) 0 0.7px, transparent 1.5px),
      radial-gradient(circle at 170px 25px, rgb(255 255 255 / 0.45) 0 0.8px, transparent 1.6px);
    background-size: 190px 190px;
    animation-timing-function: steps(50);
  }

  /* Spring: petals blowing down and to the left. */
  html[data-skek-on~='themeAnimations'][data-skek-theme='spring'] body::before {
    --skek-fx-y: 480px;
    --skek-fx-x: -360px;
    --skek-fx-sway: 22px;
    --skek-fx-time: 16s;
    background-image: url('assets/effects/spring-near.svg');
    animation-timing-function: steps(25);
  }
  html[data-skek-on~='themeAnimations'][data-skek-theme='spring'] body::after {
    --skek-fx-y: 340px;
    --skek-fx-x: -260px;
    --skek-fx-sway: 14px;
    --skek-fx-time: 25.6s;
    background-image: url('assets/effects/spring-far.svg');
    animation-timing-function: steps(40);
  }

  /* Autumn: leaves, swaying wide as they fall. */
  html[data-skek-on~='themeAnimations'][data-skek-theme='autumn'] body::before {
    --skek-fx-y: 480px;
    --skek-fx-sway: 34px;
    --skek-fx-time: 16s;
    background-image: url('assets/effects/autumn-near.svg');
    animation-timing-function: steps(25);
  }
  html[data-skek-on~='themeAnimations'][data-skek-theme='autumn'] body::after {
    --skek-fx-y: 340px;
    --skek-fx-sway: 22px;
    --skek-fx-time: 25.6s;
    background-image: url('assets/effects/autumn-far.svg');
    animation-timing-function: steps(40);
  }

  /* Halloween: lights drifting up, in the pumpkin's orange and the slime's green. */
  html[data-skek-on~='themeAnimations'][data-skek-theme='halloween'] body::before {
    --skek-fx-y: -400px;
    --skek-fx-sway: 20px;
    --skek-fx-time: 25.6s;
    background-image:
      radial-gradient(circle at 60px 80px, rgb(255 140 40 / 0.95) 0 1.6px, rgb(255 140 40 / 0.28) 4.1px, transparent 10px),
      radial-gradient(circle at 250px 40px, rgb(170 235 80 / 0.95) 0 1.3px, rgb(170 235 80 / 0.28) 3.8px, transparent 9px),
      radial-gradient(circle at 330px 260px, rgb(255 140 40 / 0.95) 0 1.7px, rgb(255 140 40 / 0.28) 4.2px, transparent 11px),
      radial-gradient(circle at 140px 320px, rgb(170 235 80 / 0.95) 0 1.4px, rgb(170 235 80 / 0.28) 3.9px, transparent 9px),
      radial-gradient(circle at 200px 190px, rgb(255 140 40 / 0.95) 0 1.2px, rgb(255 140 40 / 0.28) 3.7px, transparent 8px);
    background-size: 400px 400px;
    animation-timing-function: steps(40);
  }
  html[data-skek-on~='themeAnimations'][data-skek-theme='halloween'] body::after {
    --skek-fx-y: -280px;
    --skek-fx-sway: 12px;
    --skek-fx-time: 38.4s;
    background-image:
      radial-gradient(circle at 30px 40px, rgb(170 235 80 / 0.95) 0 0.9px, rgb(170 235 80 / 0.28) 3.4px, transparent 6px),
      radial-gradient(circle at 150px 100px, rgb(255 140 40 / 0.95) 0 1px, rgb(255 140 40 / 0.28) 3.5px, transparent 6px),
      radial-gradient(circle at 220px 200px, rgb(170 235 80 / 0.95) 0 0.8px, rgb(170 235 80 / 0.28) 3.3px, transparent 5px),
      radial-gradient(circle at 90px 230px, rgb(255 140 40 / 0.95) 0 0.9px, rgb(255 140 40 / 0.28) 3.4px, transparent 6px),
      radial-gradient(circle at 260px 20px, rgb(255 140 40 / 0.95) 0 0.8px, rgb(255 140 40 / 0.28) 3.3px, transparent 5px);
    background-size: 280px 280px;
    animation-timing-function: steps(60);
  }

  /* Summer: the sun in the top left corner, where the sidebar shows it on every page, with its
     rays turning, and two rows of waves along the bottom. */
  html[data-skek-on~='themeAnimations'][data-skek-theme='summer'] body::before,
  html[data-skek-on~='themeAnimations'][data-skek-theme='summer'] body::after {
    left: 0;
    bottom: 0;
    width: calc(100vw + 240px);
    background-repeat: repeat-x;
    animation: skek-fx-slide var(--skek-fx-time) linear infinite;
  }
  html[data-skek-on~='themeAnimations'][data-skek-theme='summer'] body::before {
    --skek-fx-x: -240px;
    --skek-fx-time: 24s;
    height: 60px;
    background-image: url('assets/effects/summer-wave-back.svg');
    animation-timing-function: steps(600);
  }
  html[data-skek-on~='themeAnimations'][data-skek-theme='summer'] body::after {
    --skek-fx-x: -160px;
    --skek-fx-time: 14s;
    height: 44px;
    background-image: url('assets/effects/summer-wave-front.svg');
    animation-timing-function: steps(350);
  }
  html[data-skek-on~='themeAnimations'][data-skek-theme='summer']::before {
    top: -700px;
    left: -700px;
    width: 1400px;
    height: 1400px;
    background: url('assets/effects/summer-rays.svg') center / 100% 100% no-repeat;
    animation: skek-fx-turn 48s steps(1200) infinite;
  }

  /* Christmas: a string of lights along the top bar's line, every other one lit in turn. */
  html[data-skek-on~='themeAnimations'][data-skek-theme='christmas'] .top-nav__menu::before,
  html[data-skek-on~='themeAnimations'][data-skek-theme='christmas'] .top-nav__menu::after {
    content: '';
    position: fixed;
    top: calc(5rem - 8px);
    left: 0;
    right: 0;
    height: 16px;
    pointer-events: none;
    background-size: 132px 16px;
    animation: skek-fx-twinkle 1.6s steps(8) infinite alternate;
  }
  html[data-skek-on~='themeAnimations'][data-skek-theme='christmas'] .top-nav__menu::before {
    background-image:
      radial-gradient(circle at 16px 8px, #ff5868 0 3px, rgb(255 88 104 / 0.38) 4.4px, transparent 8px),
      radial-gradient(circle at 82px 8px, #4fd97a 0 3px, rgb(79 217 122 / 0.38) 4.4px, transparent 8px);
  }
  html[data-skek-on~='themeAnimations'][data-skek-theme='christmas'] .top-nav__menu::after {
    background-image:
      radial-gradient(circle at 49px 8px, #ffd45c 0 3px, rgb(255 212 92 / 0.38) 4.4px, transparent 8px),
      radial-gradient(circle at 115px 8px, #6db5ff 0 3px, rgb(109 181 255 / 0.38) 4.4px, transparent 8px);
    animation-delay: -1.6s;
  }

  /* Halloween and Summer: bats, or gulls, crossing the top bar now and then, behind what's on
     it. isolation gives the bar a layer order of its own, so they can go under its buttons and
     over its background. */
  html[data-skek-on~='themeAnimations']:is([data-skek-theme='halloween'], [data-skek-theme='summer']) .top-nav__menu {
    isolation: isolate;
  }
  html[data-skek-on~='themeAnimations']:is([data-skek-theme='halloween'], [data-skek-theme='summer']) .top-nav__menu::before {
    content: '';
    position: fixed;
    z-index: -1;
    top: 0;
    left: 0;
    width: 300px;
    height: 5rem;
    pointer-events: none;
    background: center / 300px 50px no-repeat;
    will-change: transform;
  }
  html[data-skek-on~='themeAnimations'][data-skek-theme='halloween'] .top-nav__menu::before {
    background-image: url('assets/effects/halloween-bats.svg');
    animation: skek-fx-cross 50s steps(125) infinite;
  }
  html[data-skek-on~='themeAnimations'][data-skek-theme='summer'] .top-nav__menu::before {
    background-image: url('assets/effects/summer-gulls.svg');
    animation: skek-fx-cross 70s steps(175) infinite;
  }

  /* Nothing is there to move where none of it could be seen: in fullscreen, in theatre mode and
     in the stream view's modes that fill the window. */
  html[data-skek-on~='themeAnimations']:has(:fullscreen, .persistent-player--theatre, .skek-view--full-window) :is(body, .top-nav__menu)::before,
  html[data-skek-on~='themeAnimations']:has(:fullscreen, .persistent-player--theatre, .skek-view--full-window) :is(body, .top-nav__menu)::after,
  html[data-skek-on~='themeAnimations']:has(:fullscreen, .persistent-player--theatre, .skek-view--full-window)::before {
    content: none;
  }
}
