* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: white;
  color: black;
  font-family: "Times New Roman", Times, serif;
  text-align: center;
}

header {
  padding: 22px 12px 0;
}

h1 {
  font-size: clamp(32px, 6vw, 52px);
  margin: 0 0 14px;
}

nav {
  display: flex;
  justify-content: center;
  gap: 12px;
}

nav a {
  display: inline-block;
  padding: 6px 17px;
  border: 2px outset #ddd;
  background: #eee;
  color: #00e;
  font-size: 18px;
}

nav a:active {
  border-style: inset;
}

.notice {
  font-size: 16px;
  margin: 23px 10px 0;
}

.lab {
  width: min(760px, 100%);
  height: 510px;
  margin: 0 auto;
  position: relative;
  isolation: isolate;
}

.orbit-guide {
  position: absolute;
  width: 70%;
  height: 52%;
  left: 15%;
  top: 24%;
  border: 1px dashed #ddd;
  border-radius: 50%;
}

.scientist {
  position: absolute;
  width: 32%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
}

.ingredient {
  width: 23%;
  position: absolute;
  left: 50%;
  top: 50%;
  margin: 0;
  will-change: transform;
  z-index: 3;
}

.ingredient img {
  width: 100%;
  display: block;
}

figcaption {
  font-weight: bold;
  font-size: 23px;
}

.result {
  position: absolute;
  width: 47%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  z-index: 5;
}

.result img {
  width: 100%;
  display: block;
}

.result figcaption {
  font-size: 40px;
}

.controls {
  min-height: 110px;
  padding: 0 12px;
}

button {
  font: bold 23px "Times New Roman", Times, serif;
  padding: 10px 22px;
  cursor: pointer;
  background: #eee;
  color: black;
  border: 3px outset #ddd;
  border-radius: 0;
}

button:active {
  border-style: inset;
}

button:disabled {
  cursor: wait;
  color: #666;
}

button:focus-visible, a:focus-visible {
  outline: 3px solid blue;
  outline-offset: 4px;
}

#status {
  font-size: 16px;
  margin: 10px 0;
}

footer {
  margin: 20px 12px;
  font-size: 14px;
}

.explosion {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 340px;
  height: 340px;
  max-width: 90%;
  background: #bfff00;
  clip-path: polygon(50% 0,59% 24%,79% 5%,76% 33%,100% 31%,81% 50%,100% 69%,74% 69%,81% 96%,59% 78%,50% 100%,40% 77%,16% 97%,24% 69%,0 71%,19% 50%,0 30%,26% 33%,20% 5%,42% 25%);
  z-index: 8;
  display: grid;
  place-items: center;
  transform: translate(-50%,-50%) scale(0);
  visibility: hidden;
}

.lab.exploding .explosion {
  visibility: visible;
  animation: boom 650ms ease-out forwards;
}

.lab.exploding {
  animation: shake 350ms linear;
}

.lab.finished .result {
  animation: reveal 420ms steps(4,end) both;
}

.particle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 12px;
  height: 12px;
  background: var(--color);
  z-index: 7;
  animation: particle 850ms ease-out forwards;
}

@keyframes boom {
  0% {
    transform: translate(-50%,-50%) scale(.1) rotate(-15deg);
  }
  30% {
    transform: translate(-50%,-50%) scale(1.2) rotate(8deg);
  }
  65% {
    opacity: 1;
  }
  100% {
    transform: translate(-50%,-50%) scale(1.55);
    opacity: 0;
  }
}

@keyframes shake {
  0%,100% {
    translate: 0;
  }
  20%,60% {
    translate: -8px 5px;
  }
  40%,80% {
    translate: 8px -5px;
  }
}

@keyframes reveal {
  from {
    transform: translate(-50%,-50%) scale(.25) rotate(-10deg);
  }
  to {
    transform: translate(-50%,-50%) scale(1) rotate(0);
  }
}

@keyframes particle {
  from {
    transform: translate(-50%,-50%);
    opacity: 1;
  }
  to {
    transform: translate(var(--x), var(--y)) rotate(280deg);
    opacity: 0;
  }
}

@media (max-width: 540px) {
  header {
    padding-top: 25px;
  }
  .lab {
    height: 420px;
  }
  .scientist {
    width: 40%;
  }
  .ingredient {
    width: 26%;
  }
  .result {
    width: 67%;
  }
  .notice {
    margin-top: 25px;
  }
  figcaption {
    font-size: 19px;
  }
}

@media (max-width: 360px) {
  .lab {
    height: 360px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
  }
}
