:root {
  --fondo: #f2f2f2;
  --campo: #ffffff;
  --testo: #111113;
  --testo-2: #85858c;
  --testo-3: #b4b4ba;
  --bordo: rgba(17, 17, 19, 0.08);
  --bordo-forte: rgba(17, 17, 19, 0.16);
  --anello: rgba(17, 17, 19, 0.1);
  --verde: #1f9d55;
  --rosso: #e5484d;
  --tasto: #111113;
}

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

html, body { height: 100%; }

body {
  background: var(--fondo);
  color: var(--testo);
  font-family: "Mona Sans Variable", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

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

.phone {
  width: min(340px, 100%);
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.8vh, 10px);
}

.phone__label {
  font-size: 13px;
  font-weight: 560;
  letter-spacing: -0.005em;
  color: var(--testo);
  padding-left: 2px;
}

/* the field: a white pill with a hairline border; the ring grows on focus, turns red on error, green when valid */
.field {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  height: 52px;
  background: var(--campo);
  border-radius: 14px;
  box-shadow: 0 0 0 1px var(--bordo), 0 1px 2px rgba(17, 17, 19, 0.04), 0 8px 24px -12px rgba(17, 17, 19, 0.12);
  transition: box-shadow 0.25s cubic-bezier(0.2, 0, 0, 1);
}

.field.is-focus {
  box-shadow: 0 0 0 1px var(--bordo-forte), 0 0 0 4px var(--anello), 0 8px 24px -12px rgba(17, 17, 19, 0.16);
}

.field.is-error {
  box-shadow: 0 0 0 1px rgba(229, 72, 77, 0.55), 0 0 0 4px rgba(229, 72, 77, 0.12), 0 8px 24px -12px rgba(229, 72, 77, 0.2);
}

.field.is-valid {
  box-shadow: 0 0 0 1px rgba(31, 157, 85, 0.45), 0 0 0 4px rgba(31, 157, 85, 0.1), 0 8px 24px -12px rgba(31, 157, 85, 0.18);
}

.country { position: relative; height: 100%; }

.country__btn {
  height: 100%;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px 0 12px;
  border: 0;
  background: none;
  font: inherit;
  color: var(--testo);
  cursor: pointer;
  border-radius: 14px 0 0 14px;
}

.country__btn:focus-visible { outline: 2px solid var(--testo); outline-offset: -4px; }

.country__iso {
  display: inline-grid;
  place-items: center;
  height: 20px;
  min-width: 26px;
  padding: 0 5px;
  border-radius: 6px;
  background: #f1f1f3;
  box-shadow: inset 0 0 0 1px var(--bordo);
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.04em;
  color: #55555c;
}

.country__code {
  position: relative;
  display: inline-block;
  overflow: hidden;
  height: 20px;
  line-height: 20px;
  font-size: 15px;
  font-weight: 520;
  font-variant-numeric: tabular-nums;
}

.country__roll { display: block; white-space: nowrap; }

.country__chev {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: var(--testo-2);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.3s cubic-bezier(0.2, 0, 0, 1);
}

.country__btn[aria-expanded="true"] .country__chev { transform: rotate(180deg); }

@media (hover: hover) {
  .country__btn:hover .country__iso { background: #e9e9ec; }
}

/* the menu of codes: a small card that springs open under the chip, with a grey bar sliding to the row under the pointer */
.menu {
  position: absolute;
  z-index: 5;
  top: calc(100% + 6px);
  left: 0;
  width: 212px;
  padding: 5px;
  list-style: none;
  background: var(--campo);
  border-radius: 14px;
  box-shadow: 0 0 0 1px var(--bordo), 0 12px 32px -8px rgba(17, 17, 19, 0.2), 0 2px 6px rgba(17, 17, 19, 0.05);
  visibility: hidden;
  opacity: 0;
  transform-origin: 24px 0;
}

.menu__bar {
  position: absolute;
  left: 5px;
  right: 5px;
  top: 5px;
  height: 34px;
  border-radius: 9px;
  background: #f2f2f4;
  pointer-events: none;
}

.menu__row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 34px;
  padding: 0 10px;
  border-radius: 9px;
  font-size: 13.5px;
  cursor: pointer;
  user-select: none;
}

.menu__row .country__iso { height: 18px; min-width: 24px; font-size: 10px; }

.menu__name { flex: 1; color: var(--testo); }

.menu__code { color: var(--testo-2); font-variant-numeric: tabular-nums; }

.menu__row[aria-selected="true"] .menu__name { font-weight: 600; }

.field__rule {
  width: 1px;
  height: 22px;
  background: var(--bordo-forte);
}

/* the digits: a real input underneath (transparent) and the drawn digits on top, so each one can spring in */
.digits {
  position: relative;
  flex: 1;
  height: 100%;
  min-width: 0;
}

.digits__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: transparent;
  caret-color: transparent;
  font: inherit;
  font-size: 16px;
  outline: none;
}

.digits__input::selection { background: transparent; }

.digits__show {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  padding: 0 12px;
  pointer-events: none;
  font-size: 16px;
  font-weight: 520;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  white-space: pre;
  overflow: hidden;
}

.ch { display: inline-block; will-change: transform; }

.ch--sep { color: var(--testo-2); }

.digits__ph {
  position: absolute;
  left: 12px;
  color: var(--testo-3);
  font-weight: 450;
}

/* the caret: a thin line that blinks while the field has focus */
.caret {
  display: inline-block;
  width: 1.5px;
  height: 19px;
  margin-left: 1px;
  border-radius: 1px;
  background: var(--testo);
  opacity: 0;
}

.field.is-focus .caret { animation: blink 1.06s steps(1) infinite; }

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

.ok {
  width: 20px;
  height: 20px;
  margin-right: 14px;
  flex: none;
  opacity: 0;
  transform: scale(0.6);
}

.ok svg { width: 100%; height: 100%; display: block; }

.ok circle { fill: var(--verde); }

.ok path {
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}

.hint {
  min-height: 18px;
  padding-left: 2px;
  font-size: 12.5px;
  color: var(--testo-2);
  transition: color 0.25s ease;
}

.hint span { display: inline-block; }

.hint.is-error { color: var(--rosso); }

.hint.is-valid { color: var(--verde); }

/* Send code: grey and flat while the number is incomplete, black and lifted when it can go */
.send {
  position: relative;
  height: 46px;
  margin-top: 4px;
  border: 0;
  border-radius: 12px;
  background: #e4e4e7;
  color: #a1a1a8;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.005em;
  cursor: not-allowed;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(17, 17, 19, 0.04);
  transition: background 0.3s cubic-bezier(0.2, 0, 0, 1), color 0.3s cubic-bezier(0.2, 0, 0, 1), box-shadow 0.3s ease;
}

.send.is-ready {
  background: var(--tasto);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.12) inset, 0 6px 16px -6px rgba(17, 17, 19, 0.45), 0 1px 2px rgba(17, 17, 19, 0.2);
}

@media (hover: hover) {
  .send.is-ready:hover { background: #26262a; }
}

.send:focus-visible { outline: 2px solid var(--testo); outline-offset: 3px; }

.send__label { display: inline-block; }

.send__spin, .send__done {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  fill: none;
  stroke: #fff;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
}

.send__spin { stroke-width: 2; stroke-dasharray: 30 44; }

.send__done { stroke-width: 2.2; stroke-dasharray: 1; stroke-dashoffset: 1; }

/* the fake pointer of the autopilot */
.ghost {
  position: absolute;
  left: 0;
  top: 0;
  width: 22px;
  height: 22px;
  z-index: 10;
  pointer-events: none;
  opacity: 0;
  fill: #111113;
  stroke: #fff;
  stroke-width: 1.4;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.25));
}

@media (max-height: 300px) {
  .send { height: 40px; }
  .field { height: 46px; }
}
