/* The username field of a made-up app's sign up, alone on white. The field is one element moved by GSAP (the sideways
   no); its ring, its edge and its colours live in CSS on classes. The counter digits roll in clipped columns, the
   rejected characters jump out of a layer laid over the input. A GSAP element never has a transform in the CSS. */
:root {
  --page: #ffffff;          /* the page */
  --ink: #17171c;           /* the typed name and the label */
  --muted: #8d8c96;         /* the @, the counter and the hint */
  --line: #e3e2e8;          /* the field's edge at rest */
  --line-hover: #c9c8d1;    /* the field's edge under the pointer */
  --field: #ffffff;         /* the field's body */
  --free: #12925c;          /* a free name: the check and the line */
  --taken: #e0453a;         /* a taken name: the edge, the cross and the line */
  --pill: #f6f6f8;          /* the suggestion pills */
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--page);
  color: var(--ink);
  font-family: "Mona Sans Variable", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

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

.stage {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.user {
  width: min(360px, calc(100vw - 32px));
  display: grid;
  gap: 0;
}

/* ---- label and counter ---- */
.user__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0 2px 9px;
}

.user__label {
  font-size: 13.5px;
  font-weight: 560;
  font-stretch: 104%;
  letter-spacing: 0.005em;
  color: var(--ink);
}

.count {
  display: inline-flex;
  align-items: baseline;
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  line-height: 16px;
  transition: color 0.3s;
}

.count.is-full { color: var(--taken); }

.count__digits { display: inline-flex; }

.roll {
  display: inline-block;
  height: 16px;
  overflow: hidden;
  width: 0.62em;
  -webkit-mask-image: linear-gradient(180deg, transparent, #000 22%, #000 78%, transparent);
  mask-image: linear-gradient(180deg, transparent, #000 22%, #000 78%, transparent);
}

.roll__col { display: block; }
.roll__col span { display: block; height: 16px; text-align: center; }

.count__max { color: #b4b3bc; }

/* ---- the field ---- */
.field {
  position: relative;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 14px 0 16px;
  border-radius: 14px;
  background: linear-gradient(180deg, #fbfbfc, var(--field) 40%);
  border: 1px solid var(--line);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.9) inset,
    0 1px 1px rgba(20, 20, 30, 0.035),
    0 2px 6px -2px rgba(20, 20, 30, 0.06);
  transition: border-color 0.08s, box-shadow 0.08s;
  cursor: text;
}

/* the soft ring of the focus, drawn outside the edge */
.field__ring {
  position: absolute;
  inset: -4px;
  border-radius: 18px;
  pointer-events: none;
  box-shadow: 0 0 0 3px rgba(23, 23, 28, 0.07);
  opacity: 0;
  transition: opacity 0.2s, box-shadow 0.08s;
}

@media (hover: hover) {
  .field:hover { border-color: var(--line-hover); }
  .pill:hover .pill__face { transform: translateY(-1px); border-color: #d6d5dd; box-shadow: 0 1px 0 #fff inset, 0 4px 10px -4px rgba(20, 20, 30, 0.16); }
}

/* the green and the red come in slowly and leave at once, as soon as the text changes */
.field.is-taken, .field.is-free { transition: border-color 0.35s, box-shadow 0.35s; }
.field.is-taken .field__ring, .field.is-free .field__ring { transition: opacity 0.3s, box-shadow 0.35s; }

.field.is-focus { border-color: #9f9ea8; }
.field.is-focus .field__ring { opacity: 1; }

.field.is-taken { border-color: var(--taken); }
.field.is-taken .field__ring { opacity: 1; box-shadow: 0 0 0 3px rgba(224, 69, 58, 0.1); }

.field.is-free { border-color: rgba(18, 146, 92, 0.55); }
.field.is-free .field__ring { box-shadow: 0 0 0 3px rgba(18, 146, 92, 0.09); }

.field__at {
  font-size: 16px;
  font-weight: 500;
  color: var(--muted);
  transform: translateY(-0.5px);
  transition: color 0.3s;
}

.field.has-text .field__at { color: var(--ink); }

.field__box {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: center;
}

.field__input {
  width: 100%;
  height: 100%;
  border: 0;
  outline: 0;
  background: none;
  font: inherit;
  font-size: 16px;
  font-weight: 500;
  font-stretch: 100%;
  letter-spacing: 0.002em;
  color: var(--ink);
  caret-color: var(--ink);
  padding: 0;
}

.field__input::placeholder { color: #c1c0c8; font-weight: 450; }

/* a copy of the text, invisible, to measure where the caret is */
.field__measure {
  position: absolute;
  left: 0;
  top: 0;
  visibility: hidden;
  white-space: pre;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.002em;
}

.bumps { position: absolute; inset: 0; pointer-events: none; }

.bump {
  position: absolute;
  top: 50%;
  margin-top: -10px;
  line-height: 20px;
  font-size: 16px;
  font-weight: 600;
  color: var(--taken);
  white-space: pre;
}

.bump__mark {
  position: absolute;
  left: 50%;
  bottom: -3px;
  width: 8px;
  height: 1.5px;
  margin-left: -4px;
  border-radius: 1px;
  background: var(--taken);
}

/* ---- the slot on the right: the arc, the check, the cross ---- */
.slot {
  position: relative;
  width: 22px;
  height: 22px;
  flex: none;
}

.slot svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  fill: none;
  visibility: hidden;
}

.slot__track { stroke: #ececf0; stroke-width: 1.6; }
.slot__arc { stroke: var(--ink); stroke-width: 1.6; stroke-linecap: round; }
.slot__okbg { fill: var(--free); }
.slot__ok path { stroke: #fff; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.slot__no path { stroke: var(--taken); stroke-width: 1.7; stroke-linecap: round; }

/* ---- the status line ---- */
.status {
  position: relative;
  height: 20px;
  margin-top: 10px;
  padding: 0 2px;
  overflow: hidden;
  font-size: 13px;
  font-weight: 450;
  line-height: 20px;
  color: var(--muted);
}

.status__line {
  position: absolute;
  left: 2px;
  right: 2px;
  top: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status__line.is-free { color: var(--free); font-weight: 520; }
.status__line.is-taken { color: var(--taken); font-weight: 500; }
.status__line b { font-weight: 620; }

/* ---- the suggestions ---- */
.sugg {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  height: 34px;
  margin-top: 12px;
  overflow: visible;
}

.pill {
  position: relative;
  height: 32px;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: 13px;
  font-weight: 520;
  color: var(--ink);
  cursor: pointer;
  visibility: hidden;
  border-radius: 999px;
}

/* the face: a child for the CSS, the button itself belongs to GSAP */
.pill__face {
  display: inline-flex;
  align-items: center;
  height: 100%;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, var(--pill));
  box-shadow: 0 1px 0 #fff inset, 0 1px 2px rgba(20, 20, 30, 0.05);
  transition: transform 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.3), border-color 0.25s, box-shadow 0.25s, background 0.25s;
}

.pill__face i { font-style: normal; color: var(--muted); margin-right: 1px; }

.pill:active .pill__face { transform: scale(0.96); transition-duration: 0.08s; }
.pill.is-picked .pill__face { border-color: var(--ink); background: #fff; }

.pill:focus-visible, .field__input:focus-visible { outline: none; }
.pill:focus-visible .pill__face { box-shadow: 0 0 0 3px rgba(23, 23, 28, 0.12); border-color: var(--ink); }

/* ---- the drawn pointer of the autopilot ---- */
.ghost {
  position: fixed;
  left: 0;
  top: 0;
  width: 22px;
  height: 22px;
  fill: #17171c;
  stroke: #fff;
  stroke-width: 1.4;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.22));
  pointer-events: none;
  visibility: hidden;
  z-index: 5;
}

@media (max-width: 380px) {
  .field { height: 52px; padding: 0 12px 0 14px; }
  .pill { font-size: 12.5px; }
  .pill__face { padding: 0 10px; }
  .sugg { gap: 6px; }
}
