:root {
  --fondo: #f4f4f1;
  --carta: #ffffff;
  --inchiostro: #141416;
  --testo: #3b3b41;
  --grigio: #8b8b92;
  --grigio-chiaro: #b7b7bd;
  --linea: #ececee;
  --sopra: #f6f6f3;
  --accento: #f0642d;
  --accento-tenue: #fdeee6;
}

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

html, body { height: 100%; overflow: hidden; }

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

button { font: inherit; color: inherit; }

.palco {
  position: relative;
  height: 100vh;
  display: grid;
  place-items: center;
  padding: 12px;
  overflow: hidden;
}

/* ---------- the window of the app ---------- */
.posta {
  position: relative;
  width: min(560px, 100%);
  height: min(430px, calc(100vh - 24px));
  background: var(--carta);
  border-radius: 20px;
  border: 1px solid #e9e9ec;
  box-shadow: 0 1px 2px rgba(20, 20, 22, 0.04), 0 22px 50px -24px rgba(20, 20, 22, 0.24);
  overflow: hidden;
}

.lista {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 0 8px;
}

/* ---------- the head: the mark, Inbox and the unread count ---------- */
.testa {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: clamp(48px, 12vh, 58px);
  padding: 0 8px 0 10px;
  flex: none;
}
.testa__sx { display: flex; align-items: center; gap: 9px; min-width: 0; }
.marchio {
  width: 26px; height: 26px; border-radius: 8px; flex: none;
  background: var(--inchiostro); display: grid; place-items: center;
}
.marchio svg { width: 19px; height: 19px; fill: #fff; }
.testa__titolo { font-size: 16px; font-weight: 640; letter-spacing: -0.015em; }

.conta {
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; padding: 0 8px 0 7px; border-radius: 999px;
  background: var(--accento-tenue); color: var(--accento);
  font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.conta__cifre { display: inline-flex; }
.conta__dopo { font-weight: 500; }
.cifra {
  position: relative; display: inline-block; width: 0.62em; height: 1.25em; overflow: hidden; line-height: 1.25em; text-align: center;
  -webkit-mask-image: linear-gradient(transparent, #000 28%, #000 72%, transparent);
  mask-image: linear-gradient(transparent, #000 28%, #000 72%, transparent);
}
.cifra__col { display: flex; flex-direction: column; will-change: transform; }
.cifra__col span { display: block; height: 1.25em; }

.testa__dx { display: flex; gap: 2px; }

.tasto-icona {
  position: relative; width: 32px; height: 32px; border: 0; border-radius: 9px; background: none; cursor: pointer;
  display: grid; place-items: center; color: var(--grigio); transition: background 0.2s, color 0.2s;
}
.tasto-icona svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tasto-icona:focus-visible, .riga:focus-visible, .indietro:focus-visible { outline: 2px solid var(--inchiostro); outline-offset: -2px; }
@media (hover: hover) {
  .tasto-icona:hover { background: var(--sopra); color: var(--inchiostro); }
}

/* ---------- the rows ---------- */
.righe {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.riga {
  --peso: 470;
  --peso-oggetto: 470;
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  max-height: 66px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 12px;
  width: 100%;
  padding: 0 12px 0 14px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 0.18s;
}
.riga + .riga::before {
  content: "";
  position: absolute; left: 54px; right: 12px; top: 0; height: 1px; background: var(--linea);
  transition: opacity 0.18s;
}
.riga.is-sopra { background: var(--sopra); }
.riga.is-sopra::before, .riga.is-sopra + .riga::before { opacity: 0; }
.riga.is-via { background: transparent; z-index: 3; }
.riga.is-via::before, .riga.is-via + .riga::before { opacity: 0; }

.riga__testo { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.riga__su { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.riga__nome {
  font-size: 14px; line-height: 1.25; letter-spacing: -0.01em; white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis;
  font-weight: var(--peso); transform-origin: 0 0;
}
.riga__giu { display: flex; align-items: baseline; min-width: 0; font-size: 13px; line-height: 1.3; white-space: nowrap; color: var(--grigio); }
.riga__oggetto { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--inchiostro); font-weight: var(--peso-oggetto); transform-origin: 0 0; }
.riga__anteprima { flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; margin-left: 6px; }

.riga__dx { display: flex; align-items: center; gap: 6px; margin-left: auto; flex: none; align-self: center; }
.riga__ora { font-size: 12px; color: var(--grigio); font-variant-numeric: tabular-nums; white-space: nowrap; transition: color 0.2s; }
.riga.is-nuova .riga__ora { color: var(--inchiostro); font-weight: 560; }
.riga__stella { width: 13px; height: 13px; fill: var(--accento); stroke: none; opacity: 0; transform: scale(0.4); }

/* ---------- the avatars: initials on a soft drawn tint ---------- */
.avatar {
  position: relative;
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  font-size: 11.5px; font-weight: 620; letter-spacing: 0.01em; color: rgba(20, 20, 22, 0.78);
  background: radial-gradient(120% 120% at 30% 20%, var(--a1), var(--a2));
  box-shadow: inset 0 0 0 1px rgba(20, 20, 22, 0.06);
  transform-origin: 0 0;
}
.avatar::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: radial-gradient(60% 50% at 32% 22%, rgba(255, 255, 255, 0.65), transparent 70%);
}
.avatar--marchio { border-radius: 30%; color: #fff; }
.avatar svg { position: relative; z-index: 1; width: 52%; height: 52%; fill: none; stroke: #fff; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.avatar--grande { width: 40px; height: 40px; font-size: 15px; }

/* ---------- the selection bar ---------- */
.selezione {
  position: absolute; left: 10px; top: 0; width: 3px; height: 26px; border-radius: 3px;
  background: var(--accento); pointer-events: none; z-index: 4;
}

/* ---------- the keyboard line ---------- */
.tasti {
  display: flex; gap: 14px; align-items: center; justify-content: center; flex: none;
  height: clamp(34px, 9vh, 42px); font-size: 11.5px; color: var(--grigio);
  border-top: 1px solid var(--linea); margin: 0 4px;
}
.tasti span { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
kbd {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 4px;
  font: inherit; font-size: 10.5px; font-weight: 560; color: var(--testo);
  background: #f7f7f5; border: 1px solid #e6e6e9; border-bottom-width: 2px; border-radius: 5px;
}

/* ---------- the surface that becomes the page ---------- */
.lastra {
  --ombra: 0;
  position: absolute; left: 0; top: 0; width: 0; height: 0;
  background: var(--carta);
  border-radius: 12px;
  z-index: 2;
  visibility: hidden;
  box-shadow:
    0 0 0 1px rgba(20, 20, 22, calc(0.06 * var(--ombra))),
    0 calc(10px * var(--ombra)) calc(26px * var(--ombra)) calc(-10px * var(--ombra)) rgba(20, 20, 22, calc(0.3 * var(--ombra)));
}

/* ---------- the open message ---------- */
.messaggio {
  position: absolute; inset: 0;
  z-index: 4;
  display: flex; flex-direction: column;
  padding: 0 clamp(14px, 4.4vw, 26px) clamp(12px, 3vh, 18px);
  visibility: hidden;
  pointer-events: none;
}
.messaggio.is-aperto { visibility: visible; pointer-events: auto; }

.messaggio__barra {
  display: flex; align-items: center; justify-content: space-between;
  height: clamp(46px, 11.5vh, 56px); flex: none; margin: 0 -8px;
}
.indietro {
  display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 10px 0 4px;
  border: 0; border-radius: 9px; background: none; cursor: pointer;
  font-size: 13.5px; font-weight: 560; color: var(--testo); transition: background 0.2s;
}
.indietro svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.indietro kbd { margin-left: 6px; }
@media (hover: hover) {
  .indietro:hover { background: var(--sopra); }
}
.azioni { display: flex; gap: 2px; }

.stella { overflow: visible; }
.stella__icona { position: relative; z-index: 1; }
.stella__forma { transition: fill 0.25s, stroke 0.25s; }
.stella[aria-pressed="true"] { color: var(--accento); }
.stella[aria-pressed="true"] .stella__forma { fill: var(--accento); }
.stella__raggi {
  position: absolute; left: 50%; top: 50%; width: 40px; height: 40px; margin: -20px 0 0 -20px;
  fill: none; stroke: var(--accento); stroke-width: 1.6; stroke-linecap: round; opacity: 0; pointer-events: none;
}

.mittente { display: flex; align-items: center; gap: 12px; flex: none; margin-top: clamp(2px, 1vh, 8px); }
.mittente__testo { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.mittente__nome { font-size: 15px; line-height: 1.25; font-weight: 620; letter-spacing: -0.01em; white-space: nowrap; transform-origin: 0 0; align-self: flex-start; }
.mittente__email { font-size: 12px; color: var(--grigio); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mittente__ora { font-size: 12px; color: var(--grigio); white-space: nowrap; align-self: flex-start; margin-top: 3px; font-variant-numeric: tabular-nums; }

.oggetto {
  margin-top: clamp(10px, 2.8vh, 18px);
  font-size: clamp(18px, 5vw, 21px); line-height: 1.25; font-weight: 640; letter-spacing: -0.022em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transform-origin: 0 0; align-self: flex-start; max-width: 100%;
  flex: none;
}

.corpo {
  margin-top: clamp(8px, 2vh, 12px);
  font-size: 13.5px; line-height: 1.55; color: var(--testo);
  flex: none;
}
.corpo p + p { margin-top: clamp(6px, 1.6vh, 10px); }
.corpo .rt { display: block; }

.allegato {
  display: inline-flex; align-items: center; gap: 8px; align-self: flex-start;
  margin-top: clamp(10px, 2.4vh, 16px); height: 36px; padding: 0 12px 0 9px;
  border: 1px solid var(--linea); border-radius: 10px; font-size: 12.5px; flex: none;
}
.allegato svg { width: 18px; height: 18px; fill: none; stroke: var(--grigio); stroke-width: 1.5; stroke-linejoin: round; }
.allegato__nome { font-weight: 560; }
.allegato__peso { color: var(--grigio); }

.rispondi {
  margin-top: auto;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex: none;
  height: 40px; padding: 0 8px 0 14px; border-radius: 12px;
  background: #f7f7f5; border: 1px solid #ededf0;
  font-size: 13px; color: var(--grigio);
}

/* ---------- the drawn pointer of the autopilot ---------- */
.fantasma {
  position: absolute; left: 0; top: 0; width: 22px; height: 22px;
  fill: #111113; stroke: #ffffff; stroke-width: 1.4; stroke-linejoin: round;
  pointer-events: none; opacity: 0; z-index: 10;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.18));
}

/* ---------- short boxes: the phone preview is 341 by 410 ---------- */
@media (max-height: 470px) {
  .allegato { display: none; }
  .tasti { display: none; }
  .riga { max-height: 70px; }
  .corpo { font-size: 13px; line-height: 1.5; }
}
@media (max-width: 420px) {
  .riga__testo { gap: 2px; }
  .riga__giu { flex-direction: column; align-items: flex-start; }
  .riga__oggetto { max-width: 100%; }
  .riga__anteprima { flex: none; width: 100%; margin-left: 0; font-size: 12.5px; }
  .conta__dopo { display: none; }
  .indietro kbd { display: none; }
  .riga { padding: 0 10px 0 12px; column-gap: 10px; }
  .riga + .riga::before { left: 50px; }
  .tasti { gap: 10px; }
}
