@font-face {
  font-family: 'DungGeunMo';
  src: url('https://fastly.jsdelivr.net/gh/projectnoonnu/noonfonts_six@1.2/DungGeunMo.woff')
    format('woff');
  font-weight: normal;
  font-style: normal;
}

:root {
  --pixel: 5;
  @media screen and (max-width: 1800px) {
    --pixel: 4;
  }
  @media screen and (max-width: 1200px) {
    --pixel: 3;
  }
  @media screen and (max-width: 800px) {
    --pixel: 2;
  }
  @media screen and (max-width: 600px) {
    --pixel: 1;
  }
  --block: calc(24px * var(--pixel));
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  overflow: hidden;
  * {
    font-family: 'DungGeunMo';
    font-size: 24px;
    font-weight: bold;
    -webkit-font-smoothing: none;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeSpeed;
  }
}
@keyframes transition-1 {
  0% {
    mask-image: url(./assets/t1-1.png);
  }
  25% {
    mask-image: url(./assets/t1-2.png);
  }
  50% {
    mask-image: url(./assets/t1-3.png);
  }
  75% {
    mask-image: url(./assets/t1-4.png);
  }
  100% {
    mask-image: url(./assets/t1-5.png);
  }
}
@keyframes transition-2 {
  0% {
    mask-image: url(./assets/t2-1.png);
  }
  25% {
    mask-image: url(./assets/t2-2.png);
  }
  50% {
    mask-image: url(./assets/t2-3.png);
  }
  75% {
    mask-image: url(./assets/t2-4.png);
  }
  100% {
    mask-image: url(./assets/t2-5.png);
  }
}
.intro {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100vw;
  height: 100vh;
  background-image: url(./assets/bg.png);
  background-size: cover;
  z-index: 300;
  &.done {
    mask-size: var(--block) var(--block);
    animation: transition-1 2s steps(5) forwards;
  }
  .cover {
    width: 40vw;
    min-width: 300px;
    text-align: center;
    img {
      width: 100%;
      height: 100%;
      margin-bottom: var(--block);
      object-fit: contain;
    }
  }
  &:not(.skip) .message {
    display: none;
  }
  &.skip .cover {
    display: none;
  }
}
.status-bar {
  position: fixed;
  top: calc(var(--block) * 0.5);
  width: calc(var(--block) * 4);
  height: var(--block);
  background-size: var(--block) var(--block);
  z-index: 200;
  ul {
    display: flex;
  }
  li {
    width: var(--block);
    height: var(--block);
    background-repeat: no-repeat;
    background-size: cover;
  }
  &::before, &::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: calc(var(--block) * -1);
    width: var(--block);
    height: var(--block);
    background-repeat: no-repeat;
    background-size: auto var(--block);
    background-position: top right;
  }
  &::after {
    right: calc(var(--block) * -1);
    left: auto;
    background-position: top left;
  }
  &.heart {
    left: var(--block);
    background-image: url(./assets/status_bar-red-center.png);
    &::before {
      background-image: url(./assets/status_bar-red-left.png);
    }
    &::after {
      background-image: url(./assets/status_bar-red-right.png);
    }
    li {
      background-image: url(./assets/status_heart.png);
      &:not(:first-child) {
        margin-left: calc(var(--block) * -0.2);
      }
    }
  }
  &.coin {
    right: var(--block);
    left: auto;
    background-image: url(./assets/status_bar-yellow-center.png);
    &::before {
      background-image: url(./assets/status_bar-yellow-left.png);
    }
    &::after {
      background-image: url(./assets/status_bar-yellow-right.png);
    }
    ul {
      justify-content: end;
    }
    li {
      display: flex;
      justify-content: center;
      align-items: center;
      color: #71403b;
      font-size: max(var(--pixel) * 7.2px, 24px) !important;
      text-indent: -0.1em;
      background-image: url(./assets/status_coin.png);
      &:not(:first-child) {
        margin-left: calc(var(--block) * -0.2);
      }
    }
  }
}
.message {
  position: absolute;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: var(--block);
  align-items: center;
  width: 40vw;
  min-width: 300px;
  max-height: calc(70vh - 36px * 2);
  border: 24px solid transparent;
  border-image: url(./assets/scroll.png) 12 / var(--block) /
    calc(var(--block) * 0.5) round;
  background-color: #efc083;
  z-index: 200;
  & > div {
    margin-top: calc(var(--block) * 0.5);
    text-align: center;
    button {
      margin-top: calc(var(--block) * 0.5);
    }
  }
}
.result {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  opacity: 0;
}
.map {
  position: absolute;
  top: 50%;
  left: 50%;
  display: grid;
  grid-template-columns: repeat(var(--x), 1fr);
  width: max-content;
  background-image: url(./assets/map/k.gif);
  background-size: var(--block) var(--block);
  transform: translate(-50%, -50%);
  & > div {
    position: relative;
    width: var(--block);
    height: var(--block);
    background-repeat: no-repeat;
    background-size: var(--block) var(--block);
    &.object {
      &::before {
        content: '';
        position: absolute;
        inset: 0;
        background-repeat: no-repeat;
        background-size: cover;
      }
    }
    &.tree {
      &::before {
        background-image: url(./assets/map/tree.png);
      }
    }
    &.rock {
      &::before {
        background-image: url(./assets/map/rock.png);
      }
    }
    &[data-name='top-left'] {
      background-image: url(./assets/map/a-1.gif);
    }
    &[data-name='top-center'] {
      background-image: url(./assets/map/a-2.gif);
    }
    &[data-name='top-right'] {
      background-image: url(./assets/map/a-3.gif);
    }
    &[data-name='middle-left'] {
      background-image: url(./assets/map/a-4.gif);
    }
    &[data-name='middle-center'] {
      background-image: url(./assets/map/a-5.gif);
    }
    &[data-name='middle-right'] {
      background-image: url(./assets/map/a-6.gif);
    }
    &[data-name='bottom-left'] {
      background-image: url(./assets/map/a-7.gif);
    }
    &[data-name='bottom-center'] {
      background-image: url(./assets/map/a-8.gif);
    }
    &[data-name='bottom-right'] {
      background-image: url(./assets/map/a-9.gif);
    }
    &::after {
      position: absolute;
      inset: 0;
      background-size: cover;
    }
    &.coin::after {
      content: '';
      background-image: url(./assets/coin.png);
    }
  }
}
@keyframes fairy {
  from {
    background-position: 0 0;
  }
  to {
    background-position: calc(var(--block) * -4) 0;
  }
}
@keyframes move {
  0% {
    offset-distance: 0%;
  }
  100% {
    offset-distance: 100%;
  }
}
@keyframes shoot {
  from {
    background-position: calc(var(--block) * -3) 0;
  }
  to {
    background-position: calc(var(--block) * -10) 0;
  }
}
.fairy {
  position: absolute;
  width: var(--block);
  height: var(--block);
  background-repeat: no-repeat;
  background-image: url(./assets/fairy.png);
  background-size: cover;
  animation: fairy 1s steps(4) infinite;
  z-index: 200;
  pointer-events: none;
  offset-rotate: 0deg;
  opacity: 0;
  transition: opacity 0.6s steps(3);
  &.active {
    opacity: 1;
  }
  &.move {
    top: 0 !important;
    left: 0 !important;
    animation: fairy 0.5s steps(4) infinite, move 10s linear forwards;
  }
  &.shoot {
    animation: shoot 1s steps(7) infinite;
  }
}

canvas {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 100vw;
  height: 100vh;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
input {
  width: 2em;
  border: none;
  background-color: transparent;
  outline: none;
}
button {
  position: relative;
  min-width: 100px;
  padding: calc(var(--pixel) * 1px);
  border: none;
  background-color: transparent;
  filter: drop-shadow(0 calc(var(--pixel) * 1px) 0 rgba(0, 0, 0, 0.4));
  cursor: pointer;
  &:active {
    transform: translateY(calc(var(--pixel) * 1px));
    filter: drop-shadow(0 0 0 rgba(0, 0, 0, 0.4));
  }
  &::before {
    content: '';
    position: absolute;
    top: 0;
    right: calc(var(--pixel) * 1px);
    bottom: 0;
    left: calc(var(--pixel) * 1px);
    background-color: #000;
    z-index: -1;
  }
  &::after {
    content: '';
    position: absolute;
    top: calc(var(--pixel) * 1px);
    right: 0;
    bottom: calc(var(--pixel) * 1px);
    left: 0;
    background-color: #000;
    z-index: -1;
  }
  p {
    position: relative;
    padding: calc(var(--pixel) * 1px) calc(var(--pixel) * 6px)
      calc(var(--pixel) * 2px);
    color: var(--color, #000);
    background-color: var(--bg, #fff);
    &::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      bottom: 0;
      width: calc(var(--pixel) * 1px);
      background-color: rgba(0, 0, 0, 0.4);
    }
    &::after {
      content: '';
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      width: calc(var(--pixel) * 1px);
      background-color: rgba(0, 0, 0, 0.4);
    }
  }
  span {
    position: relative;
    display: block;
    height: 100%;
    padding: calc(var(--pixel) * 2px) calc(var(--pixel) * 1px);
    font-size: max(var(--pixel) * 7.2px, 24px) !important;
    z-index: 10;
    &::after {
      content: '';
      position: absolute;
      right: calc(var(--pixel) * -6px);
      bottom: calc(var(--pixel) * -2px);
      left: calc(var(--pixel) * -6px);
      height: calc(var(--pixel) * 1px);
      background-color: rgba(0, 0, 0, 0.4);
      z-index: -1;
    }
  }
}

section {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  transform: translate(-50%, -50%);
  z-index: 20;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes fade-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}
.fade-in {
  pointer-events: all;
  animation: fade-in 0.6s steps(3) forwards;
}
.fade-out {
  pointer-events: none;
  animation: fade-out 0.6s steps(3) forwards;
}
.controler {
  position: fixed;
  bottom: var(--block);
  left: 50%;
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  z-index: 300;
  &.active {
    pointer-events: all;
    animation: fade-in 0.6s steps(3) forwards;
  }
  &.inactive {
    animation: fade-out 0.6s steps(3) forwards;
  }
}

@keyframes blink-mask {
  from {
    mask-position: var(--block) 0;
  }
  to {
    mask-position: calc(var(--block) * -1) 0;
  }
}
@keyframes blink-light {
  from {
    left: 100%;
  }
  to {
    left: -100%;
  }
}
@keyframes coin-pop {
  0% {
    top: 0;
  }
  45% {
    top: calc(var(--block) * -0.2);
  }
  55% {
    top: calc(var(--block) * -0.2);
  }
  100% {
    top: 0;
  }
}
@keyframes shadow-pop {
  0% {
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
  45% {
    transform: translate3d(0, calc(var(--block) * 0.2), 0);
    opacity: 0.6;
  }
  55% {
    transform: translate3d(0, calc(var(--block) * 0.2), 0);
    opacity: 1;
  }
  100% {
    transform: translate3d(0, 0, 0);
    opacity: 0.6;
  }
}
@keyframes sparkling {
  from {
    background-position: var(--block) 0;
  }
  100% {
    background-position: calc(var(--block) * -7) 0;
  }
}

#playground {
  display: flex;
  justify-content: center;
  align-items: center;
  ul {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: calc(
      var(--block) *
        min(max(var(--main-grid-count) - var(--item-count) + 1, 0), 1)
    );
    margin-left: calc(
      round(down, var(--main-grid-count) * 0.5, 1) - var(--item-count) * '1px'
    );
    list-style: none;
    &.winner li {
      animation: coin-pop 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94) 2;
      .sparkling {
        animation: sparkling 0.8s steps(8) 2;
      }
      &::after {
        animation: shadow-pop 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94) 2;
      }
    }
    &.blink {
      .effect,
      .effect::before {
        animation: blink-mask 1.5s forwards;
      }
    }
  }
  li {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    aspect-ratio: 1 / 1;
    width: var(--block);
    height: auto;
    font-size: calc(var(--block) * (38 / 72));
    font-weight: normal;
    background-repeat: no-repeat;
    background-size: var(--block) var(--block);
    background-image: url(./assets/coin.png);
    opacity: 0;
    .sparkling {
      position: absolute;
      inset: 0;
      background-repeat: no-repeat;
      background-size: 700% 100%;
      background-image: url(./assets/sparkling.png);
      background-position: var(--block) 0;
      z-index: 100;
    }
    &.init {
      opacity: 1;
    }
    &.winner {
      animation: coin-pop 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94) 2;
      .sparkling {
        animation: sparkling 0.8s steps(8) 2;
      }
      &::after {
        animation: shadow-pop 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94) 2;
      }
    }
    &::before {
      content: attr(data-no);
      position: absolute;
      left: 50%;
      color: #eea700;
      -webkit-text-stroke: 1px #eea700;
      transform: translate(-50%, calc(var(--pixel) * -1px));
      z-index: 10;
    }
    &::after {
      content: '';
      position: absolute;
      inset: 0;
      background-repeat: no-repeat;
      background-size: var(--block) var(--block);
      background-image: url(./assets/coin_shadow.png);
      z-index: -1;
    }
    .effect {
      position: absolute;
      inset: 0;
      display: flex;
      justify-content: center;
      align-items: center;
      width: 100%;
      height: 100%;
      font-size: calc(var(--block) * (38 / 72));
      font-weight: normal;
      background-repeat: no-repeat;
      background-size: var(--block) var(--block);
      z-index: 20;
      mask-image: url(./assets/coin_mask.png);
      mask-size: 200% 100%;
      mask-repeat: no-repeat;
      mask-position: var(--block) 0;
      &::before {
        content: '';
        position: absolute;
        top: 0;
        inset: 0;
        background-repeat: no-repeat;
        background-size: var(--block) var(--block);
        background-image: url(./assets/coin_plate.png);
        mask-image: url(./assets/coin_light.png);
        mask-size: cover;
        mask-repeat: no-repeat;
        mask-position: var(--block) 0;
        z-index: 30;
      }
      div {
        position: absolute;
        inset: 0;
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100%;
        height: 100%;
        font-size: calc(var(--block) * (38 / 72));
        font-weight: normal;
        background-repeat: no-repeat;
        background-size: var(--block) var(--block);
        background-image: url(./assets/coin.png);
        z-index: 20;
        /* mask-image: url(./assets/coin_light.png); */
        mask-size: cover;
        mask-repeat: no-repeat;
        mask-position: var(--block) 0;
        &::before {
          content: attr(data-no);
          position: absolute;
          left: 50%;
          color: #eea700;
          -webkit-text-stroke: 1px #eea700;
          transform: translate(-50%, calc(var(--pixel) * -1px));
          z-index: 10;
        }
        &::after {
          content: none;
        }
      }
    }
    &.blink {
      .effect,
      .effect::before {
        animation: blink-mask 1.5s forwards;
      }
    }
    span {
      font-size: calc(var(--block) * (38 / 72));
      font-weight: normal;
      color: #df8500;
      -webkit-text-stroke: 1px #df8500;
      transform: translate(
        calc(var(--pixel) * -1px),
        calc(var(--pixel) * -1px)
      );
    }
  }
}
