/* The email field: a graphite field on a black page with an off-white Subscribe button inside it, a line of help
   under it, and the copy editor's pencils: blue for a likely typo, red for what is missing. */
:root {
  --page: #000000;          /* the page */
  --field: #111113;         /* the field */
  --field-on: #16161a;      /* the field while typing in it */
  --line: #2a2a30;          /* the edge of the field */
  --line-on: #8e8d97;       /* the edge while typing */
  --ink: #f2f1ee;           /* the letters */
  --soft: #c9c8c4;          /* the label */
  --muted: #85848d;         /* the help under the field */
  --ghost: #5b5a63;         /* the rest of a provider, in grey after the caret */
  --pencil: #8da2ff;        /* the blue pencil: a likely typo */
  --wrong: #ff6a5e;         /* the red pencil: something missing or wrong */
  --right: #4fd8a0;         /* right, and subscribed */
  --send: #f2f1ee;          /* the button */
  --send-ink: #000000;      /* the button's word */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

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

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

.stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 40px 16px;
}

.mail {
  --send-w: 118px;
  width: min(440px, 100%);
  margin: 0;
}

.mail__label {
  display: block;
  margin: 0 0 10px 4px;
  font-size: 14px;
  font-weight: 560;
  color: var(--soft);
}

/* ---------------------------------------------------------------- the field */
.mail__field {
  position: relative;
  height: 60px;
  border-radius: 18px;
  background: linear-gradient(180deg, var(--field-on), var(--field) 70%);
  background-color: var(--field);
  box-shadow: inset 0 0 0 1px var(--line), inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 0 0 0 rgba(255, 255, 255, 0);
  transition: box-shadow 0.25s ease;
}

.mail__field.is-on,
.mail__field.is-pretend {
  box-shadow: inset 0 0 0 1px var(--line-on), inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 0 0 4px rgba(255, 255, 255, 0.08);
}

.mail__field.is-wrong {
  box-shadow: inset 0 0 0 1px var(--wrong), inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 0 0 4px rgba(255, 106, 94, 0.18);
  box-shadow: inset 0 0 0 1px var(--wrong), inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 0 0 4px color-mix(in srgb, var(--wrong) 20%, transparent);
}

/* the real input: over the whole field, with room on the right for the tick and the button */
.mail__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0 calc(var(--send-w) + 34px) 0 18px;
  border: 0;
  border-radius: inherit;
  outline: none;
  background: transparent;
  color: var(--ink);
  caret-color: var(--ink);
  font: 450 18px/normal 'Archivo Variable', system-ui, sans-serif;
  font-kerning: normal;
  font-variant-ligatures: none;
  letter-spacing: 0;
  -webkit-tap-highlight-color: transparent;
}

.mail__input::placeholder {
  color: var(--ghost);
  opacity: 1;
}

/* the browser's autofill paints the field light blue: back to the field's own colours */
.mail__input:-webkit-autofill {
  -webkit-text-fill-color: var(--ink);
  -webkit-box-shadow: 0 0 0 60px var(--field) inset;
  caret-color: var(--ink);
}

/* while the drawn letters move, the input's own letters, caret and placeholder are invisible */
.mail__field.is-taken .mail__input,
.mail__field.is-taken .mail__input::placeholder {
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: transparent;
}

/* subscribed: the address rests, dimmed */
.mail__field.is-done .mail__input {
  color: var(--muted);
  transition: color 0.4s ease;
}

/* ---------------------------------------------------------------- what is drawn over the input */
/* exactly over the input's text box, so the drawn letters are cut where the input cuts its own */
.mail__ink {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 18px;
  right: calc(var(--send-w) + 34px);
  overflow: hidden;
  pointer-events: none;
  font: 450 18px/normal 'Archivo Variable', system-ui, sans-serif;
  font-kerning: normal;
  font-variant-ligatures: none;
}

/* the row moves with the input's scroll */
.mail__row {
  position: absolute;
  inset: 0;
}

/* a letter, while the letters move */
.ch {
  position: absolute;
  left: 0;
  top: 50%;
  color: var(--ink);
  white-space: pre;
  line-height: normal;
  will-change: transform;
}

/* the rest of a provider, in grey after the caret, with a key to take it */
.mail__ghost {
  position: absolute;
  left: 0;
  top: 50%;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 26px;
  color: var(--ghost);
  white-space: pre;
  opacity: 0;
  cursor: pointer;
}

.mail__ghost.is-on {
  pointer-events: auto;
}

.ghost__clip {
  position: relative;
  display: grid;
  height: 26px;
  line-height: 26px;
  /* cut above and below, for the roll, but not on the right, where the old ending may still be longer */
  clip-path: inset(0 -400px 0 0);
}

.ghost__text {
  grid-area: 1 / 1;
}

.ghost__text.is-going {
  position: absolute;
  left: 0;
  top: 0;
}

.ghost__key {
  display: none;
  height: 20px;
  padding: 0 6px;
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px #34343b, inset 0 -2px 0 #26262b;
  color: #75747d;
  font-size: 11px;
  font-weight: 560;
  line-height: 19px;
  letter-spacing: 0.02em;
}

@media (hover: hover) and (pointer: fine) {
  .ghost__key {
    display: block;
  }
}

/* the caret of the library's preview, which types without taking the focus */
.mail__caret {
  position: absolute;
  left: -1px;
  top: 50%;
  width: 2px;
  height: 22px;
  border-radius: 1px;
  background: var(--ink);
  opacity: 0;
}

.mail__caret.is-on {
  animation: blink 1.06s steps(1) infinite;
}

@keyframes blink {
  0%,
  50% {
    opacity: 1;
  }

  50.01%,
  100% {
    opacity: 0;
  }
}

/* the pencil marks: a wavy line under a word, a wedge where something is missing */
.mail__marks {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 100%;
  overflow: visible;
}

.mail__marks path {
  fill: none;
  stroke: var(--pencil);
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mail__marks.is-wrong path {
  stroke: var(--wrong);
}

.mail__wedge {
  opacity: 0;
  stroke-width: 2;
}

/* the tick after a right address */
.mail__tick {
  position: absolute;
  left: 0;
  top: 50%;
  width: 20px;
  height: 20px;
  margin-top: -10px;
  overflow: visible;
  pointer-events: none;
}

.mail__tick path {
  fill: none;
  stroke: var(--right);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
}

/* ---------------------------------------------------------------- the button */
.send {
  position: absolute;
  top: 6px;
  right: 6px;
  bottom: 6px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  width: var(--send-w);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--send-ink);
  font: 620 15px/1 'Archivo Variable', system-ui, sans-serif;
  cursor: pointer;
  isolation: isolate;
  -webkit-tap-highlight-color: transparent;
}

.send > * {
  grid-area: 1 / 1;
}

/* the colour is a layer of its own: it swells under the pointer while the word widens, so nothing round it moves */
.send__bg {
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: var(--send);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.14), 0 1px 0 rgba(255, 255, 255, 0.08);
  transition: inset 0.6s cubic-bezier(0.3, 1.7, 0.45, 1), transform 0.16s ease-out;
}

.send__label {
  display: block;
  font-stretch: 100%;
  white-space: nowrap;
  transition: font-stretch 0.6s cubic-bezier(0.3, 1.7, 0.45, 1);
}

@media (hover: hover) and (pointer: fine) {
  .send:not([aria-disabled='true']):hover .send__bg {
    inset: -2px -3px;
  }

  .send:not([aria-disabled='true']):hover .send__label {
    font-stretch: 114%;
  }
}

.send:not([aria-disabled='true']):active .send__bg {
  transform: scale(0.96);
}

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

/* the focus ring in the blue pencil, clear of the colour that swells */
.send:focus-visible {
  outline: 2px solid var(--pencil);
  outline-offset: 3px;
}

.send__spin,
.send__done {
  width: 24px;
  height: 24px;
  overflow: visible;
  opacity: 0;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.send__spin {
  stroke-width: 2.4;
  stroke-dasharray: 34 60;
}

.send__done {
  stroke-width: 2.6;
}

/* ---------------------------------------------------------------- the line under the field */
.mail__note {
  position: relative;
  min-height: 20px;
  margin: 12px 4px 0;
  font-size: 14px;
  line-height: 20px;
  color: var(--muted);
}

.note__line {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.note__line.is-going {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  pointer-events: none;
}

.note__line svg {
  flex: none;
  width: 16px;
  height: 16px;
  margin-top: 2px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.note__line.is-pencil {
  color: var(--soft);
}

.note__line.is-pencil svg {
  color: var(--pencil);
}

.note__line.is-wrong {
  color: var(--wrong);
}

.note__line.is-right,
.note__line.is-done {
  color: var(--soft);
}

.note__line.is-right svg,
.note__line.is-done svg {
  color: var(--right);
}

.note__tail {
  white-space: nowrap;
}

/* the suggestion is a button: the letters it would change are in the blue pencil */
.note__fix {
  display: inline;
  margin: -2px -2px;
  padding: 2px 5px;
  border: 0;
  border-radius: 7px;
  background: rgba(141, 162, 255, 0.1);
  background: color-mix(in srgb, var(--pencil) 11%, transparent);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.note__fix b {
  color: var(--pencil);
  font-weight: 700;
}

@media (hover: hover) and (pointer: fine) {
  .note__fix:hover {
    background: color-mix(in srgb, var(--pencil) 22%, transparent);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--pencil) 45%, transparent);
  }
}

.note__fix:focus-visible {
  outline: 2px solid var(--pencil);
  outline-offset: 2px;
}

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

@media (max-width: 440px) {
  .mail {
    --send-w: 108px;
  }

  .mail__input {
    padding-right: calc(var(--send-w) + 32px);
  }

  .mail__ink {
    right: calc(var(--send-w) + 32px);
  }
}
