:root {
  color-scheme: dark;
  font-family: ui-sans-serif, system-ui, sans-serif;
  color: #e8e4dc;
  background: #1b2022;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100svh;
  background: #1b2022;
}

main {
  min-height: 100svh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 30px;
  padding: 32px;
  text-align: center;
}

.intro {
  display: grid;
  justify-items: center;
  gap: 10px;
}

.intro p {
  max-width: 34rem;
  margin: 0;
  color: rgba(232, 228, 220, 0.62);
  font-size: clamp(0.88rem, 1.8vw, 1rem);
  line-height: 1.5;
  text-wrap: balance;
}

.maker {
  display: grid;
  justify-items: center;
  gap: 14px;
}

h1 {
  margin: 0;
  font-size: clamp(1.65rem, 4vw, 3rem);
  font-weight: 500;
  letter-spacing: -0.035em;
  line-height: 1.1;
  text-wrap: balance;
}

.assembly {
  position: relative;
  width: 96px;
  height: 18px;
}

.assembly::before {
  content: "";
  position: absolute;
  top: 50%;
  right: 0;
  left: 0;
  height: 1px;
  background: rgba(232, 228, 220, 0.18);
}

.capsule {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.capsule-half {
  position: relative;
  z-index: 2;
  width: 15px;
  height: 14px;
  border-top: 1px solid rgba(232, 228, 220, 0.7);
  border-bottom: 1px solid rgba(232, 228, 220, 0.7);
  opacity: 0.38;
}

.powder {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.powder i {
  --start-x: 0px;
  --end-x: 0px;
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: #e8e4dc;
  opacity: 0;
}

.powder i:nth-child(1) { --start-x: -15px; --end-x: -4px; }
.powder i:nth-child(2) { --start-x: -9px; --end-x: 2px; }
.powder i:nth-child(3) { --start-x: -3px; --end-x: -1px; }
.powder i:nth-child(4) { --start-x: 5px; --end-x: 4px; }
.powder i:nth-child(5) { --start-x: 11px; --end-x: -3px; }
.powder i:nth-child(6) { --start-x: 16px; --end-x: 1px; }

.capsule-left {
  border-left: 1px solid rgba(232, 228, 220, 0.7);
  border-radius: 999px 0 0 999px;
  background: #e8e4dc;
  transform: translate3d(-28px, 0, 0);
}

.capsule-right {
  border-right: 1px solid rgba(232, 228, 220, 0.7);
  border-radius: 0 999px 999px 0;
  background: #d9785f;
  transform: translate3d(28px, 0, 0);
}

.assembly.is-assembling .capsule {
  animation: complete-pill 1.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.assembly.is-assembling .capsule-half {
  will-change: transform, opacity;
}

.assembly.is-assembling .capsule-left {
  animation: assemble-left 1.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.assembly.is-assembling .capsule-right {
  animation: assemble-right 1.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.assembly.is-assembling .powder i {
  animation: fill-powder 1.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.assembly.is-assembling .powder i:nth-child(2),
.assembly.is-assembling .powder i:nth-child(5) {
  animation-delay: 40ms;
}

.assembly.is-assembling .powder i:nth-child(3),
.assembly.is-assembling .powder i:nth-child(6) {
  animation-delay: 80ms;
}

@keyframes fill-powder {
  0% {
    opacity: 0;
    transform: translate3d(var(--start-x), -13px, 0) scale(0.7);
  }

  10% {
    opacity: 0.9;
  }

  34% {
    opacity: 0.9;
    transform: translate3d(var(--end-x), 1px, 0) scale(1);
  }

  43%,
  100% {
    opacity: 0;
    transform: translate3d(var(--end-x), 2px, 0) scale(0.45);
  }
}

@keyframes assemble-left {
  0% {
    opacity: 0.38;
    transform: translate3d(-28px, 0, 0);
  }

  28% {
    opacity: 1;
  }

  62%,
  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

@keyframes assemble-right {
  0% {
    opacity: 0.38;
    transform: translate3d(28px, 0, 0);
  }

  28% {
    opacity: 1;
  }

  62%,
  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

@keyframes complete-pill {
  0%, 60% {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }

  68% {
    transform: scale(0.94, 1.06) rotate(0);
  }

  76% {
    transform: scale(1) rotate(-7deg);
  }

  86% {
    opacity: 1;
    transform: translate3d(0, 0, 0) rotate(0);
  }

  100% {
    opacity: 0;
    transform: translate3d(0, -9px, 0) rotate(0);
  }
}

button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid rgba(232, 228, 220, 0.42);
  border-radius: 999px;
  color: #e8e4dc;
  background: transparent;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 160ms ease-out, border-color 160ms ease-out;
}

button:hover:not(:disabled) {
  border-color: rgba(232, 228, 220, 0.72);
  background: rgba(232, 228, 220, 0.08);
}

button:focus-visible {
  outline: 2px solid #d9785f;
  outline-offset: 4px;
}

button:disabled {
  opacity: 0.48;
  cursor: wait;
}

.count-feedback {
  position: relative;
  display: grid;
  min-height: 18px;
  place-items: center;
}

#pill-count {
  margin: 0;
  color: rgba(232, 228, 220, 0.62);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.pill-feedback {
  position: absolute;
  top: 50%;
  left: calc(100% + 8px);
  color: #d9785f;
  font-size: 0.72rem;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translate3d(0, -30%, 0);
}

button.is-success {
  border-color: #d9785f;
  color: #d9785f;
}

.count-feedback.is-updated #pill-count {
  animation: confirm-count 480ms cubic-bezier(0.16, 1, 0.3, 1);
}

.count-feedback.is-updated .pill-feedback {
  animation: confirm-plus-one 520ms cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes confirm-count {
  0% {
    color: #d9785f;
    transform: scale(1);
  }

  35% {
    color: #d9785f;
    transform: scale(1.08);
  }

  100% {
    color: rgba(232, 228, 220, 0.62);
    transform: scale(1);
  }
}

@keyframes confirm-plus-one {
  0% {
    opacity: 0;
    transform: translate3d(0, -30%, 0);
  }

  22% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate3d(0, -115%, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .assembly.is-assembling .capsule,
  .assembly.is-assembling .capsule-half,
  .assembly.is-assembling .powder i {
    animation-duration: 0.01ms;
  }

  .powder {
    display: none;
  }

  .count-feedback.is-updated #pill-count,
  .count-feedback.is-updated .pill-feedback {
    animation: none;
  }

  .count-feedback.is-updated #pill-count {
    color: #d9785f;
  }
}
