:root {
  --carta: #f6f3ee;      /* il bianco caldo del fondo */
  --inchiostro: #1d1b18; /* il testo e i fili */
  --filo: #8f8a82;       /* il colore dei fili e della barra */
  --faccia: #ffffff;     /* la faccia delle etichette */
  --bordo: #e2ddd5;      /* il bordo sottile delle etichette */
  --muto: #8a857d;       /* i testi piccoli */
  --accento: #2f5bff;    /* l’etichetta scelta */
  --fs: clamp(12px, min(2.9vw, 4.1vh), 30px);
}

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

html, body { height: 100%; }

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

.stage {
  position: relative;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.top {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; justify-content: space-between; align-items: baseline;
  padding: clamp(14px, 3.4vh, 30px) clamp(16px, 4vw, 40px) 0;
  font-size: clamp(11px, min(1.6vw, 2.4vh), 14px);
}
.brand { font-weight: 640; font-stretch: 112%; letter-spacing: -0.01em; }
.hint { color: var(--muto); font-weight: 460; }

.rig { position: absolute; inset: 0; }

.threads {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  overflow: visible;
  pointer-events: none;
}
.rail { stroke: var(--filo); stroke-width: 1; stroke-linecap: round; }
.knot { fill: none; stroke: var(--filo); stroke-width: 1; }
.thread { fill: none; stroke: var(--filo); stroke-width: 1; stroke-linecap: round; }
.thread.is-taut { stroke: var(--inchiostro); }

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

/* GSAP-free: the script writes left/top through transform on .tag; the face is for CSS */
.tag {
  position: absolute; left: 0; top: 0;
  display: block;
  padding: 0; border: 0; background: none;
  font: inherit; color: inherit;
  cursor: grab;
  pointer-events: auto;
  transform-origin: 50% 0;
  will-change: transform;
  -webkit-tap-highlight-color: transparent;
}
.tag:active { cursor: grabbing; }
.tag:focus-visible { outline: none; }
.tag:focus-visible .tag__face { box-shadow: 0 0 0 2px var(--carta), 0 0 0 3.5px var(--accento); }

.tag__clip {
  position: absolute; left: 50%; top: -5px;
  width: 4px; height: 8px;
  margin-left: -2px;
  border-radius: 1.5px;
  background: linear-gradient(90deg, #b9b3a9, #e8e3db 55%, #a59f95);
  box-shadow: 0 0.5px 0 rgba(0, 0, 0, 0.08);
}

.tag__face {
  display: block;
  padding: 0.5em 1.05em 0.56em;
  border-radius: 999px;
  background: var(--faccia);
  border: 1px solid var(--bordo);
  font-size: var(--fs);
  font-weight: 540;
  font-stretch: 100%;
  letter-spacing: -0.005em;
  line-height: 1;
  white-space: nowrap;
  /* the shadow follows the swing: --sx is written by the script */
  box-shadow:
    calc(var(--sx, 0) * 1px) calc(4px + var(--sy, 0) * 1px) calc(10px + var(--sb, 0) * 1px) rgba(40, 30, 20, 0.09),
    calc(var(--sx, 0) * 0.3px) 1px 2px rgba(40, 30, 20, 0.07);
  transition: background-color 0.28s ease, border-color 0.28s ease, color 0.28s ease, font-stretch 0.35s ease, font-weight 0.35s ease, transform 0.14s ease;
}
.tag__label { display: block; }
.tag.is-on .tag__face {
  background: var(--accento);
  border-color: var(--accento);
  color: #fff;
  font-weight: 620;
  font-stretch: 108%;
}
.tag.is-down .tag__face { transform: scale(0.96); }
.tag__face { transform-origin: 50% 0; }

@media (hover: hover) {
  .tag:not(.is-on):hover .tag__face { border-color: #cfc8bd; }
}

.foot {
  position: absolute; left: 0; right: 0;
  bottom: clamp(18px, 13vh, 130px);
  text-align: center;
  padding: 0 16px;
}
.count {
  font-size: clamp(15px, min(3.2vw, 4.6vh), 36px);
  font-weight: 560;
  font-stretch: 104%;
  letter-spacing: -0.015em;
}
.count__n { display: inline-block; min-width: 1.6em; text-align: right; color: var(--accento); }
.count__name { display: inline-block; }
.note {
  margin-top: 0.55em;
  font-size: clamp(11px, min(1.5vw, 2.3vh), 13px);
  color: var(--muto);
}

.ghost {
  position: absolute; left: 0; top: 0;
  width: 24px; height: 24px;
  fill: #111; stroke: #fff; stroke-width: 1.4; stroke-linejoin: round;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.25));
  pointer-events: none;
  opacity: 0;
  z-index: 5;
}

@media (prefers-reduced-motion: reduce) {
  .tag__face { transition: background-color 0.4s ease, border-color 0.4s ease, color 0.4s ease; }
}
