:root {
  --fondo: #f5f3ee;          /* the warm white behind the card */
  --carta: #ffffff;
  --bordo: rgba(28, 26, 22, 0.07);
  --testo: #1a1a1c;
  --testo-2: #6c6b68;
  --testo-3: #a8a6a1;
  --mio: #1b1c1f;            /* my bubbles, ink */
  --suo: #f1efea;            /* her bubbles, warm grey */
  --accento: #3366f0;        /* the one accent: the read ticks and the send button */
  --volto-1: #eadccb;        /* the avatar, sand */
  --volto-2: #d3bea5;
}

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

.stage {
  position: relative;
  height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(10px, 3vh, 28px) 12px;
}

/* ---- the card ---- */
.chat {
  position: relative;
  width: min(360px, 100%);
  height: min(520px, 100%);
  display: flex;
  flex-direction: column;
  background: var(--carta);
  border-radius: clamp(20px, 4vh, 28px);
  box-shadow:
    0 0 0 1px var(--bordo),
    0 1px 1px rgba(40, 32, 20, 0.03),
    0 6px 14px -6px rgba(40, 32, 20, 0.08),
    0 24px 48px -20px rgba(40, 32, 20, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  overflow: hidden;
  isolation: isolate;
}

/* ---- the header ---- */
.top {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: clamp(10px, 2.2vh, 14px) 14px clamp(9px, 2vh, 12px) 8px;
  border-bottom: 1px solid rgba(28, 26, 22, 0.06);
  background: rgba(255, 255, 255, 0.92);
}
.top__back, .top__call {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: var(--testo-2);
  transition: background-color .25s;
}
.top__back svg, .top__call svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.top__call { margin-left: auto; }
.top__call svg { width: 17px; height: 17px; stroke-width: 1.4; }
.top__who { display: flex; flex-direction: column; min-width: 0; }
.top__name { font-size: 14.5px; font-weight: 600; font-variation-settings: "wdth" 100; letter-spacing: -0.01em; line-height: 1.2; }
.top__sub { display: grid; height: 15px; overflow: hidden; font-size: 11.5px; color: var(--testo-2); line-height: 15px; }
.top__line { grid-area: 1 / 1; display: block; white-space: nowrap; }
.top__line--typing { opacity: 0; color: var(--testo-2); }
.top__line--typing .l { display: inline-block; opacity: 0.32; }

.face {
  flex: none;
  position: relative;
  display: grid; place-items: center;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: radial-gradient(120% 120% at 30% 20%, var(--volto-1), var(--volto-2));
  box-shadow: inset 0 0 0 0.5px rgba(60, 40, 20, 0.18), 0 1px 2px rgba(60, 40, 20, 0.16);
  color: #5d4a35;
  font-size: 6.5px; font-weight: 650; letter-spacing: 0.02em;
}
.face--big { width: 32px; height: 32px; font-size: 11.5px; box-shadow: inset 0 0 0 0.5px rgba(60, 40, 20, 0.16), inset 0 1px 0 rgba(255,255,255,0.5); }
.face__in { line-height: 1; }

/* ---- the thread ---- */
.thread {
  position: relative;
  z-index: 2;
  flex: 1;
  min-height: 0;
  clip-path: inset(0 -20px -90px -20px);
}
.thread::before {
  content: "";
  position: absolute; left: 0; right: 0; top: 0; height: 34px;
  background: linear-gradient(var(--carta), rgba(255, 255, 255, 0));
  z-index: 2;
  pointer-events: none;
}
.list {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 0 14px clamp(6px, 1.4vh, 10px);
  display: flex;
  flex-direction: column;
  gap: clamp(5px, 1.1vh, 8px);
}
.msg { display: flex; flex-direction: column; }
.stamp { align-self: center; margin-bottom: 4px; font-size: 10.5px; letter-spacing: 0.01em; color: var(--testo-3); font-variant-numeric: tabular-nums; }
.stamp b { font-weight: 600; color: var(--testo-2); }
.msg--out { align-items: flex-end; }
.msg--in { align-items: flex-start; }
.msg--in + .msg--out, .msg--out + .msg--in { margin-top: clamp(3px, 0.8vh, 6px); }

.bubble {
  position: relative;
  max-width: 70%;
  padding: 8px 12px 8.5px;
  border-radius: 18px;
  font-size: clamp(13px, 2.6vh, 14px);
  line-height: 1.32;
  font-variation-settings: "wdth" 100;
  letter-spacing: -0.003em;
  will-change: transform;
}
.bubble--out {
  background: var(--mio);
  color: #fbfaf8;
  border-bottom-right-radius: 6px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 4px 10px -6px rgba(10, 10, 12, 0.5);
}
.bubble--in {
  background: var(--suo);
  color: var(--testo);
  border-bottom-left-radius: 6px;
  box-shadow: inset 0 0 0 0.5px rgba(28, 26, 22, 0.05);
}
.bubble__text { display: block; }
.bubble--typing { padding: 0; width: 52px; height: 34px; overflow: hidden; }
.bubble--typing .wave { position: absolute; left: 50%; top: 50%; width: 32px; height: 14px; margin: -7px 0 0 -16px; fill: none; stroke: #8f8c86; stroke-width: 1.5; stroke-linecap: round; }
.bubble--typing .bubble__text { opacity: 0; white-space: nowrap; }

/* the read time that slides out beside a read message */
.readchip {
  position: absolute;
  right: calc(100% + 7px);
  top: 50%;
  margin-top: -10px;
  height: 20px;
  padding: 0 8px;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 0 0 1px rgba(28, 26, 22, 0.07), 0 4px 10px -5px rgba(40, 32, 20, 0.22);
  color: var(--testo-2);
  font-size: 10.5px;
  line-height: 20px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}

/* ---- the status under my last message ---- */
.meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  height: 0;
  margin-top: 0;
  color: var(--testo-3);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}
.tick { width: 17px; height: 12px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.35; stroke-linecap: round; stroke-linejoin: round; overflow: visible; opacity: 0; }
.tick__clock { transform-origin: 6px 6px; }
.tick__hand { transform-origin: 6px 6px; }
.tick__one, .tick__two { stroke-dasharray: 1 1; stroke-dashoffset: 1; }
.meta__label { position: relative; display: inline-block; height: 14px; line-height: 14px; overflow: hidden; min-width: 1px; }
.meta__word { display: block; white-space: nowrap; }
.meta__word + .meta__word { position: absolute; right: 0; top: 0; }
.meta__slot { width: 16px; height: 16px; flex: none; margin-left: 1px; }

/* the avatar that sits under the last message she has read */
.seen { position: absolute; left: 0; top: 0; z-index: 1; pointer-events: none; }

/* ---- the composer ---- */
.composer {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: clamp(8px, 1.8vh, 12px) 12px clamp(10px, 2.2vh, 14px);
  background: var(--carta);
}
.composer__plus { width: 30px; height: 30px; flex: none; display: grid; place-items: center; border-radius: 50%; background: #f4f2ee; color: var(--testo-2); }
.composer__plus svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.field {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 36px;
  border-radius: 18px;
  background: #faf9f6;
  box-shadow: inset 0 0 0 1px rgba(28, 26, 22, 0.08);
  transition: box-shadow .3s;
}
.field:focus-within { box-shadow: inset 0 0 0 1px rgba(51, 102, 240, 0.45), 0 0 0 3px rgba(51, 102, 240, 0.08); }
.field__input {
  width: 100%; height: 100%;
  padding: 0 14px;
  font-size: clamp(13px, 2.6vh, 14px);
  letter-spacing: -0.003em;
  outline: none;
  color: var(--testo);
}
.field__input::placeholder { color: var(--testo-3); }
.field__mirror { position: absolute; left: 14px; top: 0; visibility: hidden; white-space: pre; font-size: clamp(13px, 2.6vh, 14px); letter-spacing: -0.003em; }
.field__caret { position: absolute; left: 14px; top: 50%; width: 1.5px; height: 17px; margin-top: -8.5px; border-radius: 1px; background: var(--accento); opacity: 0; }

.send { position: relative; width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 50%; color: #fff; }
.send:disabled { cursor: default; }
.send__bg { position: absolute; inset: 0; border-radius: 50%; background: #e7e4de; box-shadow: inset 0 1px 0 rgba(255,255,255,0.25); }
.send__arrow { position: relative; width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

@media (hover: hover) {
  .top__back:hover, .top__call:hover { background: #f3f1ec; }
}
@media (max-width: 340px) {
  .bubble { max-width: 74%; }
}
