:root {
  --background-color: #130028;
  --grid-item: #300063;
  --grid-item-active: #7b2ad0;
  --gold: #e89437;
  --danger: #e31b54;
  --offset: 2px;
  --pacman: #d155ff;
  --pacman-alt: #e8aaff;
  --pacman-danger: #ba00ff;
}

@keyframes backgrounds {
  0% {
    opacity: 0.1;
    transform: scale(1, 1) rotate(0);
    top: 10%;
    left: -40%;
  }

  25% {
    opacity: 0.05;
    transform: scale(0.9, 0.9) rotate(-20deg);
    left: -10%;
  }

  50% {
    opacity: 0.08;
    transform: scale(1.5, 1.5) rotate(20deg);
    left: 20%;
  }

  75% {
    opacity: 0.08;
    transform: scale(0.9, 0.9) rotate(10deg);
    left: 50%;
    top: -10%;
  }

  100% {
    opacity: 0.06;
    transform: scale(1.2, 1) rotate(0deg);
    left: 80%;
  }
}

@keyframes pacman {
  0% {
    fill: var(--pacman);
  }

  100% {
    fill: var(--pacman-danger);
  }
}

html {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: var(--background-color);
}

body {
  width: 100%;
  min-height: 100%;
  display: flex;
  align-items: center;
  align-content: center;
  margin: 0;
  padding: 0;
  background-size: contain;
  overflow: hidden;
  box-shadow: inset 0 0 200px rgba(0, 0, 0, 0.8);
}

@media only screen and (max-width: 600px) {
  html {
    font-size: 10px;
  }
}

*,
*:before,
*:after {
  box-sizing: border-box;
  background-position: center center;
  background-repeat: no-repeat;
  touch-action: manipulation;
}

#backgrounds {
  position: absolute;
  z-index: 0;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  /* opacity: 0.5; */

  >* {
    background-blend-mode: screen;
    background-size: contain;
    position: absolute;
    z-index: -1;
    height: 100%;
  }

  >.animated {
    opacity: 0.05;
    width: 50%;
    animation-name: backgrounds;
    animation-duration: 10s;
    animation-iteration-count: infinite;
    animation-direction: alternate;
  }

  >.animated-2 {
    opacity: 0;
    width: 30%;
  }

  &>#ghost {
    background-image: url('./images/ghost.svg');
    animation-direction: alternate-reverse;
    animation-duration: 14s;
    left: 80%;
  }

  &>#pacman {
    right: 70%;
    border: solid 1px red;
  }
}

#container {
  margin-left: auto;
  margin-right: auto;
  position: absolute;
  z-index: 1;
  left: 50%;
  top: 50%;
}

#container .item {
  position: absolute;
}

#container .grid-item {
  z-index: -1;
  display: flex;
  align-items: center;
  align-content: center;
  justify-content: center;
  border: solid 2px transparent;
  overflow: hidden;
  transition-property: all;
  transition-duration: 500ms;
  transition-delay: 200ms;
}

#container .grid-item:after {
  content: '';
  display: block;
  position: absolute;
  border-radius: 100%;
  left: var(--offset);
  top: var(--offset);
  right: var(--offset);
  bottom: var(--offset);
  z-index: -1;
  transition-delay: 400ms;
}

#container .grid-item:not(.wall):after {
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  background-color: var(--grid-item);
}

#container .grid-item.occupied {
  opacity: 0.2;

  >:after {
    background-color: #888;
  }
}

#container .grid-item:before {
  content: attr(data-currency);
  color: white;
  font-weight: bold;
  display: block;
  opacity: 0;
  transition-duration: 200ms;
  transition-delay: 200ms;
  position: relative;
  font-size: 2rem;
  font-family: monospace;
}

#container .grid-item.food[data-currency="£"]:after {
  background-color: var(--gold);
}

#container .grid-item.food[data-currency="¥"]:after {
  background-color: var(--danger);
}

#container .grid-item.food:before {
  opacity: 1;
}

#container .grid-item.food:after {
  background-color: var(--grid-item-active);
}

#container .grid-item.food.consumed {
  background-color: transparent;
  transition-property: all;
  transition-duration: 2000ms;
  transition-delay: 0;
  border: none;
}

#container .object {
  z-index: 10;
  background-size: 100%;
}

#container .pacman {
  transition-property: left top;
  transition-duration: 500ms;
  transform-origin: center center;

  svg {
    path {
      fill: var(--pacman-alt);
    }
  }

  &.danger {
    svg {
      path {
        fill: var(--pacman-danger);

        animation-name: pacman;
        animation-duration: 500ms;
        animation-iteration-count: infinite;
        animation-direction: alternate;
      }
    }
  }
}

#pacman {
  object-fit: contain;

  path {
    fill: var(--pacman);
    transition-property: all;
    transition-duration: 500ms;
  }
}

#container .pacman.eating {}

#container .pacman[data-dir="left"] {
  transform: rotate(0deg);
}

#container .pacman[data-dir="up"] {
  transform: rotate(-90deg);
}

#container .pacman[data-dir="right"] {
  transform: rotate(0deg);
}

#container .pacman[data-dir="down"] {
  transform: rotate(90deg);
}

#container .pacman[data-flip="true"] {
  transform: scale(-1, 1);
}

#container .ghost {
  background-image: url('./images/ghost.svg');
  background-size: contain;
  overflow: hidden;
  z-index: 11;
  transition-property: all;
  transition-duration: 200ms;
  transition-delay: 100ms;
  opacity: 0.9;
}

#container .ghost:before {
  content: '';
  background-image: url('./images/ghost-eyes.svg');
  background-size: contain;
  left: 27%;
  top: 32%;
  display: block;
  position: absolute;
  width: 100%;
  height: 100%;
  z-index: -1;
  transition-property: all;
  transition-duration: 500ms;
}

#container .ghost[data-dir="up"]:before {
  top: 27%;
}

#container .ghost[data-dir="down"]:before {
  top: 37%;
}

#container .ghost[data-dir="left"]:before {
  left: 20%;
}

#container .ghost[data-dir="right"]:before {
  left: 34%;
}

.display-container {
  font-family: monospace;
  font-size: 2rem;

  >.value {
    display: inline-block;
    border: solid 2px transparent;
    text-align: center;
    position: relative !important;
    z-index: 1;
    overflow: hidden;
    flex-grow: 1;
    height: 100%;
    border-radius: 100%;

    &:before {
      content: '';
      display: block;
      position: absolute;
      z-index: -1;
      background-color: white;
      width: 100%;
      height: 100%;
    }

    > .val {
      position: absolute;
      width: 100%;
      height: 100%;
      left: 0;
      top: 0;
      text-align: center;
      color: black;
    }
  }
}

#points {
  position: absolute;
  bottom: 101%;
  right: 0%;
  width: 100%;
  margin-top: -10px;
  text-align: right;
  justify-content: end;

  &::after {
    content: '';
    display: block;
    position: absolute;
    left: 0;
    right: 0;
    bottom: -10%;
    border-bottom: solid 1px white;
  }
}

#clock {
  position: absolute;
  bottom: 101%;
  left: 0%;
  width: 100%;
  margin-top: -10px;
  color: white;
  display: none;
}


#controls {
  display: none;
  position: absolute;
  width: 160px;
  height: 160px;
  left: 50%;
  top: 50%;
  margin-left: -80px;
  margin-top: -80px;

  > button {
    appearance: none;
    font-size: 50px;
    position: absolute;
    border: none;
    width: 60px;
    height: 60px;
    line-height: 60px;
    text-align: center;
    padding: 0;
    transform: rotate(-45deg);
    transform-origin: center center;

    &.left {
      left: 0;
      top: 50%;
      margin-top: -30px;
    }

    &.right {
      right: 0;
      top: 50%;
      margin-top: -30px;
    }

    &.up {
      left: 50%;
      top: 0;
      margin-left: -30px;
    }

    &.down {
      left: 50%;
      bottom: 0;
      margin-left: -30px;
    }
  }
}

@media (pointer:coarse) {
  #controls {
    display: block;
  }
}

