:root {
  --di: 6.5rem;
  --duration: 0ms;
  --black: #1e1e1e;
  --border-width: max(1rem, min(2vh, 2vw));
  --gray: #ddd;
  --graydark: #bbb;
  --offwhite: #eee;
  --white: #fff;
}

* {
  -ms-touch-action: manipulation;
  touch-action: manipulation;
}

html,
body,
main {
  height: 100%;
  overflow: hidden;
  width: 100%;
}

body {
  --fill-1: hsl(14, 89%, 53%);
  --fill-2: hsl(6, 100%, 69%);
  --fill-3: hsl(266, 100%, 67%);
  --fill-4: hsl(197, 99%, 55%);
  --fill-5: hsl(157, 91%, 43%);
  --fill-progress-1: hsla(14, 89%, 53%, var(--progress-1, 0));
  --fill-progress-2: hsla(6, 100%, 69%, var(--progress-2, 0));
  --fill-progress-3: hsla(266, 100%, 67%, var(--progress-3, 0));
  --fill-progress-4: hsla(197, 99%, 55%, var(--progress-4, 0));
  --fill-progress-5: hsla(157, 91%, 43%, var(--progress-5, 0));
  background: var(--background, white);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
  margin: 0;
}

main {
  align-items: center;
  box-shadow: inset var(--color, transparent) 0 0 0 var(--border-width),
    inset var(--color-inner, transparent) 0 0 0 calc(var(--border-width) * 2);
  display: flex;
  justify-content: center;
}

span.border-ne::before,
span.border-ne::after,
span.border-sw::before,
span.border-sw::after {
  background: var(--offwhite)
    linear-gradient(
      var(--direction),
      var(--fill-progress-1) 0%,
      var(--fill-progress-1) 20%,
      var(--fill-progress-2) 20%,
      var(--fill-progress-2) 40%,
      var(--fill-progress-3) 40%,
      var(--fill-progress-3) 60%,
      var(--fill-progress-4) 60%,
      var(--fill-progress-4) 80%,
      var(--fill-progress-5) 80%,
      var(--fill-progress-5) 100%
    );
  content: "";
  display: block;
  position: fixed;
  transition: background 150ms ease-in-out;
  z-index: -1;
}

span.border-ne::before,
span.border-sw::before {
  --direction: 90deg;
  height: var(--border-width);
  left: 0;
  width: 100%;
}
span.border-ne::after,
span.border-sw::after {
  --direction: 0deg;
  height: 100%;
  top: 0;
  width: var(--border-width);
}
span.border-ne::before {
  top: 0;
}
span.border-sw::before {
  bottom: 0;
  transform: scaleX(-1);
}
span.border-ne::after {
  right: 0;
  transform: scaleY(-1);
}
span.border-sw::after {
  left: 0;
}

main::before {
  background: var(--color);
  bottom: 0;
  content: "";
  left: 0;
  opacity: var(--confidence, 0);
  pointer-events: none;
  position: absolute;
  right: 0;
  top: 0;
  z-index: 1;
}

figure {
  height: calc(var(--di) * 3);
  margin: 0 auto;
  opacity: var(--opacity, 1);
  position: relative;
  width: calc(var(--di) * 2);
}

.svg-white figure svg {
  fill: #fff;
}

.svg-black figure svg {
  fill: var(--black);
}

figure svg {
  height: calc(3 * var(--di) * 1.07317073171);
  left: 50%;
  opacity: 0;
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: auto;
}

figure svg,
figure button {
  transition: transform var(--duration) ease-in-out,
    background var(--duration) ease-in-out;
}

.svg figure {
  z-index: 2;
}
.svg figure svg {
  opacity: 1;
}

.svg figure button {
  opacity: 0;
}

button {
  appearance: none;
  background: var(--fill);
  border: none;
  cursor: pointer;
  display: flex;
  height: var(--di);
  opacity: 1;
  padding: 0;
  position: absolute;
  transform: translate(calc(var(--x) * 100%), calc(var(--y) * 100%));
  width: var(--di);
}

button:focus-visible {
  outline-offset: 4px;
  outline-color: var(--fill);
  z-index: 1;
}

button:hover {
  background: var(--fill);
}

button.active {
  background: var(--black);
  color: white;
}

span.logo-piece {
  --diameter: 0.6em;
  background: var(--fill);
  display: block;
  height: var(--diameter);
  width: var(--diameter);
}
span.logo-piece[data-position="1"],
button[data-position="1"] {
  --x: 0;
  --y: 0;
  --fill: var(--fill-1);
  border-radius: var(--di) 0 0 var(--di);
}

span.logo-piece[data-position="2"],
button[data-position="2"] {
  --x: 1;
  --y: 0;
  --fill: var(--fill-2);
  border-radius: 0 var(--di) var(--di) 0;
}

span.logo-piece[data-position="3"],
button[data-position="3"] {
  --x: 0;
  --y: 1;
  --fill: var(--fill-3);
  border-radius: var(--di) 0 0 var(--di);
}

span.logo-piece[data-position="4"],
button[data-position="4"] {
  --x: 1;
  --y: 1;
  --fill: var(--fill-4);
  border-radius: var(--di);
}

span.logo-piece[data-position="5"],
button[data-position="5"] {
  --x: 0;
  --y: 2;
  --fill: var(--fill-5);
  border-radius: var(--di) 0 var(--di) var(--di);
}

#reveal {
  --timeline-pieces: 500ms;
  --timeline-pause: 200ms;
  --timeline-latest-pause: 200ms;
  --duration: 350ms;
  --duration-unknown: 500ms;
  --delay-step: 150ms;
  --delay: 0ms;
  --known-index: 0;
  --latest-index: 0;
  --unknown-index: 0;

  align-items: center;
  background: var(--white);
  bottom: 0;
  color: var(--black);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  font-size: 6rem;
  gap: 1rem;
  justify-content: center;
  left: 0;
  margin: 0;
  opacity: 0;
  pointer-events: none;
  position: fixed;
  right: 0;
  text-align: center;
  text-decoration: none;
  top: 0;
  transition: opacity 150ms ease-in-out;
  z-index: 2;
}

@keyframes h1-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes h1-pulse {
  from {
    opacity: 1;
  }
  to {
    opacity: 0.8;
  }
}

#reveal h1 {
  --delay: calc(
    var(--timeline-pieces) + var(--timeline-pause) +
      var(--timeline-latest-pause) +
      (var(--latest-total) + var(--known-total) + var(--unknown-total)) *
      var(--delay-step) + var(--duration-unknown)
  );
  animation: h1-in 500ms ease-in-out var(--delay) forwards,
    h1-pulse 250ms ease-in-out calc(var(--delay) + 500ms) alternate infinite;
  color: var(--graydark);
  font-size: 0.2em;
  line-height: 1;
  margin: 0;
  opacity: 0;
  position: absolute;
  left: 50%;
  bottom: 2rem;
  text-transform: uppercase;
  transform: translateX(-50%);
}

#reveal.active {
  opacity: 1;
  pointer-events: all;
}

#reveal ul {
  display: flex;
  flex-wrap: wrap;
  flex-direction: column;
  margin: 0;
  padding: 0;
}

@keyframes item-in {
  from {
    opacity: 0;
    transform: scale(var(--initial-scale));
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}
@keyframes pulse {
  from {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0.9;
    transform: scale(1.1);
  }
}

#reveal ul li {
  align-items: center;
  display: flex;
  gap: 0.1em;
  justify-content: space-between;
  margin: 0.05em 0;
}

#reveal ul li.latest {
  --timeline-delay: calc(var(--timeline-pieces) + var(--timeline-pause));
}
#reveal ul li.latest .logo-piece {
  animation: item-in var(--duration) ease-in-out var(--delay) forwards,
    pulse 250ms ease-in-out var(--timeline-delay) infinite alternate;
}
#reveal ul li.latest .emoji > * {
  --initial-scale: 1.8;
  --delay: calc(
    var(--timeline-delay) + var(--latest-index) * var(--delay-step)
  );
}
#reveal ul li.known {
  --timeline-delay: calc(
    var(--timeline-pieces) + var(--timeline-pause) +
      var(--timeline-latest-pause) + (var(--latest-total) * var(--delay-step))
  );
}
#reveal ul li.known .emoji > * {
  --delay: calc(var(--timeline-delay) + var(--known-index) * var(--delay-step));
}
#reveal ul li.unknown {
  --duration: var(--duration-unknown);
  --timeline-delay: calc(
    var(--timeline-pieces) + var(--timeline-pause) +
      var(--timeline-latest-pause) + (var(--latest-total) + var(--known-total)) *
      var(--delay-step)
  );
  gap: 0.2em;
}
#reveal ul li.unknown .emoji > * {
  --delay: calc(
    var(--timeline-delay) + var(--unknown-index) * var(--delay-step)
  );
}

#reveal ul li .logo-piece {
  --initial-scale: 1.25;
  animation: item-in var(--duration) ease-in-out var(--delay) forwards;
  opacity: 0;
}
#reveal ul li:nth-child(1) .logo-piece {
  --delay: calc(var(--timeline-pieces) / 5 * 1);
}
#reveal ul li:nth-child(2) .logo-piece {
  --delay: calc(var(--timeline-pieces) / 5 * 2);
}
#reveal ul li:nth-child(3) .logo-piece {
  --delay: calc(var(--timeline-pieces) / 5 * 3);
}
#reveal ul li:nth-child(4) .logo-piece {
  --delay: calc(var(--timeline-pieces) / 5 * 4);
}
#reveal ul li:nth-child(5) .logo-piece {
  --delay: calc(var(--timeline-pieces) / 5 * 5);
}

#reveal ul li .emoji {
  --initial-scale: 1.5;
  color: var(--gray);
  border-radius: 30rem;
  display: flex;
  flex: 1;
}

#reveal ul li .emoji > span {
  font-size: 0.3em;
  font-weight: bold;
}

#reveal ul li .emoji > img {
  width: 0.7em;
}
#reveal ul li .emoji > * {
  animation: item-in var(--duration) ease-in-out var(--delay) forwards;
  height: 0.7em;
  line-height: 0.7em;
  opacity: 0;
  transform: scale(var(--initial-scale));
}
#reveal ul li .emoji > *:nth-child(2),
#reveal ul li .emoji > *:nth-child(3) {
  margin-left: -0.05em;
}

#reveal ul li.empty .emoji > * {
  --initial-scale: 1;
}
#reveal ul li.latest .emoji > *:nth-child(1) {
  --delay-item: calc(0.2 * var(--timeline-latest));
}
#reveal ul li.latest .emoji > *:nth-child(2) {
  --delay-item: calc(0.4 * var(--timeline-latest));
}
#reveal ul li.latest .emoji > *:nth-child(3) {
  --delay-item: calc(0.6 * var(--timeline-latest));
}

video,
#video {
  height: 100%;
  left: 0;
  object-fit: cover;
  object-position: center;
  opacity: var(--opacity, 1);
  position: absolute;
  top: 0;
  width: 100%;
  z-index: -1;
}

video.remove,
#video.remove {
  opacity: 0;
}

p {
  bottom: calc(var(--border-width) * 3);
  color: var(--black);
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  left: 0;
  margin: 0;
  position: fixed;
  width: 100%;
}

p span {
  border-bottom: 0.3rem solid var(--gray);
  display: flex;
  font-size: 2rem;
  font-weight: bold;
  justify-content: center;
  width: min(3rem, 6vw);
}

p span.active {
  border-bottom-color: var(--black);
}

@media screen and (min-width: 1024px) {
  p span {
    border-bottom: 0.4rem solid var(--gray);
    font-size: 3rem;
  }
  #reveal {
    font-size: 6rem;
    gap: 2rem;
  }
}

canvas {
  bottom: 0;
  display: block;
  left: 0;
  height: 100%;
  position: fixed;
  right: 0;
  top: 0;
  user-select: none;
  width: 100%;
  z-index: 9999;
}
