<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>CSS Variables</title>

  <link rel="stylesheet" href="./styles.css">
</head>
<body>
  <h1 class="title">Update CSS variables with <span class="hl">JS</span></h1>

  <div class="container">
    <div class="controls">
      <div class="ranges">
        <label for="spacing">Spacing:</label>
        <input type="range" id="spacing" value="20" min=0 max=35>

        <label for="blur">Blur:</label>
        <input type="range" id="blur" value="0">
      </div>

      <div class="color">
        <label for="color">Color:</label>
        <input type="color" id="color" value="#FFC107">
      </div>
    </div>

    <img src="https://source.unsplash.com/p7mo8-CG5Gs/400x300">
  </div>

  <script src="./scripts.js"></script>
</body>
</html>
:root {
  --spacing: 20px;
  --blur: 0;
  --color: #FFC107;
}

* {
  margin: 0;
  padding: 0;
}

body {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(to right, #155799, #159957);
}

.container {
  width: 80vw;
  height: 55vh;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  flex-direction: column;
  position: relative;
}

.title {
  color: #fff;
  font-size: 48px;
  -webkit-text-stroke: 1px rgba(0, 0, 0, 0.2);
}

.title .hl {
  color: var(--color);
}

.controls {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.controls label {
  margin-right: 10px;
  color: #fff;
  font-size: 30px;
}

.controls input {
  margin-right: 30px;
}

.controls input:last-child {
  margin-right: 0;
}

.controls .ranges {
  margin-right: 30px;
}

img {
  max-width: 45%;
  min-width: 240px;
  padding: var(--spacing);
  background: var(--color);
  filter: blur(var(--blur));
  position: absolute;
  bottom: 0;
}

@media (max-width: 600px) {
  .container {
    width: 100vw;
    height: 85vh;
  }

  .title {
    font-size: 24px;
    margin-bottom: 15px;
  }

  .controls {
    width: 90%;
  }

  .controls label {
    text-align: center;
    font-size: 16px;
    display: block;
  }

  .controls label:last-of-type {
    margin-right: 0;
  }
}
function updateImage(e) {
  let inputKind = e.target.id,
      suffix = inputKind === 'color' ? '' : 'px',
      cssValue = `${e.target.value}${suffix}`;

  document.documentElement.style.setProperty(`--${inputKind}`, cssValue);
}

document.addEventListener('input', updateImage);