EN TR
<h3>Color palette generator</h3>

<ul class="color-palette" id="color-palette"></ul>

<div class="action">
	<button type="button" onclick="generateColorPalette()">Generate palette</button>
	<p>
		Or just press the “Spacebar” to generate new palettes.
	</p>
</div>

<div class="shortcut-text">
	Click to copy individual color • Press “C” to copy palette
</div>
@import url('https://fonts.googleapis.com/css2?family=Mulish:[email protected];600;700;900&display=swap');

* {
  padding: 0;
  margin: 0;
  list-style: none;
  border: none;
  text-decoration: none;
  box-sizing: border-box;
  -webkit-overflow-scrolling: touch;
  font-family: 'Mulish', sans-serif;

  &:focus {
    outline: 0;
  }
}

html, body {
  height: 100%;
}

body {
  background: #E8ECF3;
  display: grid;
  place-items: center;
}

.alert {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  padding: 18px 42px;
  background: #0C1226;
  color: #fff;
  font-size: 18px;
  border-radius: 30px;
  opacity: 0;
  visibility: hidden;
  transition: 300ms all;

  &.active {
    top: 20px;
    opacity: 1;
    visibility: visible;
  }
}

h3 {
  font-size: 34px;
  font-weight: bold;
  color: #0C1226;
}

ul.color-palette {
  display: flex;

  li {
    margin: 0 15px;
    width: 207px;
    height: 329px;
    background: #fff;
    border-radius: 15px;
    display: flex;
    flex-direction: column;
    padding: 10px;
    cursor: pointer;
    position: relative;
    top: 0;
    transition: 300ms all;

    &:hover {
      box-shadow: 0 15px 42px -12px #A8B2C3;
      top: -10px;
    }

    input {
      position: absolute;
      opacity: 0;
      left: -999999px;
    }

    .color {
      width: 100%;
      height: 251px;
      background: var(--color);
      border-radius: 5px;
      margin-bottom: 20px;
    }

    .text {
      text-align: center;
      font-size: 22px;
      font-weight: bold;
      color: #0C1226;
    }
  }
}

.action {
  text-align: center;

  button {
    width: 393px;
    height: 68px;
    background: #7E6CCA;
    border-radius: 5px;
    color: #fff;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    margin-bottom: 20px;
  }

  p {
    font-size: 18px;
    color: #0C1226;
    line-height: 29px;
  }
}

.shortcut-text {
  background: #fff;
  padding: 9px 20px;
  border-radius: 25px;
  font-size: 16px;
  color: #0C1226;
}
let colorPalette = document.getElementById('color-palette');
let currentElem;

function notification(msg){

    let old_div = document.querySelector('.alert');
    if (old_div){
        old_div.parentNode.removeChild(old_div);
    }

    let div = document.createElement('div');
    div.className = 'alert';
    div.innerHTML = msg;
    document.body.appendChild(div);

    setTimeout(() => div.classList.add('active'), 1);
    setTimeout(() => div.classList.remove('active'), 1000);

}

function generateColorPalette(){
    colorPalette.innerHTML = '';
    for (let i = 1; i <= 5; i++){

        let color = generateColor();

        let li = document.createElement('li');

        let spanColor = document.createElement('span');
        spanColor.className = 'color';
        spanColor.style.setProperty('--color', color);
        let spanText = document.createElement('span');
        spanText.className = 'text';
        spanText.innerText = color;
        let input = document.createElement('input');
        input.name = 'color';
        input.value = color;

        li.appendChild(spanColor);
        li.appendChild(spanText);
        li.appendChild(input);
        colorPalette.appendChild(li);

        li.addEventListener('mouseover', (e) => {
            currentElem = e.target.parentNode;
        });

        li.addEventListener('click', (e) => {
            let targetInput = e.target.parentNode.querySelector('input[name="color"]');
            targetInput .select();
            document.execCommand('copy');
            notification('Color <b>' + targetInput.value  + '</b> copied to your clipboard')
        });

    }
}

function generateColor(){
    let str = 'abcdef0123456789';
    let color = '#';
    for (let i = 0; i <= 5; i++) {
        color += str[Math.floor(Math.random() * str.length)];
    }
    return color;
}

window.addEventListener('keypress', (e) => {
    if (e.keyCode === 32){
        generateColorPalette();
    } else if (e.keyCode === 99 && currentElem){
        let targetInput = currentElem.querySelector('input[name="color"]');
        targetInput.select();
        document.execCommand('copy');
        notification('Color <b>' + targetInput.value  + '</b> copied to your clipboard');
    }
    e.preventDefault();
});

generateColorPalette();