/* Where the dots begin, as a share of the button's width. Registered so it can be animated. */
@property --dh-dbutton-from {
  syntax: "<percentage>";
  inherits: true;
  initial-value: 58%;
}

.dh-dbutton {
  --dh-dbutton-colour: var(--dh-accent, #2563ff);
  --dh-dbutton-dots: color-mix(in oklab, var(--dh-dbutton-colour) 62%, #000);
  --dh-dbutton-from: 58%;
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  height: 2.6em;
  padding: 0 1em 0 1.15em;
  overflow: hidden;
  border: 0;
  border-radius: 0.65em;
  background: var(--dh-dbutton-colour);
  box-shadow:
    inset 0 0 0 1px color-mix(in srgb, var(--dh-dbutton-dots) 55%, transparent),
    0 1px 2px rgb(0 0 0 / 0.2);
  color: var(--dh-on-accent, #fff);
  font: inherit;
  font-weight: 500;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition:
    --dh-dbutton-from 700ms cubic-bezier(0.23, 1, 0.32, 1),
    transform 150ms cubic-bezier(0.23, 1, 0.32, 1);
}

/* The dots: a darker shade of the colour, shown only through a grid of round holes that
   fades in from left to right. */
.dh-dbutton::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--dh-dbutton-dots);
  -webkit-mask-image: radial-gradient(circle, #000 0.085em, transparent 0.11em), linear-gradient(90deg, transparent var(--dh-dbutton-from), #000 calc(var(--dh-dbutton-from) + 55%));
  mask-image: radial-gradient(circle, #000 0.085em, transparent 0.11em), linear-gradient(90deg, transparent var(--dh-dbutton-from), #000 calc(var(--dh-dbutton-from) + 55%));
  -webkit-mask-size: 0.3em 0.3em, auto;
  mask-size: 0.3em 0.3em, auto;
  -webkit-mask-composite: source-in;
  mask-composite: intersect;
}

.dh-dbutton svg {
  transition: transform 350ms cubic-bezier(0.23, 1, 0.32, 1);
}

.dh-dbutton:active {
  transform: scale(0.97);
}

.dh-dbutton:focus-visible {
  outline: 2px solid var(--dh-faint, #8a8a8a);
  outline-offset: 2px;
}

@media (hover: hover) {
  .dh-dbutton:hover {
    --dh-dbutton-from: 8%;
  }
  .dh-dbutton:hover svg {
    transform: translateX(0.2em);
  }
}

/* The quiet one: a raised white button whose dots are your colour. */
.dh-dbutton[data-quiet] {
  --dh-dbutton-dots: color-mix(in srgb, var(--dh-dbutton-colour) 34%, transparent);
  background: var(--dh-raised, #fff);
  box-shadow:
    0 0 0 0.5px var(--dh-edge, #d6d6d2),
    0 1px 2px rgb(0 0 0 / 0.12);
  color: var(--dh-fg, #171717);
}

@media (prefers-reduced-motion: reduce) {
  .dh-dbutton,
  .dh-dbutton svg {
    transition: none;
  }
}

/* The preview's layout. */
.dh-dbutton-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75em;
}
