body {
  font-family: system-ui, sans-serif;
  padding: 3rem;
  color: #243c32;
  background: #f5f7f2;
}
.light-glow {
  position: absolute;
  inset: -30%;
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(ellipse at 50% 40%,
    rgba(255, 202, 100, .24) 0%,
    rgba(255, 183, 75, .15) 35%,
    rgba(255, 177, 60, .08) 65%,
    transparent 100%);
  filter: blur(45px);
  transition: opacity 1.5s ease;
}

.scene.on .light-glow {
  opacity: 1;
}

/* HEADING */

.heading {
  position: absolute;
  top: 35px;
  font-size: 10px;
  letter-spacing: 7px;
  color: #999;
  z-index: 6;
}

.subtitle {
  position: absolute;
  bottom: 35px;
  font-size: 9px;
  letter-spacing: 4px;
  color: #777;
  z-index: 6;
}

/* BULB */

.lamp {
  position: absolute;
  top: 105px;
  width: 115px;
  height: 135px;
  z-index: 5;
}

.bulb {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.glass {
  fill: #b9bdc5;
  fill-opacity: .09;
  stroke: #9da1a9;
  stroke-width: 2;
  transition: all 1s ease;
}

.scene.on .glass {
  fill: #ffdc8b;
  fill-opacity: .85;
  stroke: #fff0c2;
  filter: drop-shadow(0 0 25px #ffc75a);
}

.filament {
  fill: none;
  stroke: #aaa;
  stroke-width: 3;
  stroke-linecap: round;
}

.scene.on .filament {
  stroke: #fff7d7;
  filter: drop-shadow(0 0 7px #fff0a5);
}

.base {
  fill: #858991;
  stroke: #b5b8bf;
  stroke-width: 1;
}

.scene.on .base {
  fill: #b28a45;
  stroke: #ffe2a1;
}

/* PULL STRING */

.string-area {
  position: absolute;
  top: 229px;
  width: 80px;
  height: 280px;
  z-index: 7;
  display: flex;
  justify-content: center;
}

.string {
  position: absolute;
  top: 0;
  width: 2px;
  height: 110px;
  background: linear-gradient(#aaa, #eee);
  transition: height .15s ease;
}

.pull-handle {
  position: absolute;
  top: 110px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(145deg, #fff, #777);
  border: 2px solid #ddd;
  box-shadow: 0 0 12px #ffffff35;
  cursor: grab;
  touch-action: none;
}

.pull-handle:active {
  cursor: grabbing;
}

.scene.on .pull-handle {
  box-shadow: 0 0 22px #ffcf70;
}

/* FULL SCREEN FLOATING WORDS */

.particles {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  pointer-events: none;
  z-index: 3;
}

.word {
  position: absolute;
  color: #ffe4a8;
  font-size: 12px;
  letter-spacing: 3px;
  font-weight: 500;
  opacity: 0;
  white-space: nowrap;

  text-shadow:
    0 0 8px #ffc75a,
    0 0 18px #ffb52b,
    0 0 30px #ffb52b;

  animation: floatWord var(--duration) ease-in-out infinite;
  animation-delay: var(--delay);
  transition: opacity 1s ease;
}

.scene.on .word {
  opacity: var(--opacity);
}

@keyframes floatWord {
  0% {
    transform: translate3d(0, 35px, 0) scale(.8);
  }

  50% {
    transform: translate3d(12px, -35px, 0) scale(1.1);
  }

  100% {
    transform: translate3d(-8px, -100px, 0) scale(.8);
  }
}

/* INSTRUCTIONS */

.instruction {
  position: absolute;
  bottom: 100px;
  text-align: center;
  color: #999;
  font-size: 10px;
  letter-spacing: 2px;
  line-height: 2.2;
  z-index: 6;
}

.status {
  color: #c5a66e;
  font-size: 10px;
  letter-spacing: 4px;
  margin-top: 10px;
}
</style>
</head>

<body>

<div class="scene" id="scene">

  <div class="heading">A LITTLE MAGIC FOR YOU</div>

  <div class="light-glow"></div>

  <div class="particles" id="particles"></div>

  <div class="lamp">
    <svg class="bulb" viewBox="0 0 120 145">

      <path class="glass"
        d="M60 5 C25 5 12 32 17 58
        C20 77 36 87 40 105
        L80 105 C84 87 100 77 103 58
        C108 32 95 5 60 5Z"/>

      <path class="filament"
        d="M43 75 L50 61 L60 75 L70 61 L77 75"/>

      <path class="filament"
        d="M50 61 L50 51 M70 61 L70 51"/>

      <rect class="base" x="41" y="105" width="38" height="9" rx="2"/>
      <rect class="base" x="43" y="115" width="34" height="7" rx="2"/>

      <path class="base"
        d="M45 122 L75 122 L68 137 L52 137Z"/>

    </svg>
  </div>

  <div class="string-area">
    <div class="string" id="string"></div>
    <div class="pull-handle" id="handle"></div>
  </div>

  <div class="instruction">
    PULL DOWN TO TURN ON<br>
    PULL UP TO TURN OFF

    <div class="status" id="status">LIGHT IS OFF</div>
  </div>

  <div class="subtitle">MADE WITH A LITTLE FEELING</div>

</div>

<script>
const scene = document.getElementById("scene");
const handle = document.getElementById("handle");
const string = document.getElementById("string");
const statusText = document.getElementById("status");
const particles = document.getElementById("particles");

let isOn = false;
let dragging = false;
let startY = 0;
let currentLength = 110;

const defaultLength = 110;

// Create MANHA words across the ENTIRE screen

for (let i = 0; i < 45; i++) {
  const word = document.createElement("div");

  word.className = "word";
  word.textContent = "MANHA";

  word.style.left = (Math.random() * 90 + 3) + "%";
  word.style.top = (Math.random() * 88 + 5) + "%";

  word.style.setProperty(
    "--duration",
    (5 + Math.random() * 7) + "s"
  );

  word.style.setProperty(
    "--delay",
    (Math.random() * 8) + "s"
  );

  word.style.setProperty(
    "--opacity",
    (0.35 + Math.random() * 0.55)
  );

  particles.appendChild(word);
}

// LIGHT ON / OFF

function setLight(value) {
  isOn = value;

  scene.classList.toggle("on", isOn);

  statusText.textContent = isOn
    ? "LIGHT IS ON"
    : "LIGHT IS OFF";
}

// UPDATE STRING

function updateString(length) {
  currentLength = length;

  string.style.height = length + "px";
  handle.style.top = length + "px";
}

// START DRAGGING

handle.addEventListener("pointerdown", (e) => {
  dragging = true;
  startY = e.clientY;

  handle.setPointerCapture(e.pointerId);
});

// MOVE STRING

handle.addEventListener("pointermove", (e) => {
  if (!dragging) return;

  const difference = e.clientY - startY;

  let newLength = defaultLength + difference;

  newLength = Math.max(15, Math.min(235, newLength));

  updateString(newLength);
});

// RELEASE STRING

function releaseString() {
  if (!dragging) return;

  dragging = false;

  if (currentLength > 175) {
    setLight(true);
  }

  if (currentLength < 45) {
    setLight(false);
  }

  updateString(defaultLength);
}

handle.addEventListener("pointerup", releaseString);
handle.addEventListener("pointercancel", releaseString);

</script>

</body>
</html>

