/* ══════════════════════════════════════════════════════════════════
   Lezioni — sistema visivo

   Il modulo del quadretto (24px) detta ogni spaziatura: 8 / 16 / 24 / 48.
   Blu inchiostro per quello che si fa, rosso correzione per quello che è
   in diretta o non si torna indietro. Nessun webfont: su 150 kb/s due
   famiglie scaricate sarebbero banda rubata alla lezione.
   ══════════════════════════════════════════════════════════════════ */

:root {
  --modulo: 24px;
  --s1: 8px;
  --s2: 16px;
  --s3: 24px;
  --s4: 48px;

  --carta: #f5f6f8;
  --carta-alta: #ffffff;
  --quadretto: #dbe2ee;
  --inchiostro: #16181d;
  --inchiostro-tenue: #5c6270;
  --inchiostro-fioco: #8b909c;

  --blu: #4a5ddb;
  --blu-scuro: #3546b8;
  --rosso: #d1394a;
  --verde: #1c8a5a;
  --ambra: #e8a33d;

  --scuro: #14161a;
  --scuro-alto: #1e2127;
  --scuro-piu: #272b33;
  --bordo-scuro: #333844;
  --testo-scuro: #e9ebf1;
  --testo-scuro-tenue: #969cab;

  --raggio: 10px;
  --raggio-grande: 16px;
  --ombra: 0 1px 2px rgb(22 24 29 / 0.06), 0 8px 24px rgb(22 24 29 / 0.08);
  --ombra-alta: 0 12px 40px rgb(0 0 0 / 0.45);

  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo,
    Consolas, monospace;

  color-scheme: light dark;
}

* { box-sizing: border-box; }

/*
 * Senza questa riga l attributo hidden non funziona: la regola del browser
 * ([hidden] { display: none }) viene da un foglio di stile di rango inferiore e
 * perde contro qualunque display dichiarato qui, indipendentemente dalla
 * specificita. Con .stanza { display: grid } le tre schermate finirebbero una
 * sopra l altra.
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--sans);
  color: var(--inchiostro);
  background: var(--carta);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--blu);
  outline-offset: 2px;
  border-radius: 4px;
}

.nascosto { position: absolute; left: -9999px; opacity: 0; }

/* ─────────────── Tipografia ─────────────── */

.marchio {
  margin: 0 0 var(--s4);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--blu);
}

.etichetta {
  margin: 0 0 var(--s1);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--inchiostro-fioco);
}

.tesi {
  margin: 0 0 var(--s3);
  font-size: clamp(2.1rem, 8vw, 3.5rem);
  line-height: 1.02;
  letter-spacing: -0.035em;
  font-weight: 700;
}

.sottotesi {
  margin: 0 0 var(--s4);
  max-width: 34ch;
  font-size: 1.0625rem;
  line-height: 1.55;
  color: var(--inchiostro-tenue);
}

.nota {
  margin: var(--s2) 0 0;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--inchiostro-tenue);
}

.nota--piccola { font-size: 0.8125rem; margin-top: var(--s1); }

.errore {
  margin: var(--s1) 0 0;
  min-height: 1.2em;
  font-size: 0.875rem;
  color: var(--rosso);
}

/* ─────────────── Schermate a carta ─────────────── */

.schermata {
  position: relative;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--s4) var(--s3);
}

/* La firma: il quaderno a quadretti, appena percettibile. */
.carta-griglia {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(to right, var(--quadretto) 1px, transparent 1px),
    linear-gradient(to bottom, var(--quadretto) 1px, transparent 1px);
  background-size: var(--modulo) var(--modulo);
  opacity: 0.5;
  mask-image: radial-gradient(ellipse 80% 60% at 30% 20%, #000 20%, transparent 78%);
  pointer-events: none;
}

.home-contenuto,
.lobby-contenuto {
  position: relative;
  width: 100%;
  max-width: 560px;
}

.azioni-home { margin-bottom: var(--s4); }

/* ─────────────── Controlli ─────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s1);
  padding: 12px 20px;
  border: 1px solid transparent;
  border-radius: var(--raggio);
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  transition: background-color 0.15s, border-color 0.15s, transform 0.08s;
}

.btn:active { transform: translateY(1px); }

.btn--grande { width: 100%; padding: 16px 24px; font-size: 1rem; }

.btn--primario { background: var(--blu); color: #fff; }
.btn--primario:hover { background: var(--blu-scuro); }

.btn--solido {
  background: var(--inchiostro);
  color: var(--carta-alta);
}
.btn--solido:hover { background: #000; }

.btn--fantasma {
  background: transparent;
  border-color: var(--quadretto);
  color: var(--inchiostro);
}
.btn--fantasma:hover { border-color: var(--inchiostro-fioco); background: var(--carta-alta); }

.btn--scuro {
  border-color: var(--bordo-scuro);
  color: var(--testo-scuro);
  width: 100%;
  margin-top: var(--s1);
}
.btn--scuro:hover { background: var(--scuro-piu); border-color: var(--inchiostro-fioco); }

.btn--rosso { color: var(--rosso); }
.btn--rosso:hover { background: rgb(209 57 74 / 0.12); border-color: var(--rosso); }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.campo {
  width: 100%;
  padding: 12px 14px;
  background: var(--carta-alta);
  border: 1px solid var(--quadretto);
  border-radius: var(--raggio);
  transition: border-color 0.15s;
}
.campo:focus { border-color: var(--blu); outline: none; box-shadow: 0 0 0 3px rgb(74 93 219 / 0.15); }

.campo--codice {
  font-family: var(--mono);
  font-size: 1.0625rem;
  letter-spacing: 0.08em;
}

.campo-gruppo { display: block; margin-bottom: var(--s2); }

.campi { margin-bottom: var(--s3); }

.interruttori { display: grid; gap: var(--s1); margin-bottom: var(--s3); }

.interruttore {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9375rem;
  cursor: pointer;
}
.interruttore input { width: 18px; height: 18px; accent-color: var(--blu); }

.interruttore--scuro {
  color: var(--testo-scuro);
  margin: var(--s2) 0 var(--s1);
}

.avviso-link {
  display: inline-block;
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--blu-scuro);
  overflow-wrap: anywhere;
}

.avviso {
  margin: 0 0 var(--s3);
  padding: 12px 14px;
  background: rgb(232 163 61 / 0.12);
  border-left: 3px solid var(--ambra);
  border-radius: 0 var(--raggio) var(--raggio) 0;
  font-size: 0.875rem;
  line-height: 1.5;
  color: #7a5410;
}

/* ─────────────── Il codice come eroe ─────────────── */

.pannello-codice {
  margin-bottom: var(--s4);
  padding: var(--s3);
  background: var(--carta-alta);
  border: 1px solid var(--quadretto);
  border-radius: var(--raggio-grande);
  box-shadow: var(--ombra);
}

.codice-eroe {
  margin: 0 0 var(--s3);
  font-family: var(--mono);
  font-size: clamp(1.5rem, 7vw, 2.4rem);
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--inchiostro);
}

.link-riga {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) 0;
  border-top: 1px solid var(--carta);
}

.link-testo { min-width: 0; flex: 1; }

.link-testo code {
  display: block;
  font-family: var(--mono);
  font-size: 0.8125rem;
  color: var(--inchiostro-tenue);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unisciti { border-top: 1px solid var(--quadretto); padding-top: var(--s3); }
.unisciti-riga { display: flex; gap: var(--s1); }
.unisciti-riga .campo { flex: 1; }

/* ─────────────── Sala d'attesa ─────────────── */

.titolo-lobby {
  margin: 0 0 var(--s3);
  font-size: clamp(1.5rem, 5vw, 2rem);
  letter-spacing: -0.025em;
}

.anteprima-blocco { margin-bottom: var(--s3); }

.anteprima-cornice {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--scuro);
  border-radius: var(--raggio-grande);
  overflow: hidden;
  display: grid;
  place-items: center;
}

.anteprima-cornice video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* Specchio: ci si aspetta di vedersi come allo specchio, non al contrario. */
  transform: scaleX(-1);
}

.anteprima-vuota {
  position: absolute;
  margin: 0;
  font-size: 0.875rem;
  color: var(--testo-scuro-tenue);
}

.vu {
  height: 6px;
  margin-top: var(--s1);
  background: var(--quadretto);
  border-radius: 999px;
  overflow: hidden;
}

.vu-barra {
  height: 100%;
  width: 0%;
  background: var(--verde);
  border-radius: 999px;
  transition: width 0.08s linear;
}

/* ─────────────── La stanza ─────────────── */

.stanza {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  background: var(--scuro);
  color: var(--testo-scuro);
  overflow: hidden;
}

.palco {
  position: relative;
  overflow: hidden;
  background: var(--scuro);
}

.video-palco {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: var(--scuro);
}

#v-remoto { object-fit: cover; }
/* Lo schermo condiviso non si taglia mai: il testo tagliato non si legge. */
#v-schermo { object-fit: contain; }

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

.tela--live {
  touch-action: none;
  cursor: crosshair;
}

.tela--live.disegnabile { pointer-events: auto; }

.palco-vuoto {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: var(--s1);
  padding: var(--s3);
  text-align: center;
}

.palco-vuoto-titolo {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.palco-vuoto-testo {
  margin: 0 0 var(--s2);
  max-width: 32ch;
  font-size: 0.9375rem;
  color: var(--testo-scuro-tenue);
}

.palco-vuoto .btn--fantasma { color: var(--testo-scuro); border-color: var(--bordo-scuro); }
.palco-vuoto .btn--fantasma:hover { background: var(--scuro-alto); }

.etichetta-video {
  position: absolute;
  left: var(--s2);
  top: var(--s2);
  margin: 0;
  padding: 5px 10px;
  background: rgb(0 0 0 / 0.55);
  backdrop-filter: blur(8px);
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 600;
}

/* Ingrandimento della lavagna. In basso a sinistra: gli strumenti stanno al
   centro e i riquadri a destra. Serve anche a chi non puo disegnare, per
   leggere da vicino, quindi vive fuori dalla barra degli strumenti. */
.zoom {
  position: absolute;
  left: var(--s2);
  bottom: calc(var(--s2) + 76px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  background: rgb(30 33 39 / 0.92);
  backdrop-filter: blur(12px);
  border: 1px solid var(--bordo-scuro);
  border-radius: 999px;
  z-index: 6;
  transition: opacity 0.35s ease;
}

/*
 * A ingrandimento fermo l'indicatore si toglie di mezzo. Non resta invisibile e
 * cliccabile: se lo fosse, chi prova a disegnare in quell'angolo colpirebbe un
 * pulsante che non vede.
 */
.zoom.svanito {
  opacity: 0;
  pointer-events: none;
}

.zoom-bottone {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  background: transparent;
  border: none;
  border-radius: 999px;
  color: var(--testo-scuro-tenue);
}

.zoom-bottone svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.zoom-bottone:hover { background: var(--scuro-piu); color: var(--testo-scuro); }
.zoom-bottone:disabled { opacity: 0.35; cursor: not-allowed; }

.zoom-misura {
  min-width: 52px;
  padding: 0 6px;
  background: transparent;
  border: none;
  font-family: var(--mono);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--testo-scuro-tenue);
}

.zoom-misura:hover { color: var(--testo-scuro); }

@media (max-height: 460px) and (orientation: landscape) {
  .zoom { bottom: calc(var(--s1) + 58px); }
}

/* ─────────────── Riquadri delle persone ─────────────── */

.pip {
  position: absolute;
  right: var(--s2);
  bottom: calc(var(--s2) + 76px + env(safe-area-inset-bottom));
  display: grid;
  gap: var(--s1);
  touch-action: none;
  z-index: 5;
}

.pip-tessera {
  position: relative;
  width: 116px;
  aspect-ratio: 4 / 3;
  background: var(--scuro-alto);
  border: 1px solid var(--bordo-scuro);
  border-radius: var(--raggio);
  overflow: hidden;
  display: grid;
  place-items: center;
}

.pip-tessera video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#pip-locale video { transform: scaleX(-1); }

.pip-nome {
  position: absolute;
  left: 6px;
  bottom: 5px;
  margin: 0;
  padding: 2px 7px;
  background: rgb(0 0 0 / 0.55);
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
  max-width: calc(100% - 12px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pip-spento {
  position: absolute;
  margin: 0;
  font-size: 0.6875rem;
  color: var(--testo-scuro-tenue);
}

.pip.trascinato { transition: none; }

/* Con la chat aperta i riquadri finirebbero sotto il pannello. */
.pip.con-chat { right: calc(min(320px, 100vw - var(--s2) * 2) + var(--s3)); }

/* ─────────────── Strumenti della lavagna ─────────────── */

.strumenti {
  position: absolute;
  /* Centrata nello spazio che resta a sinistra dei riquadri, non nella finestra:
     centrarla sulla finestra la farebbe finire sotto le tessere video. */
  left: var(--s2);
  right: calc(var(--s2) + 132px);
  width: max-content;
  max-width: 100%;
  margin-inline: auto;
  bottom: calc(var(--s2) + 76px + env(safe-area-inset-bottom));
  display: flex;
  gap: var(--s1);
  padding: 6px;
  background: rgb(30 33 39 / 0.92);
  backdrop-filter: blur(12px);
  border: 1px solid var(--bordo-scuro);
  border-radius: 999px;
  overflow-x: auto;
  scrollbar-width: none;
  z-index: 6;
}

.strumenti::-webkit-scrollbar { display: none; }

.strumenti { transition: opacity 0.25s ease; }

/*
 * Scelto lo strumento, la barra si toglie di mezzo: resta una pastiglia che
 * dice quale strumento hai in mano e lo riapre. Come per lo zoom, da raccolta
 * non intercetta i tocchi, o si finirebbe per premere pulsanti invisibili
 * mentre si disegna.
 */
.strumenti.raccolta {
  opacity: 0;
  pointer-events: none;
}

.strumenti-apri {
  position: absolute;
  left: var(--s2);
  right: calc(var(--s2) + 132px);
  width: 46px;
  margin-inline: auto;
  bottom: calc(var(--s2) + 76px + env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
  height: 46px;
  padding: 0;
  background: rgb(30 33 39 / 0.92);
  backdrop-filter: blur(12px);
  border: 1px solid var(--bordo-scuro);
  border-radius: 999px;
  color: var(--testo-scuro);
  z-index: 6;
}

.strumenti-apri svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.strumenti-apri:hover { background: var(--scuro-piu); }

/* Il pallino dice con che colore stai scrivendo. */
.strumenti-apri::after {
  content: '';
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 11px;
  height: 11px;
  background: var(--colore-attivo, #16181d);
  border: 2px solid var(--scuro-alto);
  border-radius: 999px;
}

.strumenti-gruppo {
  display: flex;
  gap: 2px;
  padding-right: var(--s1);
  border-right: 1px solid var(--bordo-scuro);
  flex-shrink: 0;
}

.strumenti-gruppo:last-child { border-right: none; padding-right: 0; }

.strumento {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  background: transparent;
  border: none;
  border-radius: 999px;
  color: var(--testo-scuro-tenue);
  transition: background-color 0.12s, color 0.12s;
  flex-shrink: 0;
}

.strumento svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.strumento:hover { background: var(--scuro-piu); color: var(--testo-scuro); }
.strumento.attivo { background: var(--blu); color: #fff; }
.strumento--rosso:hover { background: rgb(209 57 74 / 0.2); color: var(--rosso); }
.strumento:disabled { opacity: 0.35; cursor: not-allowed; }

.colori { align-items: center; }

.colore {
  width: 26px;
  height: 26px;
  margin: 6px 1px;
  padding: 0;
  background: var(--c);
  border: 2px solid transparent;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.18);
  flex-shrink: 0;
}

.colore.attivo { border-color: #fff; }

.spessore {
  display: grid;
  place-items: center;
  width: 32px;
  height: 38px;
  background: transparent;
  border: none;
  border-radius: var(--raggio);
  flex-shrink: 0;
}

.spessore i {
  display: block;
  width: 18px;
  height: var(--s);
  background: var(--testo-scuro-tenue);
  border-radius: 999px;
}

.spessore:hover { background: var(--scuro-piu); }
.spessore.attivo { background: var(--scuro-piu); }
.spessore.attivo i { background: #fff; }

/* ─────────────── Barra dei comandi ─────────────── */

.barra {
  display: grid;
  place-items: center;
  padding: var(--s1) var(--s2) calc(var(--s1) + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--scuro) 55%, transparent);
  z-index: 8;
}

.barra-pillola {
  display: flex;
  gap: 2px;
  max-width: 100%;
  padding: 5px;
  background: var(--scuro-alto);
  border: 1px solid var(--bordo-scuro);
  border-radius: var(--raggio-grande);
  overflow-x: auto;
  scrollbar-width: none;
}

.barra-pillola::-webkit-scrollbar { display: none; }

.comando {
  position: relative;
  display: grid;
  place-items: center;
  gap: 3px;
  min-width: 58px;
  padding: 8px 10px;
  background: transparent;
  border: none;
  border-radius: 12px;
  color: var(--testo-scuro-tenue);
  transition: background-color 0.12s, color 0.12s;
  flex-shrink: 0;
}

.comando svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.comando-testo {
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.comando:hover { background: var(--scuro-piu); color: var(--testo-scuro); }
.comando.attivo { color: var(--testo-scuro); }

/* Spento: la barra diagonale dice "questa cosa non sta uscendo". */
.comando.spento { color: var(--rosso); }
.comando.spento::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 12px;
  width: 25px;
  height: 1.7px;
  background: var(--rosso);
  transform: translateX(-50%) rotate(-45deg);
  border-radius: 2px;
}

.comando--rosso:hover { background: rgb(209 57 74 / 0.18); color: var(--rosso); }
.comando--rete { min-width: 58px; }

.pallino {
  position: absolute;
  top: 6px;
  right: 10px;
  width: 8px;
  height: 8px;
  background: var(--rosso);
  border-radius: 999px;
}

.tacche { display: flex; align-items: flex-end; gap: 2px; height: 21px; }

.tacche i {
  width: 4px;
  background: var(--bordo-scuro);
  border-radius: 1px;
  transition: background-color 0.3s;
}
.tacche i:nth-child(1) { height: 25%; }
.tacche i:nth-child(2) { height: 50%; }
.tacche i:nth-child(3) { height: 75%; }
.tacche i:nth-child(4) { height: 100%; }
.tacche i.on { background: var(--verde); }
.tacche.media i.on { background: var(--ambra); }
.tacche.scarsa i.on { background: var(--rosso); }

/* ─────────────── Pannelli ─────────────── */

.pannello {
  position: absolute;
  right: var(--s2);
  bottom: calc(var(--s2) + 76px + env(safe-area-inset-bottom));
  width: min(300px, calc(100vw - var(--s2) * 2));
  padding: var(--s3);
  background: var(--scuro-alto);
  border: 1px solid var(--bordo-scuro);
  border-radius: var(--raggio-grande);
  box-shadow: var(--ombra-alta);
  z-index: 9;
}

.pannello .etichetta { color: var(--testo-scuro-tenue); margin-top: var(--s2); }
.pannello .etichetta:first-child { margin-top: 0; }
.pannello .nota { color: var(--testo-scuro-tenue); }

.statistiche { margin: 0 0 var(--s2); display: grid; gap: 5px; }
.statistiche > div { display: flex; justify-content: space-between; gap: var(--s2); }
.statistiche dt { font-size: 0.8125rem; color: var(--testo-scuro-tenue); }
.statistiche dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

.segmenti {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  padding: 3px;
  background: var(--scuro);
  border-radius: var(--raggio);
}

.segmento {
  padding: 7px 4px;
  background: transparent;
  border: none;
  border-radius: 7px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--testo-scuro-tenue);
}
.segmento:hover { color: var(--testo-scuro); }
.segmento.attivo { background: var(--blu); color: #fff; }

/* ─────────────── Chat ─────────────── */

.chat {
  position: absolute;
  right: var(--s2);
  bottom: calc(var(--s2) + 76px + env(safe-area-inset-bottom));
  top: var(--s2);
  width: min(320px, calc(100vw - var(--s2) * 2));
  display: flex;
  flex-direction: column;
  background: var(--scuro-alto);
  border: 1px solid var(--bordo-scuro);
  border-radius: var(--raggio-grande);
  box-shadow: var(--ombra-alta);
  overflow: hidden;
  z-index: 9;
}

.chat-testa {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s2) var(--s2) var(--s1);
}

.chat-testa .etichetta { margin: 0; color: var(--testo-scuro-tenue); }

.chiudi {
  width: 28px;
  height: 28px;
  background: transparent;
  border: none;
  border-radius: 999px;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--testo-scuro-tenue);
}
.chiudi:hover { background: var(--scuro-piu); color: var(--testo-scuro); }

.chat-lista {
  flex: 1;
  overflow-y: auto;
  padding: var(--s1) var(--s2);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-messaggio { max-width: 88%; }
.chat-messaggio.mio { align-self: flex-end; text-align: right; }

.chat-meta {
  margin: 0 0 3px;
  font-size: 0.6875rem;
  color: var(--inchiostro-fioco);
}

.chat-testo {
  margin: 0;
  padding: 8px 11px;
  background: var(--scuro-piu);
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.chat-messaggio.mio .chat-testo { background: var(--blu); color: #fff; }

.chat-form {
  display: flex;
  gap: var(--s1);
  padding: var(--s2);
  border-top: 1px solid var(--bordo-scuro);
}

.chat-form .campo {
  flex: 1;
  min-width: 0;
  background: var(--scuro);
  border-color: var(--bordo-scuro);
  color: var(--testo-scuro);
}

.chat-form .btn { flex-shrink: 0; }
.chat-form .btn--solido { background: var(--blu); color: #fff; }

/* ─────────────── Preparazione dell'immagine ─────────────── */

.ritaglio {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: var(--s2);
  padding: var(--s2);
  padding-bottom: calc(var(--s2) + env(safe-area-inset-bottom));
  background: rgb(20 22 26 / 0.98);
  z-index: 22;
}

.ritaglio-testa { text-align: center; }
.ritaglio-testa .etichetta { margin: 0 0 4px; color: var(--testo-scuro-tenue); }

.ritaglio-aiuto {
  margin: 0 auto;
  max-width: 46ch;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--testo-scuro-tenue);
}

.ritaglio-tela {
  width: 100%;
  height: 100%;
  min-height: 0;
  /* Il trascinamento lo gestiamo noi: il browser non deve scorrere la pagina. */
  touch-action: none;
  cursor: grab;
  border-radius: var(--raggio);
}

.ritaglio-tela:active { cursor: grabbing; }

.ritaglio-comandi {
  display: grid;
  gap: var(--s2);
  justify-items: center;
}

/* Cinque forme non stanno su una riga di telefono: si dispongono da sole su
   due righe invece di schiacciarsi o traboccare. */
.segmenti--forme {
  grid-template-columns: repeat(auto-fit, minmax(76px, 1fr));
  width: min(480px, 100%);
}

.ritaglio-azioni {
  display: flex;
  gap: var(--s1);
  padding: 5px;
  background: var(--scuro-alto);
  border: 1px solid var(--bordo-scuro);
  border-radius: 999px;
}

.ritaglio-scelte {
  display: flex;
  gap: var(--s1);
  width: min(420px, 100%);
}

.ritaglio-scelte .btn { flex: 1; margin: 0; }

@media (max-width: 520px) {
  .ritaglio-aiuto { display: none; }
  .ritaglio-comandi { gap: var(--s1); }
}

/* ─────────────── La pausa ─────────────── */

.pausa {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--s3);
  background: rgb(20 22 26 / 0.97);
  backdrop-filter: blur(8px);
  z-index: 20;
}

.pausa-scena {
  display: grid;
  justify-items: center;
  gap: var(--s1);
  text-align: center;
  max-width: 34ch;
}

.pausa-scena .etichetta { margin: var(--s2) 0 0; color: var(--testo-scuro-tenue); }

.tazza {
  width: clamp(120px, 26vmin, 190px);
  height: auto;
  color: var(--ambra);
}

.tazza-corpo,
.tazza-manico,
.tazza-piatto {
  fill: none;
  stroke: var(--testo-scuro);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tazza-piatto { stroke-width: 5; }

.vapore path {
  fill: none;
  stroke: currentColor;
  stroke-width: 3.5;
  stroke-linecap: round;
  opacity: 0;
  /*
   * I riccioli salgono e sfumano. Solo traslazione, niente scaleY: uno
   * stiramento ha bisogno di sapere dove sta il proprio centro, e su un <path>
   * quel centro lo stabilisce transform-box: fill-box. Dove quella proprieta
   * non e supportata l'origine cade sull'angolo del viewBox e il tratto
   * schizza fuori dall'inquadratura: si vede la tazzina e il vapore sparisce.
   * Una traslazione invece non ha origine da calcolare, e si comporta uguale
   * ovunque.
   */
  animation: sale 3.4s ease-in-out infinite;
}

.vapore path:nth-child(2) { animation-delay: 0.6s; }
.vapore path:nth-child(3) { animation-delay: 1.2s; }

@keyframes sale {
  0%   { opacity: 0;    transform: translateY(8px); }
  25%  { opacity: 0.8; }
  65%  { opacity: 0.5; }
  100% { opacity: 0;    transform: translateY(-14px); }
}

/* Il conto alla rovescia: cifre a larghezza fissa, o a ogni secondo la riga
   ballerebbe. */
.pausa-conto {
  margin: 0;
  font-family: var(--mono);
  font-size: clamp(2.6rem, 12vmin, 4.4rem);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  line-height: 1;
  color: var(--testo-scuro);
}

.pausa-nota {
  margin: 0;
  font-size: 0.9375rem;
  color: var(--testo-scuro-tenue);
}

.pausa-nota--fioca { font-size: 0.8125rem; opacity: 0.7; margin-top: var(--s1); }

.pausa-scena .btn { margin-top: var(--s2); }

/* Via d'uscita discreta: durante quindici minuti di pausa qualcuno potrebbe
   dover chiudere, e non deve essere costretto a riprendere per farlo. */
.pausa-esci {
  margin-top: var(--s1);
  padding: 6px 10px;
  background: none;
  border: none;
  font-size: 0.8125rem;
  color: var(--testo-scuro-tenue);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.pausa-esci:hover { color: var(--rosso); }

/* Con la pausa in corso i comandi dei media non hanno senso. */
.comando:disabled { opacity: 0.3; cursor: not-allowed; }

/* ─────────────── Striscia e avvisi ─────────────── */

.striscia {
  position: absolute;
  left: 50%;
  top: var(--s2);
  transform: translateX(-50%);
  margin: 0;
  padding: 9px 16px;
  max-width: calc(100vw - var(--s3) * 2);
  background: rgb(30 33 39 / 0.94);
  backdrop-filter: blur(10px);
  border: 1px solid var(--bordo-scuro);
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
  text-align: center;
  z-index: 10;
}

.striscia.allarme { border-color: var(--rosso); color: #ffc9cf; }
.striscia.calma { border-color: var(--ambra); color: #ffe0b0; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--s4) + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  padding: 11px 18px;
  background: var(--inchiostro);
  color: var(--carta-alta);
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--ombra-alta);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}

#toast.visibile { opacity: 1; transform: translate(-50%, 0); }

/* Editor di testo della lavagna: appare esattamente dove si è toccato. */
.editor-testo {
  position: absolute;
  min-width: 140px;
  padding: 2px 6px;
  background: rgb(255 255 255 / 0.96);
  border: 2px solid var(--blu);
  border-radius: 6px;
  font-weight: 600;
  z-index: 7;
}

/* ─────────────── Adattamenti ─────────────── */

@media (max-width: 520px) {
  .schermata { padding: var(--s3) var(--s2); align-content: start; }

  /* Nove comandi devono stare in 390 punti senza scorrere: sotto il pollice,
     non dietro un trascinamento. */
  .comando { min-width: 38px; padding: 7px 3px; }
  .comando-testo { display: none; }
  .barra { padding-left: var(--s1); padding-right: var(--s1); }
  .barra-pillola { gap: 0; padding: 4px; }

  .pip-tessera { width: 88px; }
  .strumento { width: 36px; height: 36px; }

  /* In verticale il fondo dello schermo e conteso da due barre: i riquadri
     salgono in alto, dove c'e spazio libero. */
  .pip {
    top: calc(var(--s2) + env(safe-area-inset-top));
    bottom: auto;
  }

  .chat { left: var(--s2); width: auto; top: 25%; }
  .pannello { left: var(--s2); width: auto; }
  .pip.con-chat { display: none; }

  /* Con i riquadri in alto, gli strumenti si riprendono tutta la larghezza.
     Non ci stanno comunque tutti: la sfumatura a destra dice che si scorre,
     invece di lasciarli sembrare tagliati. */
  .strumenti-apri { right: var(--s2); }

  .strumenti {
    right: var(--s2);
    -webkit-mask-image: linear-gradient(to right, #000 90%, transparent 100%);
    mask-image: linear-gradient(to right, #000 90%, transparent 100%);
  }
}

/* Schermo basso e largo: il telefono in orizzontale, caso frequentissimo. */
@media (max-height: 460px) and (orientation: landscape) {
  .strumenti { bottom: calc(var(--s1) + 58px); right: var(--s2); }
  .strumenti-apri { bottom: calc(var(--s1) + 58px); right: var(--s2); }
  /* Di traverso lo spazio c'e in larghezza: i riquadri tornano di lato, in alto,
     per non finire sopra la barra degli strumenti. */
  .pip {
    top: calc(var(--s1) + env(safe-area-inset-top));
    bottom: auto;
    grid-auto-flow: column;
  }
  .pip-tessera { width: 78px; }
  .comando { min-width: 44px; padding: 5px; }
  .comando-testo { display: none; }
}

@media (min-width: 900px) {
  .pip-tessera { width: 168px; }
  .strumenti { gap: 6px; right: calc(var(--s2) + 184px); }
  .strumenti-apri { right: calc(var(--s2) + 184px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }

  /* Con il movimento ridotto resta una dissolvenza lenta, senza spostamenti:
     qualcosa deve pur dire che la scena e viva. Prima il vapore si congelava
     del tutto, ed era indistinguibile da un'animazione rotta. */
  .vapore path {
    opacity: 0.5;
    animation: respira 4s ease-in-out infinite !important;
  }

  @keyframes respira {
    0%, 100% { opacity: 0.25; }
    50%      { opacity: 0.6; }
  }
}
