/* The send button: a signup form whose button goes through its states. The paper plane flies off, the pill shrinks
   into a ring that spins while it sends, then a green tick (or a red cross and a shake) before it opens back into a
   pill. Every state is also said out loud in a status line. */
:root {
  --page: #ffffff;          /* the page */
  --ink: #0d2b2a;           /* text and the button */
  --ok: #1f9d6b;            /* sent */
  --no: #d64545;            /* failed */
  --ok-text: #137650;       /* the same two, dark enough for small text */
  --no-text: #b53333;
  --muted: rgba(13, 43, 42, 0.6);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'DM Sans Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 40px clamp(18px, 3.2vw, 48px);
}

.signup-box {
  width: min(520px, 100%);
}

/* ---------------------------------------------------------------- the form */
.signup {
  display: flex;
  gap: 10px;
}

.field {
  flex: 1;
  min-width: 0;
}

.field__input {
  width: 100%;
  height: 58px;
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  background: #fff;
  box-shadow: inset 0 0 0 1.5px rgba(13, 43, 42, 0.2);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  font-weight: 500;
  transition: box-shadow 0.25s ease;
}

.field__input::placeholder {
  color: rgba(13, 43, 42, 0.4);
}

.field__input:focus {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--ink);
}

.field__input[aria-invalid='true'] {
  box-shadow: inset 0 0 0 2px var(--no);
}

/* the slot keeps the width of the widest pill (the script measures it), so the field never moves while the
   button turns into a ring */
.send-slot {
  width: var(--slot, auto);
  display: grid;
  justify-items: center;
  align-items: center;
}

.send {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 58px;
  padding: 0 22px 0 26px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font: inherit;
  font-size: 16px;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: box-shadow 0.25s ease;
}

.send:focus-visible {
  outline: 2.5px solid var(--ok);
  outline-offset: 4px;
}

.send[aria-disabled='true'] {
  cursor: progress;
}

@media (hover: hover) and (pointer: fine) {
  .send:not([aria-disabled='true']):hover {
    box-shadow: 0 14px 26px -14px rgba(13, 43, 42, 0.7);
  }
}

/* the ring that leaves the button when the letter has gone */
.send__halo {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: 0 0 0 2px var(--ok);
  opacity: 0;
  pointer-events: none;
}

.send__label {
  display: inline-block;
}

.send__plane {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* the ring, the tick and the cross live in one drawing over the middle of the button */
.send__state {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.send__track {
  stroke: rgba(255, 255, 255, 0.22);
  stroke-width: 3.4;
}

.send__arc {
  stroke: #fff;
  stroke-width: 3.4;
  stroke-dasharray: 107;
  stroke-dashoffset: 76;
}

.send__tick,
.send__cross {
  stroke: #fff;
  stroke-width: 4;
  opacity: 0;
}

.status {
  min-height: 1.5em;
  margin: 14px 0 0 6px;
  font-size: 14px;
  color: var(--muted);
  transition: color 0.25s ease;
}

.status.is-ok {
  color: var(--ok-text);
}

.status.is-no {
  color: var(--no-text);
}

/* the switch for the demo: the next send fails */
.fail {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 12px 0;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;   /* on a phone the tap answers at once, without waiting for a double tap */
}

.fail input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.fail__box {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 5px;
  box-shadow: inset 0 0 0 1.5px rgba(13, 43, 42, 0.35);
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.fail__box svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.2s ease, transform 0.3s cubic-bezier(0.34, 1.6, 0.5, 1);
}

.fail input:checked + .fail__box {
  background: var(--no);
  box-shadow: none;
}

.fail input:checked + .fail__box svg {
  opacity: 1;
  transform: none;
}

.fail input:focus-visible + .fail__box {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

@media (max-width: 560px) {
  .signup {
    flex-direction: column;
  }

  .send-slot,
  .send {
    width: 100%;
  }
}
