:root {
  --fondo: #ffffff;
  --inchiostro: #101114;
  --grigio: #6b6d76;
  --grigio-chiaro: #a3a5ad;
  --bordo: rgba(16, 17, 20, 0.11);
  --bordo-forte: rgba(16, 17, 20, 0.2);
  --campo: #fbfbfc;
  --pillola: #f1f2f5;
  --tondo: #eceef2;
  --accento: #3f4fe8;
  --accento-tinta: rgba(63, 79, 232, 0.12);
  --alone: rgba(63, 79, 232, 0.13);
  --field: clamp(50px, 13vh, 58px);
  --search: clamp(38px, 10vh, 44px);
  --row: clamp(32px, 8.4vh, 40px);
  --rows: 4.5;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--fondo);
  color: var(--inchiostro);
  font-family: "Mona Sans Variable", "Mona Sans", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input { font: inherit; color: inherit; }

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

/* the wrap reserves the room of the open list, so the list never leaves the frame */
.wrap {
  position: relative;
  width: min(360px, 100%);
  min-height: calc(30px + var(--field) + var(--search) + var(--row) * var(--rows) + 22px);
}

.head {
  display: flex; align-items: center; gap: 9px;
  height: 18px; margin-bottom: 12px;
  font-size: 12px; letter-spacing: 0.01em; color: var(--grigio);
}
.head__brand { font-weight: 720; color: var(--inchiostro); font-stretch: 112%; letter-spacing: 0.04em; text-transform: uppercase; font-size: 11px; }
.head__sep { width: 1px; height: 11px; background: var(--bordo-forte); }
.head__title { font-weight: 520; }

.slot { position: relative; height: var(--field); z-index: 3; }

/* the field and the list are one box: its border is the field's border closed and the list's border open */
.box {
  position: absolute; left: 0; right: 0; top: 0;
  border-radius: 14px;
  background: var(--campo);
  border: 1px solid var(--bordo);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.9) inset, 0 1px 2px rgba(16, 17, 20, 0.04);
  overflow: hidden;
  transition: border-color 0.25s, box-shadow 0.35s, background-color 0.25s;
}
.box.is-open {
  background: #ffffff;
  border-color: var(--bordo-forte);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.9) inset, 0 1px 2px rgba(16, 17, 20, 0.05),
    0 10px 24px -10px rgba(16, 17, 20, 0.16), 0 28px 56px -24px rgba(16, 17, 20, 0.2);
}
.box.is-focus { border-color: var(--accento); box-shadow: 0 0 0 4px var(--alone), 0 1px 2px rgba(16, 17, 20, 0.05); }
.box.is-open.is-focus { border-color: var(--bordo-forte); }

.field {
  position: relative; display: block; width: 100%;
  height: calc(var(--field) - 2px);
  padding: 0 44px 0 14px;
  text-align: left; background: none; border: 0; cursor: pointer;
  outline: none;
}
.field__label {
  position: absolute; left: 14px; top: calc(var(--field) * 0.17);
  font-size: 11px; font-weight: 560; color: var(--grigio); letter-spacing: 0.01em;
}
.field__val {
  position: absolute; left: 14px; right: 44px; bottom: calc(var(--field) * 0.14);
  height: 22px; overflow: hidden;
}
.val {
  position: absolute; left: 0; top: 0; height: 22px;
  display: flex; align-items: center; gap: 8px; white-space: nowrap;
  font-size: 14.5px; font-weight: 580; letter-spacing: -0.005em;
}
.field__chev {
  position: absolute; right: 14px; top: 50%; width: 18px; height: 18px; margin-top: -9px;
  fill: none; stroke: var(--grigio); stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
}

/* the country codes in small rounds of text, never flags */
.code {
  flex: none; display: inline-grid; place-items: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--tondo);
  box-shadow: 0 0 0 1px rgba(16, 17, 20, 0.06) inset, 0 1px 0 rgba(255, 255, 255, 0.8);
  font-size: 8.5px; font-weight: 720; letter-spacing: 0.04em; font-stretch: 108%;
  color: #44464e;
}
.val .code { background: var(--inchiostro); color: #ffffff; box-shadow: 0 1px 2px rgba(16, 17, 20, 0.2); }

.body { position: relative; padding: 0 6px 6px; }
.body__rule { position: absolute; left: 12px; right: 12px; top: 0; height: 1px; background: var(--bordo); transform-origin: 50% 50%; }

.search {
  position: relative; display: flex; align-items: center; gap: 8px;
  height: var(--search); padding: 0 8px;
}
.search__ic { flex: none; width: 16px; height: 16px; fill: none; stroke: var(--grigio-chiaro); stroke-width: 2; stroke-linecap: round; transition: stroke 0.2s; }
.search:focus-within .search__ic { stroke: var(--accento); }
.search__in {
  flex: 1; min-width: 0; height: 100%;
  border: 0; outline: none; background: none;
  font-size: 13.5px; font-weight: 500;
  caret-color: var(--accento);
}
.search__in::placeholder { color: var(--grigio-chiaro); }
.search__clear {
  flex: none; width: 22px; height: 22px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; background: var(--pillola);
  opacity: 0; visibility: hidden;
}
.search__clear svg { width: 12px; height: 12px; fill: none; stroke: var(--grigio); stroke-width: 2.4; stroke-linecap: round; }

.list {
  position: relative;
  max-height: calc(var(--row) * var(--rows));
  overflow-y: auto; overscroll-behavior: contain;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(transparent 0, #000 10px, #000 calc(100% - 14px), transparent);
  mask-image: linear-gradient(transparent 0, #000 10px, #000 calc(100% - 14px), transparent);
}
.list::-webkit-scrollbar { display: none; }
.list__ul { position: relative; list-style: none; }

/* the pill that follows the active option */
.hl {
  position: absolute; left: 0; right: 0; top: 0; height: var(--row);
  border-radius: 10px;
  background: var(--pillola);
  box-shadow: 0 0 0 1px rgba(16, 17, 20, 0.04) inset, 0 1px 0 rgba(255, 255, 255, 0.9) inset;
  opacity: 0; pointer-events: none;
}

.opt { position: relative; height: var(--row); overflow: hidden; cursor: pointer; }
.opt[hidden] { display: none; }
.opt__in {
  position: absolute; left: 0; right: 0; top: 0; height: var(--row);
  display: flex; align-items: center; gap: 10px; padding: 0 10px;
  font-size: 13.5px; font-weight: 480; white-space: nowrap;
}
.opt__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; transition: font-variation-settings 0.25s; }
.opt__name mark {
  color: var(--accento); background: var(--accento-tinta);
  border-radius: 3px; padding: 0 1px; margin: 0 -1px;
  font-weight: 680;
}
.opt__dial { flex: none; font-size: 12px; color: var(--grigio-chiaro); font-variant-numeric: tabular-nums; font-weight: 520; }
.opt__check { flex: none; width: 15px; height: 15px; fill: none; stroke: var(--accento); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.opt[aria-selected="true"] .opt__check { opacity: 1; }
.opt[aria-selected="true"] .opt__name { font-weight: 640; }
.opt.is-active .opt__dial { color: var(--grigio); }

.empty {
  height: var(--row); display: none; align-items: center; padding: 0 12px;
  font-size: 13px; color: var(--grigio-chiaro);
}
.empty.is-on { display: flex; }

/* the phone field below: its code rolls with the country */
.phone {
  position: relative; margin-top: 10px; height: var(--field);
  border-radius: 14px; background: var(--campo); border: 1px solid var(--bordo);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.9) inset, 0 1px 2px rgba(16, 17, 20, 0.04);
  transition: border-color 0.25s, box-shadow 0.25s;
}
.phone:focus-within { border-color: var(--accento); box-shadow: 0 0 0 4px var(--alone); background: #fff; }
.phone__label { position: absolute; left: 14px; top: calc(var(--field) * 0.17); font-size: 11px; font-weight: 560; color: var(--grigio); }
.phone__row { position: absolute; left: 14px; right: 14px; bottom: calc(var(--field) * 0.14); height: 22px; display: flex; align-items: center; gap: 10px; }
.dial {
  position: relative; flex: none; height: 22px; overflow: hidden;
  font-size: 14.5px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.dial__line { position: absolute; left: 0; top: 0; display: flex; height: 22px; line-height: 22px; white-space: nowrap; }
.dial__ch { display: inline-block; }
.phone__rule { flex: none; width: 1px; height: 14px; background: var(--bordo-forte); }
.phone__in {
  flex: 1; min-width: 0; height: 22px; border: 0; outline: none; background: none;
  font-size: 14.5px; font-weight: 500;
}
.phone__in::placeholder { color: var(--grigio-chiaro); font-weight: 450; }

/* the key the autopilot presses, shown under the form */
.key {
  position: absolute; right: 0; top: -3px;
  display: flex; align-items: center; gap: 6px;
  height: 23px; min-width: 26px; justify-content: center; padding: 0 7px; border-radius: 7px;
  background: #ffffff; border: 1px solid var(--bordo-forte);
  box-shadow: 0 2px 0 rgba(16, 17, 20, 0.08), 0 4px 10px -4px rgba(16, 17, 20, 0.18);
  font-size: 11px; font-weight: 620; color: #3a3c44;
  opacity: 0; visibility: hidden;
}
.key__arrow { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.ghost {
  position: fixed; left: 0; top: 0; width: 22px; height: 22px; z-index: 10;
  pointer-events: none;
  fill: #111216; stroke: #ffffff; stroke-width: 1.4; stroke-linejoin: round;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
  opacity: 0; visibility: hidden;
}

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (hover: hover) {
  .box:not(.is-open):hover { border-color: var(--bordo-forte); background: #ffffff; }
  .box:not(.is-open):hover .field__chev { stroke: var(--inchiostro); }
  .search__clear:hover { background: #e6e7eb; }
}
.field:focus-visible { outline: none; }
.box:has(.field:focus-visible):not(.is-open) { border-color: var(--accento); box-shadow: 0 0 0 4px var(--alone); }

@media (max-width: 380px) {
  .opt__dial { font-size: 11.5px; }
}
