:root {
  /* the page: pure white; the ink is warm, like a cotton label */
  --carta: #ffffff;
  --inchiostro: #1d1814;
  --tenue: #8b8176;
  --linea: rgba(29, 24, 20, 0.13);
  --pieno: #1d1814;
  --fuoco: #b8343a;
  --e-elastico: cubic-bezier(0.34, 1.8, 0.64, 1);
  --e-uscita: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: var(--carta);
  color: var(--inchiostro);
  font-family: 'Bricolage Grotesque Variable', system-ui, sans-serif;
  font-stretch: 100%;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

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

.studio {
  --testo: var(--inchiostro);
  --sbiadito: var(--tenue);
  --filo-ui: var(--linea);
  --fondo-pieno: var(--pieno);
  --sfondo: var(--carta);
  width: min(680px, 100%);
  display: grid;
  gap: 18px;
}

/* ------------------------------------------------------------------ the stage */
.palco {
  display: grid;
  gap: 6px;
}
.tavola {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1 / 0.92;
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  outline: none;
}
.tavola:focus-visible {
  box-shadow: 0 0 0 2px var(--sfondo), 0 0 0 4px var(--testo);
}
.tela {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.cenno {
  margin: 0;
  height: 22px;
  overflow: hidden;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 500;
  font-stretch: 92%;
  letter-spacing: 0.005em;
  color: var(--sbiadito);
}
.cenno__testo {
  display: inline-block;
}

/* ------------------------------------------------------------------ controls */
.comandi {
  width: min(520px, 100%);
  justify-self: center;
  display: grid;
  gap: 12px;
}
.riga {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.riga--azioni {
  justify-content: center;
  gap: 10px;
}
/* with the zip button (only inside the site): the animation on a row of its own, the other two share the row
   below; when they no longer fit side by side, each takes a whole row */
.riga--zip > .pillola {
  flex: 1 1 0;
}
.riga--zip > [data-scarica-animazione] {
  flex-basis: 100%;
}

/* the cloth: three radios on one track, the cursor slides under the chosen one */
.stoffe {
  position: relative;
  display: flex;
  padding: 4px;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px var(--filo-ui);
}
.stoffe__cursore {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 0;
  width: 60px;
  border-radius: 999px;
  background: var(--fondo-pieno);
  pointer-events: none;
}
.stoffa {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 13px 0 9px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--testo);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  font-stretch: 88%;
  cursor: pointer;
  transition: font-stretch 0.5s var(--e-elastico), color 0.2s ease;
}
/* a scrap of Aida: the cloth colour with its little holes */
.stoffa__campione {
  width: 16px;
  height: 16px;
  flex: none;
  border-radius: 4px;
  background-color: var(--t);
  background-image: radial-gradient(circle, rgba(70, 52, 30, 0.42) 0 0.7px, transparent 1.1px);
  background-size: 4px 4px;
  background-position: -2px -2px;
  box-shadow: inset 0 0 0 1px rgba(70, 52, 30, 0.16);
  transition: transform 0.5s var(--e-elastico);
}
.stoffa[aria-checked='true'] {
  color: var(--sfondo);
}
.stoffa[aria-checked='true'] .stoffa__campione {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
  transform: rotate(-8deg);
}
.stoffa:focus-visible,
.filo:focus-visible,
.pillola:focus-visible {
  outline: 2px solid var(--testo);
  outline-offset: 3px;
}
@media (hover: hover) and (pointer: fine) {
  .stoffa:not([aria-checked='true']):hover {
    font-stretch: 100%;
  }
  .stoffa:not([aria-checked='true']):hover .stoffa__campione {
    transform: rotate(8deg) scale(1.08);
  }
}

/* the thread: little skeins, two plies twisted */
.fili {
  display: flex;
  gap: 8px;
}
.filo {
  position: relative;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 46%),
    repeating-linear-gradient(-58deg, var(--a) 0 2.6px, var(--b) 2.6px 4.4px);
  box-shadow: inset 0 -2px 4px rgba(0, 0, 0, 0.22);
  cursor: pointer;
  transition: transform 0.5s var(--e-elastico);
}
.filo::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1.5px var(--testo);
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.2s ease, transform 0.5s var(--e-elastico);
}
.filo[aria-checked='true']::after {
  opacity: 1;
  transform: none;
}
@media (hover: hover) and (pointer: fine) {
  .filo:hover {
    transform: translateY(-2px) rotate(-24deg);
  }
}
.filo:active {
  transform: scale(0.9);
}

/* the address */
.indirizzo {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 56px;
  padding: 4px 4px 4px 14px;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px var(--filo-ui);
}
.indirizzo:focus-within {
  box-shadow: inset 0 0 0 1.5px var(--testo);
}
.indirizzo__segno {
  width: 18px;
  height: 18px;
  flex: none;
  color: var(--sbiadito);
}
.indirizzo__campo {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: var(--testo);
  font: inherit;
  font-size: 1rem;
  font-weight: 450;
  font-stretch: 94%;
  outline: none;
}
.indirizzo__campo::selection {
  background: color-mix(in srgb, var(--fuoco) 26%, transparent);
}

/* the elastic pill: the fill swells with a bounce, the label widens on the wdth axis */
.pillola {
  --pb: var(--fondo-pieno);
  --pt: var(--sfondo);
  --pbordo: 0 0 0 transparent;
  --gonfia: 6px;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 48px;
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--pt);
  font: inherit;
  font-size: 0.96rem;
  font-weight: 640;
  font-stretch: 84%;
  letter-spacing: -0.005em;
  white-space: nowrap;
  cursor: pointer;
  isolation: isolate;
  flex: none;
}
.pillola::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: var(--pb);
  box-shadow: var(--pbordo);
  transition: inset 0.6s var(--e-elastico), transform 0.25s var(--e-uscita);
}
.pillola__testo {
  display: inline-grid;
  text-align: center;
  transition: font-stretch 0.6s var(--e-elastico);
}
/* the label at its widest, invisible: it keeps the room */
.pillola__testo::before {
  content: attr(data-testo);
  grid-area: 1 / 1;
  height: 0;
  overflow: hidden;
  visibility: hidden;
  font-stretch: 100%;
}
.pillola__segno {
  width: 18px;
  height: 18px;
  flex: none;
  transition: transform 0.6s var(--e-elastico);
}
.pillola--vuota {
  --pb: transparent;
  --pt: var(--testo);
  --pbordo: inset 0 0 0 1px var(--filo-ui);
}
/* dentro al campo la pillola si gonfia solo un poco, senza uscire dal bordo */
.indirizzo .pillola {
  --gonfia: 1px;
}
@media (hover: hover) and (pointer: fine) {
  .pillola:hover::before {
    inset: -2px calc(var(--gonfia) * -1);
  }
  .pillola:hover .pillola__testo {
    font-stretch: 100%;
  }
  .pillola:hover .pillola__segno {
    transform: translateY(2px);
  }
  .pillola:hover .pillola__segno--ago {
    transform: translate(2px, -2px) rotate(-8deg);
  }
  .pillola--vuota:hover {
    --pbordo: inset 0 0 0 1.5px var(--testo);
  }
}
.pillola:active::before {
  transform: scale(1.03, 0.88);
}
/* the display of the pill would beat the hidden attribute: outside the site the zip button is not there */
.pillola[hidden] {
  display: none;
}
/* while the zip is being packed the arrow keeps dropping into the box */
.pillola[aria-busy='true'] {
  cursor: progress;
}
.pillola[aria-busy='true'] .pillola__segno path:last-child {
  animation: cala 0.9s var(--e-uscita) infinite;
}
@keyframes cala {
  0% { transform: translateY(-3px); opacity: 0; }
  35% { opacity: 1; }
  100% { transform: translateY(2px); opacity: 0.2; }
}

@media (max-width: 460px) {
  .studio { gap: 14px; }
  .riga--scelte { justify-content: center; }
  .stoffa { padding: 0 11px 0 8px; font-size: 0.84rem; }
  .pillola { padding: 0 18px; }
}

/* ------------------------------------------------------------------ the downloaded animation: only the stage */
/* the frame can be any size (a square, a wide banner, a phone): the stage keeps its shape, as large as fits,
   centred, with the hint underneath */
.solo-palco body {
  --margine: clamp(8px, 3vmin, 32px);
  min-height: 0;
  height: 100vh;
  height: 100svh;
  padding: var(--margine);
  overflow: hidden;
}
.solo-palco .studio {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  gap: 0;
}
.solo-palco .palco {
  justify-items: center;
}
.solo-palco .tavola {
  width: min(calc(100vw - 2 * var(--margine)), calc((100vh - 2 * var(--margine) - 28px) / 0.92));
  width: min(calc(100vw - 2 * var(--margine)), calc((100svh - 2 * var(--margine) - 28px) / 0.92));
}
.solo-palco .comandi {
  display: none;
}

/* ------------------------------------------------------------------ the preview frame: only the stage, square */
.anteprima body {
  padding: 0;
  overflow: hidden;
}
.anteprima .studio {
  width: 100vw;
  height: 100vh;
  display: block;
}
.anteprima .palco {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
}
.anteprima .tavola {
  width: min(100vw, 100vh);
  height: min(100vw, 100vh);
  aspect-ratio: auto;
  border-radius: 0;
  pointer-events: none;
}
.anteprima .cenno,
.anteprima .comandi {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .stoffa,
  .stoffa__campione,
  .filo,
  .filo::after,
  .pillola::before,
  .pillola__testo,
  .pillola__segno {
    transition: opacity 0.2s ease, color 0.2s ease;
  }
  .pillola[aria-busy='true'] .pillola__segno path:last-child {
    animation: none;
    opacity: 0.5;
  }
}
