* {
  box-sizing: border-box;
}

body {
  background: #f0e6cb;
  padding: 1rem;
  margin: 0;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  container-type: size;
  touch-action: pan-x pan-y;
}

.logo {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 100;
  display: flex;
  width: 32px;
  height: 32px;
  opacity: 0.7;
  transition: opacity 0.15s;
}

.logo:hover {
  opacity: 1;
}

.logo img {
  width: 100%;
  height: 100%;
}

main {
  flex-grow: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-direction: column;
}

nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2rem;

  button {
    --bg: #f5f5dd;
    --fg: #897c69;

    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.5rem;
    padding: 8px;
    border-radius: 1.5rem;
    font-weight: bold;
    color: var(--fg);
    background: var(--bg);
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    transform: none;

    &:active,
    &:hover {
      --bg: #0bc5b7;
      --fg: #b6fdfc;
      --shadow: rgba(85, 75, 51, 0.5);
      outline: 8px solid white;
    }

    &:active {
      box-shadow: 0.25rem 0.25rem 0.5rem var(--shadow);
      transform: translate(2px, 2px);
    }

    &[data-shortcut]:before {
      content: attr(data-shortcut);
      box-sizing: border-box;
      font-weight: 500;
      border-radius: 1000px;
      display: inline-flex;
      justify-content: center;
      align-items: center;
      background: var(--fg);
      color: var(--bg);
      width: 2rem;
      height: 2rem;
      padding-bottom: 4px;
    }
  }
}

h1 {
  text-align: center;
  color: #0bc5b7;
  margin: 0;

  &.won {
    color: violet;
    text-shadow: 2px 2px 0 teal;
  }
  &.lost {
    color: red;
  }
}

game-board {
  --bg: #a268fd;
  --tile: rgba(255, 255, 255, 0.2);
  --flipped: #f3eedb;
  --gap: 4px;
  --grid-size: 5;
  height: 40%;
  max-height: 300px;
  max-width: 300px;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-radius: 16px;
  padding: 8px;
  gap: var(--gap);
  transition: all 0.5s;
  transform: scale(1);

  &.target.won {
    background: rgba(0, 0, 0, 0.2);
    transform: scale(0.8);
  }
  &.board.green {
    background: #60c267;
  }
  &.board.won {
    transform: scale(0.5);
    z-index: 50;
    position: absolute;
    bottom: -2rem;
    right: -2rem;
  }
}

game-row {
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(var(--grid-size), 1fr);
}

game-tile {
  border-radius: 8px;
  background: var(--tile);
  aspect-ratio: 1;
  transform: scaleX(1);
  transition: all 0.25s;

  &.flipped {
    background: var(--flipped);
    transform: scaleX(-1);
  }
}

.board:not(.won) game-tile {
  cursor: pointer;

  &:hover {
    outline: 4px solid rgba(61, 30, 106, 0.5);
    outline-offset: 4px;
    z-index: 10;
  }
  &.flipped:hover {
    outline: 4px solid rgba(255, 255, 255, 0.5);
  }
}

@container (aspect-ratio > 1) {
  main {
    flex-direction: row;
  }

  game-board {
    height: unset;
    width: 40%;
  }
}

@keyframes translate-in-top {
  0% {
    transform: translate(-1000px, -1000px) rotate(var(--deg));
    opacity: 0;
  }
  100% {
    transform: translate(0, 0) rotate(var(--deg));
    opacity: 1;
  }
}

@keyframes translate-in-bottom {
  0% {
    transform: translate(1000px, 1000px) rotate(var(--deg));
    opacity: 0;
  }
  100% {
    transform: translate(0, 0) rotate(var(--deg));
    opacity: 1;
  }
}

game-dialog-wrapper {
  --deg: -8deg;
  --bg: #f5f5dd;
  --fg: #897c69;
  --line1: #0bc5b7;
  --line2: #4dd4cc;
  --lines: repeating-linear-gradient(
    45deg,

    var(--line1) 0px,
    var(--line1) 10px,
    var(--line2) 10px,
    var(--line2) 20px
  );

  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;

  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--lines);
    z-index: -1;
  }

  &::after {
    animation: translate-in-bottom 0.25s forwards;

    content: '';
    position: absolute;
    top: 15%;
    left: -50%;
    width: 200%;
    height: 75%;
    background: rgba(255, 255, 255, 0.5);
    background: #f2f2da;
    transform: rotate(-4deg);
    box-shadow: 24px 24px 24px rgba(0, 0, 0, 0.25);
    z-index: -1;
  }

  game-dialog {
    --bg: #ffffff99;
    --fg: #897c69;

    text-align: center;
    position: relative;
    box-sizing: border-box;
    margin: 0;
    padding: 1rem 4rem;
    border-radius: 12rem;
    border-top-right-radius: 16rem;
    border-bottom-left-radius: 16rem;
    font-size: 2rem;
    font-weight: bold;
    background: var(--bg);
    color: var(--fg);
  }

  button {
    --deg: 0deg;
    animation: translate-in-bottom 0.5s forwards;

    position: absolute;
    font: inherit;
    padding: 1rem 2rem;
    border-radius: 2rem;
    cursor: pointer;
    transition: all 0.2s;
    background: #fb8b8e;
    color: white;
    border: none;
    white-space: nowrap;
    right: 0;

    &:focus,
    &:hover {
      outline: 8px solid #fb8b8e;
      outline-offset: 8px;
    }
    &:hover {
      background: #eb6b6e;
    }
    &:active {
      transform: translate(2px, 2px);
    }
  }

  dialog-label {
    --deg: -4deg;
    animation: translate-in-top 0.5s forwards;

    position: absolute;
    top: -3rem;
    left: -2rem;
    background: var(--bg);
    color: #0bc5b7;
    font-size: 2rem;
    padding: 1rem;
    transform: rotate(-12deg);
    border-radius: 1000px;
  }
}

@container (width < 600px) {
  nav {
    justify-content: space-between;

    & button {
      display: none;
    }
    & button[data-shortcut=x],
    & button[data-shortcut=n] {
      display: inline-flex;
    }
  }

  game-dialog-wrapper {
    game-dialog {
      padding: 0 2rem;
    }
  }
}

