:root {
  --fondo: #f4f1eb;          /* the warm white behind the chat */
  --carta: #fffdf9;          /* the chat card */
  --bordo: rgba(40, 30, 20, 0.07);
  --linea: #ece6dc;
  --testo: #1c1a17;          /* ink: text, the dark stickers */
  --testo-2: #6f6a62;
  --testo-3: #a8a297;
  --accento: #ff5b37;        /* the one accent: the bright stickers and the outgoing bubble edge */
  --crema: #f6eedf;          /* the cream stickers */
  --bolla-in: #f2eee7;       /* the incoming bubble */
  --bolla-out: #1c1a17;      /* the outgoing bubble */
  --foglio: #f3eee5;         /* the backing sheet of the stickers */
  --taglio: rgba(60, 44, 28, 0.2); /* the die-cut outline left on the sheet */
  --s: clamp(40px, min(14vw, 10.6vh), 68px); /* the size of a sticker */
}

* { 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;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.stage {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(8px, 2.6vh, 28px) 14px;
  background: radial-gradient(120% 80% at 50% 0%, #faf8f4 0%, var(--fondo) 60%);
}

/* ---- the chat card ---- */
.chat {
  position: relative;
  width: min(410px, 100%);
  background: var(--carta);
  border-radius: 24px;
  padding: clamp(10px, 2.6vh, 18px) clamp(12px, 4vw, 18px) clamp(10px, 2.4vh, 16px);
  box-shadow:
    0 0 0 1px var(--bordo),
    0 1px 1px rgba(40, 28, 16, 0.04),
    0 4px 10px -4px rgba(40, 28, 16, 0.06),
    0 24px 48px -24px rgba(40, 28, 16, 0.22);
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 2.2vh, 14px);
}
.chat::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0) 30%);
  mask: linear-gradient(#000, #000) content-box exclude, linear-gradient(#000, #000);
  padding: 1px;
}

.chat__head { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(160deg, #e9e2d6, #d9cfbf);
  font-size: 11px; font-weight: 650; font-stretch: 110%; color: #5d554a;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6), 0 1px 2px rgba(40, 28, 16, 0.12);
}
.who { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.who__name { font-size: 14px; font-weight: 640; }
.who__sub { font-size: 11.5px; color: var(--testo-3); font-weight: 460; }
.chat__more { width: 20px; height: 20px; margin-left: auto; fill: none; stroke: var(--testo-3); stroke-width: 3.2; stroke-linecap: round; }

/* ---- the thread ---- */
.thread { display: flex; flex-direction: column; gap: clamp(6px, 1.6vh, 10px); padding: 2px 0; }
.msg {
  position: relative;
  max-width: 80%;
  padding: clamp(7px, 1.6vh, 10px) 13px clamp(7px, 1.6vh, 10px);
  border-radius: 18px;
  font-size: clamp(12.5px, 2.2vh, 14px);
  line-height: 1.32;
  font-weight: 470;
  display: flex; align-items: flex-end; gap: 8px;
}
.msg__time { font-size: 10.5px; font-weight: 500; opacity: 0.5; flex: none; transform: translateY(1px); }
.msg--in { align-self: flex-start; background: var(--bolla-in); border-bottom-left-radius: 6px; }
.msg--out {
  align-self: flex-end; background: var(--bolla-out); color: #f6f1e8; border-bottom-right-radius: 6px;
  box-shadow: 0 6px 14px -8px rgba(20, 14, 8, 0.45);
}
/* the ring that says «drop here» while a sticker hovers the bubble */
.msg::after {
  content: ""; position: absolute; inset: -4px; border-radius: 22px; pointer-events: none;
  border: 1.5px dashed var(--accento); opacity: 0; transform: scale(0.97);
  transition: opacity 0.2s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.msg--in::after { border-bottom-left-radius: 10px; }
.msg--out::after { border-bottom-right-radius: 10px; }
.msg.is-target::after { opacity: 0.85; transform: scale(1); }

/* ---- the tray with the sticker sheet ---- */
.tray {
  border-top: 1px solid var(--linea);
  padding-top: clamp(8px, 1.8vh, 12px);
  display: flex; flex-direction: column; gap: clamp(6px, 1.4vh, 10px);
}
.tray__bar { display: flex; align-items: baseline; gap: 8px; }
.tray__title { font-size: 12.5px; font-weight: 650; }
.tray__pack { font-size: 11.5px; color: var(--testo-3); font-weight: 460; }
.tray__reset {
  margin-left: auto; font-size: 11.5px; font-weight: 560; color: var(--testo-2);
  padding: 3px 9px; border-radius: 99px; background: var(--bolla-in);
  transition: background-color 0.2s ease, color 0.2s ease;
}
@media (hover: hover) {
  .tray__reset:hover { background: #e9e3d8; color: var(--testo); }
}

.sheet {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, var(--s));
  justify-content: space-evenly;
  row-gap: clamp(8px, 1.8vh, 14px);
  padding: clamp(10px, 2vh, 14px) 10px;
  border-radius: 14px;
  background:
    repeating-linear-gradient(135deg, rgba(60, 44, 28, 0.028) 0 1px, transparent 1px 7px),
    var(--foglio);
  box-shadow: inset 0 0 0 1px rgba(60, 44, 28, 0.06), inset 0 1px 2px rgba(60, 44, 28, 0.06);
}
.slot { position: relative; width: var(--s); height: var(--s); }
.slot__cut { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.slot__cut path { fill: rgba(255, 255, 255, 0.35); stroke: var(--taglio); stroke-width: 1.1; vector-effect: non-scaling-stroke; }

/* ---- a sticker: the outer box is moved by GSAP, the inner one carries the CSS shadow ---- */
.stk {
  position: absolute; left: 0; top: 0;
  width: var(--s); height: var(--s);
  touch-action: none; cursor: grab;
  z-index: 1;
}
.stk.is-held { cursor: grabbing; }
.stk__lift {
  --lift: 0;
  width: 100%; height: 100%;
  filter:
    drop-shadow(0 calc(0.6px + var(--lift) * 10px) calc(0.8px + var(--lift) * 9px) rgba(40, 26, 12, calc(0.22 + var(--lift) * 0.05)))
    drop-shadow(0 0.5px 0.5px rgba(40, 26, 12, 0.16));
}
.stk svg { width: 100%; height: 100%; overflow: visible; display: block; }
.stk__rim { fill: #ffffff; }
.stk__back { stroke: rgba(60, 44, 28, 0.1); stroke-width: 0.6; }
.stk__word { font-family: "Mona Sans Variable", system-ui, sans-serif; font-weight: 820; font-stretch: 112%; letter-spacing: -0.02em; }
.stk__ink { fill: none; stroke-linecap: round; stroke-linejoin: round; }

/* stuck on a message */
.msg .stk { z-index: 2; cursor: grab; }

.carry { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.carry .stk { pointer-events: auto; }

/* ---- the drawn pointer of the self-running preview ---- */
.ptr {
  position: fixed; left: 0; top: 0; width: 22px; height: 22px; z-index: 6;
  pointer-events: none; opacity: 0;
  fill: var(--testo); stroke: #fff; stroke-width: 1.4; stroke-linejoin: round;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.18));
  transform-origin: 5px 3px;
}

@media (max-height: 440px) {
  .chat__head { display: none; }
}
@media (max-width: 340px) {
  .tray__pack { display: none; }
}
