:root {
  --fondo: #f3f2ee;
  --carta: #ffffff;
  --inchiostro: #17171b;
  --grigio: #8b8a92;
  --grigio-chiaro: #c2c1c7;
  --linea: rgba(23, 23, 27, 0.08);
  --loro: #efeff2;
  --accento: #2f62ff;
  --accento-chiaro: #e9eeff;
  --chat-w: min(372px, 92vw);
  --chat-h: min(600px, 92vh);
}

* { box-sizing: border-box; margin: 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;
}

.stage {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2vh 4vw;
}

.chat {
  position: relative;
  width: var(--chat-w);
  height: var(--chat-h);
  display: flex;
  flex-direction: column;
  background: var(--carta);
  border-radius: 22px;
  box-shadow: 0 1px 0 rgba(23, 23, 27, 0.04), 0 18px 40px -22px rgba(23, 23, 27, 0.28), 0 0 0 1px var(--linea);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: clamp(10px, 2.2vh, 14px) 14px;
  border-bottom: 1px solid var(--linea);
  flex: none;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(150deg, #ffd9c2, #f5b49a);
  box-shadow: inset 0 0 0 1px rgba(23, 23, 27, 0.06);
  flex: none;
}

.avatar__in { font-size: 11px; font-weight: 640; font-stretch: 110%; color: #7a3d26; letter-spacing: 0.02em; }

.who { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.who__name { font-size: 14px; font-weight: 620; }
.who__state { font-size: 11.5px; color: var(--grigio); }

.head__ico { width: 20px; height: 20px; margin-left: auto; fill: none; stroke: var(--grigio); stroke-width: 1.6; stroke-linejoin: round; }

.thread {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 16px, #000 calc(100% - 8px), transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 16px, #000 calc(100% - 8px), transparent 100%);
}

.thread.is-presa { cursor: grabbing; }

.list {
  display: flex;
  flex-direction: column;
  padding: 14px 12px 10px;
}

.day {
  align-self: center;
  font-size: 10.5px;
  font-weight: 560;
  letter-spacing: 0.04em;
  color: var(--grigio);
  padding: 2px 0 10px;
  will-change: transform;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
  will-change: transform;
}

.row--io { justify-content: flex-end; }
.row--stacco { margin-top: 8px; }

.bubble {
  max-width: 76%;
  padding: 8px 12px 9px;
  border-radius: 18px;
  font-size: clamp(13px, 2.1vh, 14.5px);
  line-height: 1.32;
  background: var(--loro);
  color: var(--inchiostro);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.row--io .bubble {
  background: var(--accento);
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.row--loro .bubble { border-bottom-left-radius: 6px; }
.row--io .bubble { border-bottom-right-radius: 6px; }

.time {
  font-size: 10px;
  color: var(--grigio-chiaro);
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity 0.25s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  flex: none;
}

.row--io .time { order: -1; transform: translateX(4px); }

@media (hover: hover) {
  .row:hover .time { opacity: 1; transform: none; }
  .row--loro:hover .bubble { transform: translateX(2px); }
  .row--io:hover .bubble { transform: translateX(-2px); }
}

.stato {
  align-self: flex-end;
  height: 16px;
  position: relative;
  font-size: 10.5px;
  color: var(--grigio);
  padding-right: 4px;
}

.stato span { position: absolute; right: 4px; top: 2px; white-space: nowrap; }

.composer {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px clamp(10px, 2vh, 14px);
  border-top: 1px solid var(--linea);
}

.field {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 36px;
  border-radius: 18px;
  background: #f6f6f8;
  box-shadow: inset 0 0 0 1px var(--linea);
  display: flex;
  align-items: center;
  padding: 0 14px;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  transition: box-shadow 0.25s ease;
}

.field.is-attivo { box-shadow: inset 0 0 0 1.5px var(--accento); }

.field__ph { position: absolute; left: 14px; color: var(--grigio); pointer-events: none; }
.field__caret { display: inline-block; width: 1.5px; height: 17px; margin-left: 1px; background: var(--accento); opacity: 0; }

.send {
  flex: none;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.send__in {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accento);
  box-shadow: 0 6px 14px -8px rgba(47, 98, 255, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.send svg { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.cursor {
  position: fixed;
  left: 0;
  top: 0;
  width: 22px;
  height: 22px;
  fill: var(--inchiostro);
  stroke: #fff;
  stroke-width: 1.4;
  stroke-linejoin: round;
  pointer-events: none;
  opacity: 0;
  z-index: 5;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.18));
}

@media (max-height: 460px) {
  .head { padding: 8px 12px; }
  .avatar { width: 28px; height: 28px; }
  .list { padding-top: 10px; }
  .composer { padding: 8px 10px; }
  .field, .send { height: 32px; }
  .send { width: 32px; }
}
