/* ==========================================================
   isyCode – ambiente di programmazione
   ========================================================== */

body.app-isycode {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--sfondo-alt);
}

button {
  font: inherit;
}

/* Avviso se l'applicazione non riesce a partire */
.avviso-avvio {
  flex: none;
  padding: 0.8rem 1rem;
  background: #fde8e8;
  color: #8a1f1f;
  border-bottom: 1px solid #f3c2c2;
  font-size: 0.95rem;
}

/* ---------- Barra superiore ---------- */

.barra-app {
  flex: 0 0 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  background: #fff;
  border-bottom: 1px solid var(--bordo);
}

.barra-logo {
  display: flex;
  align-items: flex-end;
  gap: 0.15rem;
  text-decoration: none;
}

.barra-logo img {
  height: 26px;
  width: auto;
}

.barra-logo span {
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--blu);
  line-height: 1;
  padding-bottom: 2px;
}

/* Frase di benvenuto con il nome (cambia ogni tanto) */
.benvenuto {
  flex: 1;
  margin: 0 1.5rem;
  text-align: center;
  font-weight: 600;
  color: var(--testo-tenue);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity 0.4s;
}

.benvenuto strong {
  color: var(--blu);
}

.benvenuto.nascosto {
  opacity: 0;
}

@media (max-width: 700px) {
  .benvenuto {
    display: none;
  }
}

.barra-destra {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.pillola {
  border: 1px solid var(--bordo);
  background: var(--sfondo-alt);
  border-radius: 999px;
  padding: 0.3em 0.9em;
  cursor: pointer;
}

.pillola:hover {
  border-color: var(--blu);
}

.link-sito {
  text-decoration: none;
  font-weight: 500;
}

/* ---------- Struttura ---------- */

.app {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 0;
}

/* ---------- Colonna sinistra ---------- */

.laterale {
  display: grid;
  /* scheda, lezioni, divisore, progetti (o file della scheda): le due parti
     si cambiano trascinando il divisore (app.js imposta le variabili) */
  --spazio-lezioni: 1.3fr;
  --spazio-progetti: 1fr;
  grid-template-rows: auto minmax(70px, var(--spazio-lezioni)) auto minmax(70px, var(--spazio-progetti));
  background: #fff;
  border-right: 1px solid var(--bordo);
  min-height: 0;
}

/* Sotto il riquadro Scheda ci sono solo le sezioni che la scheda collegata possiede */
.laterale[data-sezioni="0"] {
  grid-template-rows: auto;
  align-content: start;
}

.laterale[data-sezioni="1"] {
  grid-template-rows: auto minmax(0, 1fr);
}

.pannello {
  padding: 1rem;
  border-bottom: 1px solid var(--bordo);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.pannello:last-child {
  border-bottom: 0;
}

.pannello h2 {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--testo-tenue);
  margin: 0 0 0.7rem;
}

.pannello-titolo {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pannello-titolo h2 {
  margin: 0;
}

.pannello-azioni {
  display: flex;
  gap: 0.25rem;
}

.pannello-percorsi,
.pannello-progetti,
.pannello-file {
  overflow: hidden;
}

/* Modalità avanzata: l'albero dei file della scheda al posto dei progetti */
.pannello-file {
  padding-bottom: 0.4rem;
}

.pannello-file .gf-azioni {
  padding: 0;
}

.pannello-file .gf-cartella {
  padding: 0.35rem 0 0.4rem;
}

.pannello-file .gf-albero {
  padding: 0.3rem 0 0;
  font-size: 0.86rem;
}

.albero,
.lista-file {
  overflow-y: auto;
  min-height: 0;
  flex: 1;
}

/* Modello della scheda collegata, accanto a "Scheda" */
.modello-scheda {
  margin-left: 0.35rem;
  padding: 0.1em 0.55em;
  border-radius: 999px;
  background: var(--blu-chiaro);
  color: var(--blu);
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: none;
}

/* Stato collegamento */
.stato-scheda {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.92rem;
  margin-bottom: 0.8rem;
}

.led-stato {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #b8bfca;
  flex: none;
}

.led-stato.collegata {
  background: var(--verde);
  box-shadow: 0 0 0 3px rgba(31, 157, 85, 0.2);
}

.led-stato.in-corso {
  background: var(--giallo);
  animation: pulsa 1s infinite;
}

.led-stato.esecuzione {
  background: var(--blu);
  animation: pulsa 0.8s infinite;
}

@keyframes pulsa {
  50% { opacity: 0.35; }
}

.comandi {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.btn-pieno {
  width: 100%;
  padding: 0.55em 1em;
}

.comandi-riga {
  display: grid;
  grid-template-columns: repeat(2, 1fr); /* Esegui e Ferma, larghi quanto Collega */
  gap: 0.4rem;
}

.btn-icona {
  padding: 0.5em 0.3em;
  border-radius: 8px;
  font-size: 0.85rem;
  background: var(--sfondo-alt);
  border: 1px solid var(--bordo);
  color: var(--testo);
}

.btn-icona:hover:not(:disabled) {
  border-color: var(--blu);
}

.btn-verde:not(:disabled) {
  background: var(--verde);
  border-color: var(--verde);
  color: #fff;
}

/* Mentre il programma viene inviato alla scheda: Esegui arancione con la rotella */
.btn-esegui-invio,
.btn-verde.btn-esegui-invio:not(:disabled) {
  background: #f08c00;
  border-color: #f08c00;
  color: #fff;
  opacity: 1;
}

.btn-esegui-invio .icona-esegui {
  display: inline-block;
  width: 0.8em;
  height: 0.8em;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  border-radius: 50%;
  color: transparent;
  overflow: hidden;
  vertical-align: -0.1em;
  animation: gira 0.7s linear infinite;
}

@keyframes gira {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn-esegui-invio .icona-esegui {
    animation-duration: 2s;
  }
}

.btn-rosso:not(:disabled) {
  background: var(--rosso);
  border-color: var(--rosso);
  color: #fff;
}

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

/* Menu "Collega" */
.menu-collega {
  position: relative;
}

.tendina {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 20;
  background: #fff;
  border: 1px solid var(--bordo);
  border-radius: 8px;
  box-shadow: var(--ombra);
  overflow: hidden;
}

.tendina button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.6rem 0.9rem;
  border: 0;
  background: none;
  cursor: pointer;
}

.tendina button:hover:not(:disabled) {
  background: var(--blu-chiaro);
}

.tendina button:disabled {
  color: var(--testo-tenue);
  cursor: not-allowed;
}

.btn-mini {
  border: 1px solid var(--bordo);
  background: #fff;
  border-radius: 6px;
  width: 28px;
  height: 28px;
  cursor: pointer;
  line-height: 1;
}

.btn-mini:hover {
  border-color: var(--blu);
  color: var(--blu);
}

/* Albero lezioni/story */
.albero details {
  margin-bottom: 0.2rem;
}

.albero summary {
  cursor: pointer;
  padding: 0.35rem 0.3rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.93rem;
  list-style: none;
  user-select: none;
}

.albero summary::-webkit-details-marker {
  display: none;
}

.albero summary::before {
  content: "▸";
  display: inline-block;
  width: 1em;
  transition: transform 0.15s;
  color: var(--testo-tenue);
}

.albero details[open] > summary::before {
  transform: rotate(90deg);
}

.albero summary:hover {
  background: var(--sfondo-alt);
}

.albero details details {
  margin-left: 0.9rem;
}

.albero details details summary {
  font-weight: 500;
}

.albero ul {
  list-style: none;
  margin: 0 0 0.3rem 1.9rem;
  padding: 0;
}

.voce {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  padding: 0.3rem 0.45rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--testo);
}

.voce:hover {
  background: var(--sfondo-alt);
}

.voce.attiva {
  background: var(--blu-chiaro);
  color: var(--blu-scuro);
  font-weight: 600;
}

.voce .spunta {
  margin-left: auto;
  color: var(--verde);
}

/* Lista progetti */
.lista-file {
  list-style: none;
  margin: 0.6rem 0 0;
  padding: 0;
}

.lista-file li {
  display: flex;
  align-items: center;
}

.lista-file .voce {
  flex: 1;
}

.lista-file .elimina,
.lista-file .esporta {
  visibility: hidden;
  border: 0;
  background: none;
  cursor: pointer;
  color: var(--testo-tenue);
  padding: 0.2rem 0.4rem;
}

.lista-file li:hover .elimina,
.lista-file li:hover .esporta,
.lista-file li:focus-within .elimina,
.lista-file li:focus-within .esporta {
  visibility: visible;
}

.lista-file .esporta:hover {
  color: var(--blu);
}

.lista-file .elimina:hover {
  color: var(--rosso);
}

.lista-vuota {
  color: var(--testo-tenue);
  font-size: 0.88rem;
  padding: 0.3rem;
}

/* ---------- Area di lavoro ---------- */

.lavoro {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.barra-strumenti {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.55rem 1rem;
  background: #fff;
  border-bottom: 1px solid var(--bordo);
}

/* Editor: nome del file, Blocchi/Python al centro, Console */
.lavoro .barra-strumenti {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(max-content, 1fr);
}

.lavoro .pulsanti-console {
  justify-self: end;
}

@media (max-width: 700px) {
  .lavoro .barra-strumenti {
    display: flex;
    flex-wrap: wrap;
  }

  .lavoro .documento {
    flex-basis: 100%;
  }
}

.documento {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  flex: 1;
}

.documento strong {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-tipo {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.15em 0.6em;
  border-radius: 999px;
  background: var(--blu-chiaro);
  color: var(--blu);
}

.doc-tipo:empty {
  display: none;
}

.schede-modo {
  display: flex;
  background: var(--sfondo-alt);
  border: 1px solid var(--bordo);
  border-radius: 999px;
  padding: 3px;
}

.schede-modo button {
  border: 0;
  background: none;
  padding: 0.35em 1em;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 500;
  color: var(--testo-tenue);
}

.schede-modo button[aria-selected="true"] {
  background: #fff;
  color: var(--blu);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.schede-modo button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* Sta tra Collega/Scollega ed Esegui/Ferma, con lo spazio di due righe fisso:
   i pulsanti non devono spostarsi quando cambia il messaggio */
.stato-sync {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 2.5em;
  flex: none;
  text-align: center;
  text-wrap: balance;
  font-size: 0.8rem;
  line-height: 1.25;
  color: var(--testo-tenue);
}

/* Nel gestore dei file non vale: riguarda il programma dell'editor */
.app:has(.gestore-file:not([hidden])) .stato-sync {
  visibility: hidden;
}

.stato-sync.ok { color: var(--verde); }
.stato-sync.in-corso { color: #b07800; }
.stato-sync.errore { color: var(--rosso); }

/* Consegna lezione */
.consegna {
  display: grid;
  grid-template-columns: 1fr minmax(200px, 320px);
  gap: 1.2rem;
  padding: 0.9rem 1rem;
  background: #fffaf0;
  border-bottom: 1px solid #f3e2bb;
}

.consegna h3 {
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

.consegna p {
  margin: 0;
  font-size: 0.92rem;
  color: #4a4f57;
}

.consegna-obiettivo span {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #a06a00;
}

.consegna .esito {
  margin-top: 0.5rem;
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.88rem;
  width: fit-content;
}

.consegna .esito.superata {
  background: #e3f6ea;
  color: var(--verde);
}

.consegna .esito.non-superata {
  background: #fde8e8;
  color: var(--rosso);
}

.consegna .esito.attesa {
  background: #eef1f6;
  color: var(--testo-tenue);
}

/* Editor */
.editor {
  flex: 1;
  position: relative;
  min-height: 0;
}

.vista {
  position: absolute;
  inset: 0;
}

.vista[hidden] {
  display: none;
}

.vista-blocchi {
  display: grid;
}

#area-blockly {
  position: relative;
  min-width: 0;
}

#editor-python {
  height: 100%;
}

.vista-python {
  background: #fff;
}

.CodeMirror {
  height: 100%;
  font-family: var(--font-mono);
  font-size: var(--dimensione-codice, 14px);
}

.vista-vuota {
  display: grid;
  place-items: center;
  color: var(--testo-tenue);
}

/* Console: uno o due riquadri affiancati, alti quanto dice --altezza-console */
.area-console {
  flex: 0 0 var(--altezza-console, 170px);
  /* Per alta che sia stata scelta, lascia sempre un po' di editor */
  max-height: calc(100% - 150px);
  display: flex;
  min-height: 0;
  background: #10151d;
  border-top: 1px solid #000;
}

.console {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  color: #d7dde8;
}

/* Riga di separazione solo quando ci sono davvero due console */
.console:not([hidden]) + .console {
  border-left: 1px solid #2b3442;
}

@media (max-width: 700px) {
  .area-console {
    flex-direction: column;
  }

  .console:not([hidden]) + .console {
    border-left: 0;
    border-top: 1px solid #2b3442;
  }
}

.console-barra {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.3rem 0.8rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #8a93a3;
  border-bottom: 1px solid #222a36;
}

.console-barra .btn-mini {
  background: transparent;
  border-color: #2b3442;
  width: 24px;
  height: 24px;
}

.console-uscita {
  flex: 1;
  margin: 0;
  padding: 0.5rem 0.8rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  font-family: var(--font-mono);
  font-size: var(--dimensione-console, 13px);
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.console-uscita:focus-visible {
  outline: 1px solid #3b82f6;
  outline-offset: -1px;
}

/* Console vuota: si dice che cosa ci comparirà (data-vuota nell'HTML) */
.console-uscita:empty::before {
  content: attr(data-vuota);
  color: #6b7382;
  font-family: var(--font);
  font-style: italic;
}

.console-uscita .err { color: #ff7b7b; }
.console-uscita .info { color: #7aa2f7; }

/* ---------- Console del collegamento (dati e pacchetti) ---------- */

/* Le righe della console del collegamento sono lunghe: un po' più di spazio */
.console-collegamento {
  flex: 1.4 1 0;
}

.console-collegamento-uscita {
  white-space: normal;
}

.riga-traccia {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.5em;
  padding: 1px 0;
}

.riga-traccia .ora { color: #6b7382; }
.riga-traccia .verso { color: #d7dde8; font-weight: 700; }
.riga-traccia .nome { color: #7aa2f7; }
.riga-traccia .argomento { color: #8a93a3; }
.riga-traccia .byte { color: #8a93a3; }

/* Dati in chiaro: a capo, rientrati, su tutta la riga */
.riga-traccia .carico {
  /* Tutta la riga meno il rientro: col margine, 100% uscirebbe dal riquadro */
  flex: 1 0 calc(100% - 1.6em);
  margin: 0 0 0.15rem 1.6em;
  color: #c3e88d;
  white-space: pre-wrap;
  word-break: break-all;
}

.riga-traccia.verso-invio .verso { color: #e0af68; }
.riga-traccia.verso-arrivo .verso { color: #9ece6a; }
.riga-traccia.verso-nota { color: #8a93a3; }
.riga-traccia.verso-nota .nome { color: #8a93a3; }

/* ---------- Finestre di dialogo ---------- */

.dialogo {
  border: 0;
  border-radius: 14px;
  padding: 1.5rem;
  width: min(420px, 92vw);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.dialogo::backdrop {
  background: rgba(15, 20, 30, 0.45);
}

.dialogo h3 {
  margin-top: 0;
}

.dialogo input[type="text"] {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--bordo);
  border-radius: 8px;
  font: inherit;
}

.dialogo input[type="text"]:focus {
  outline: 2px solid var(--blu);
  border-color: transparent;
}

.dialogo fieldset {
  border: 0;
  padding: 0;
  margin: 1rem 0 0;
  display: flex;
  gap: 1.2rem;
}

.dialogo legend {
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.dialogo .nota {
  font-size: 0.85rem;
  color: var(--testo-tenue);
}

.dialogo-azioni {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1.2rem;
}

/* ---------- Schermi piccoli ---------- */

@media (max-width: 900px) {
  .app {
    grid-template-columns: 230px 1fr;
  }

}

/* ---------- Scelta tra versione del browser e della scheda ---------- */

.dialogo-versioni-azioni {
  flex-wrap: wrap;
}

/* ---------- Divisore tra lezioni e progetti ---------- */

.divisore-laterale {
  height: 9px;
  margin: -4px 0;
  position: relative;
  z-index: 2;
  cursor: row-resize;
  touch-action: none;
}

.divisore-laterale::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 3px;
  width: 36px;
  height: 3px;
  margin-left: -18px;
  border-radius: 3px;
  background: var(--bordo);
  transition: background 0.15s;
}

.divisore-laterale:hover::after,
.divisore-laterale:focus-visible::after,
.divisore-laterale.trascina::after {
  background: var(--blu);
}

.divisore-laterale:focus-visible {
  outline: none;
}

/* ---------- Divisore sopra la console (altezza della console) ---------- */

.divisore-console {
  flex: none;
  height: 9px;
  margin-bottom: -4px;
  position: relative;
  z-index: 2;
  cursor: row-resize;
  touch-action: none;
}

.divisore-console::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 3px;
  width: 46px;
  height: 3px;
  margin-left: -23px;
  border-radius: 3px;
  background: var(--bordo);
  transition: background 0.15s;
}

.divisore-console:hover::after,
.divisore-console:focus-visible::after,
.divisore-console.trascina::after {
  background: var(--blu);
}

.divisore-console:focus-visible {
  outline: none;
}

/* ---------- Avviso nel pannello della scheda ---------- */

.stato-avviso {
  margin: -0.3rem 0 0.8rem;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  background: #fde8e8;
  color: #8a1f1f;
  font-size: 0.82rem;
  line-height: 1.4;
}

/* ---------- Pulsanti delle console ---------- */

.pulsanti-console {
  display: flex;
  gap: 0.4rem;
}

.btn-console {
  position: relative;
  border: 1px solid var(--bordo);
  background: #fff;
  border-radius: 999px;
  padding: 0.3em 0.9em;
  cursor: pointer;
  font-size: 0.88rem;
  white-space: nowrap;
}

.btn-console:hover,
.btn-console[aria-pressed="true"] {
  border-color: var(--blu);
  color: var(--blu);
}

.btn-console[aria-pressed="true"] {
  background: var(--blu-chiaro);
}

.novita {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--blu);
  border: 2px solid #fff;
}

.novita.errore {
  background: var(--rosso);
}

.console-barra > div {
  display: flex;
  gap: 0.3rem;
}

.btn-piccolo {
  padding: 0.35em 0.9em;
  font-size: 0.88rem;
}

/* ---------- File della scheda (modalità avanzata) ---------- */

.gestore-file {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.gf-azioni {
  display: flex;
  gap: 0.3rem;
  padding: 0.6rem 0.8rem 0.3rem;
}

.gf-azioni .btn-mini {
  width: auto;
  padding: 0 0.5rem;
}

.gf-cartella {
  margin: 0;
  padding: 0 0.8rem 0.5rem;
  font-size: 0.8rem;
  color: var(--testo-tenue);
  border-bottom: 1px solid var(--bordo);
}

.gf-albero {
  list-style: none;
  margin: 0;
  padding: 0.4rem;
  overflow: auto;
  flex: 1;
  font-size: 0.9rem;
}

.gf-albero button {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  width: 100%;
  border: 0;
  background: none;
  text-align: left;
  padding: 0.22rem 0.4rem;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  color: var(--testo);
}

.gf-albero button:hover {
  background: var(--sfondo-alt);
}

.gf-albero button.attiva {
  background: var(--blu-chiaro);
  color: var(--blu-scuro);
  font-weight: 600;
}

.gf-albero .freccia {
  width: 0.7em;
  flex: none;
  font-size: 0.75em;
  color: var(--testo-tenue);
}

.gf-albero .lista-vuota {
  font-size: 0.85rem;
}

.gf-albero .dimensione {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--testo-tenue);
}

.gf-albero .sistema {
  color: #a06a00;
}

.gf-dettaglio {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: #fff;
}

.gf-file-barra {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid var(--bordo);
}

.gf-file-barra code {
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 40%;
}

.gf-modificato {
  color: #b07800;
  font-size: 0.82rem;
}

.gf-file-azioni {
  display: flex;
  gap: 0.35rem;
  margin-left: auto;
}

.gf-file-azioni .btn-icona {
  padding: 0.35em 0.7em;
}

.gf-editor {
  flex: 1;
  min-height: 0;
}

.gf-editor[hidden] {
  display: none;
}

.gf-messaggio {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 2rem;
  text-align: center;
  color: var(--testo-tenue);
}

.gf-messaggio[hidden] {
  display: none;
}

/* ---------- Impostazioni ---------- */

.dialogo-largo {
  width: min(560px, 94vw);
  max-height: 90vh;
}

.dialogo fieldset.gruppo {
  display: block;
  border: 1px solid var(--bordo);
  border-radius: 10px;
  padding: 0.6rem 1rem 0.8rem;
  margin: 0.9rem 0 0;
}

.dialogo fieldset.gruppo:disabled {
  opacity: 0.55;
}

.dialogo fieldset.gruppo label {
  display: block;
  margin-top: 0.6rem;
  font-size: 0.92rem;
}

.dialogo select {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--bordo);
  border-radius: 8px;
  font: inherit;
  background: #fff;
}

.dialogo .spunta-riga {
  display: flex !important;
  align-items: center;
  gap: 0.5rem;
}

.dialogo .spunta-riga input {
  width: 18px;
  height: 18px;
  accent-color: var(--blu);
}

.dialogo .gruppo .nota {
  margin: 0.4rem 0 0;
}

.facoltativo {
  color: var(--testo-tenue);
  font-size: 0.85em;
}

/* ---------- Collegamento via rete ---------- */

.dialogo input[type="password"] {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--bordo);
  border-radius: 8px;
  font: inherit;
}

.dialogo .campo-codice {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  letter-spacing: 0.15em;
  text-align: center;
  text-transform: uppercase;
}

.dialogo .nota.errore {
  color: var(--rosso);
}

/* Elenco delle categorie di Blockly (LED, Pulsanti, Suono...): stesso carattere del sito */
.blocklyToolboxCategoryLabel,
.blocklyTreeLabel {
  font-family: var(--font) !important;
}

/* ---------- Monitor seriale (in fondo alla console della scheda) ---------- */

.monitor {
  flex: none;
  display: flex;
  flex-wrap: wrap; /* console stretta: spunta e pulsante vanno sotto */
  align-items: center;
  gap: 0.3rem 0.5rem;
  padding: 0.3rem 0.5rem 0.4rem 0.8rem;
  border-top: 1px solid #222a36;
}

.monitor-testo {
  flex: 1 1 150px;
  min-width: 0;
  padding: 0.3rem 0.55rem;
  border: 1px solid #2b3442;
  border-radius: 6px;
  background: #0b0f15;
  color: #d7dde8;
  font-family: var(--font-mono);
  font-size: var(--dimensione-console, 13px);
}

.monitor-testo::placeholder {
  color: #6b7382;
  font-family: var(--font);
  font-style: italic;
}

.monitor-testo:focus {
  outline: none;
  border-color: #3b82f6;
}

.monitor-testo:disabled {
  opacity: 0.6;
}

.monitor-spunta {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.78rem;
  color: #8a93a3;
  white-space: nowrap;
  cursor: pointer;
}

.monitor-invia {
  padding: 0.28rem 0.8rem;
  border: 1px solid #3b82f6;
  border-radius: 6px;
  background: #1b5fd1;
  color: #fff;
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
}

.monitor-invia:hover:not(:disabled) {
  background: #2f6fe0;
}

.monitor-invia:disabled {
  border-color: #2b3442;
  background: transparent;
  color: #6b7382;
  cursor: default;
}

/* ---------- Controller: analogico, levette e pulsanti ---------- */

/* Finestrella che galleggia sulla pagina: si sposta dalla barra (app.js, finestraController).
   --lato è il lato dell'analogico e comanda la dimensione di tutto il resto. */
.controller {
  --lato: 150px;
  position: fixed;
  z-index: 50;
  left: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  background: #10151d;
  color: #d7dde8;
  border: 1px solid #2b3442;
  border-radius: 12px;
  box-shadow: 0 12px 36px rgba(10, 20, 40, 0.35), 0 2px 6px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}

.controller-barra {
  gap: 0.8rem;
  cursor: move;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  background: #161d28;
}

.controller.trascina {
  box-shadow: 0 18px 48px rgba(10, 20, 40, 0.45), 0 2px 6px rgba(0, 0, 0, 0.25);
}

.controller.trascina,
.controller.trascina * {
  cursor: grabbing !important;
}

/* Angolo in basso a destra: si trascina per ingrandire o rimpicciolire */
.controller-angolo {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
  touch-action: none;
  background: linear-gradient(135deg, transparent 50%, #3a4558 50%, #3a4558 58%, transparent 58%,
    transparent 70%, #3a4558 70%, #3a4558 78%, transparent 78%);
}

.controller-angolo:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: -2px;
}

.controller-stato {
  margin-left: 0.4em;
  padding: 0.05em 0.6em;
  border-radius: 999px;
  border: 1px solid #2b3442;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.controller-stato[data-stato="esecuzione"] { color: #e0b252; border-color: #5a4a26; }
.controller-stato[data-stato="ascolto"] { color: #5fd38d; border-color: #24533a; }

.controller-corpo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(var(--lato) * 0.12);
  padding: 0.7rem 1.2rem 0.8rem;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: opacity 0.2s;
}

.controller-corpo.spento {
  opacity: 0.4;
}

.controller-corpo.spento * {
  cursor: not-allowed !important;
}

.ctrl-zona {
  display: flex;
  align-items: center;
}

/* Analogico */
.ctrl-zona-analogico {
  flex-direction: column;
  gap: 0.15rem;
}

.ctrl-analogico {
  --pomello: calc(var(--lato) * 0.42);
  position: relative;
  width: calc(var(--lato) - 14px);
  height: calc(var(--lato) - 14px);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, #232c3a, #151b24 70%);
  border: 2px solid #2b3442;
  box-shadow: inset 0 3px 10px rgba(0, 0, 0, 0.6);
  cursor: grab;
  touch-action: none;
}

.ctrl-analogico:focus-visible,
.ctrl-binario:focus-visible,
.ctrl-pulsante:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

.ctrl-croce {
  position: absolute;
  inset: 18%;
  background:
    linear-gradient(#2b3442, #2b3442) center / 1px 100% no-repeat,
    linear-gradient(#2b3442, #2b3442) center / 100% 1px no-repeat;
  pointer-events: none;
}

.ctrl-pomello {
  --x: 0;
  --y: 0;
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--pomello);
  height: var(--pomello);
  margin: calc(var(--pomello) / -2) 0 0 calc(var(--pomello) / -2);
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #6d8fd6, #1b5fd1 60%, #123f8c);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.55);
  /* Il centro del pomello arriva fino a un quarto del pomello dal bordo (come in controller.js) */
  transform: translate(
    calc(var(--x) * ((var(--lato) - 14px) / 2 - var(--pomello) / 4)),
    calc(var(--y) * ((var(--lato) - 14px) / 2 - var(--pomello) / 4))
  );
  transition: transform 0.12s ease-out;
  pointer-events: none;
}

.ctrl-analogico.trascina {
  cursor: grabbing;
}

.ctrl-analogico.trascina .ctrl-pomello {
  transition: none;
}

.ctrl-lettura {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: #8a93a3;
  white-space: pre;
}

/* Levette */
.ctrl-levette {
  gap: 0.7rem;
}

.ctrl-levetta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.ctrl-binario {
  position: relative;
  width: 30px;
  height: calc(var(--lato) - 30px);
  border-radius: 15px;
  background: #0b0f15;
  border: 2px solid #2b3442;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.6);
  cursor: pointer;
  touch-action: none;
}

/* Tacche delle posizioni */
.ctrl-binario::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 12px;
  bottom: 12px;
  width: 2px;
  margin-left: -1px;
  background: #2b3442;
}

.ctrl-binario[data-posizioni="3"]::after {
  content: "";
  position: absolute;
  left: 6px;
  right: 6px;
  top: 50%;
  height: 2px;
  margin-top: -1px;
  background: #2b3442;
}

.ctrl-leva {
  --pos: 0;
  position: absolute;
  left: 1px;
  right: 1px;
  height: 22px;
  /* 0 in basso, 1 in alto */
  bottom: calc(1px + var(--pos) * (100% - 24px));
  border-radius: 11px;
  background: linear-gradient(#e7ebf2, #a9b2c2);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.6);
  transition: bottom 0.1s ease-out;
  pointer-events: none;
}

.ctrl-levetta-valore {
  max-width: 44px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: #d7dde8;
}

/* Pulsanti */
.ctrl-pulsanti {
  --tasto: clamp(30px, calc((var(--lato) - 16px) / 2), 120px);
  display: grid;
  grid-template-columns: repeat(3, var(--tasto));
  gap: 10px 12px;
}

.ctrl-pulsante {
  width: var(--tasto);
  height: var(--tasto);
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.35);
  background: var(--colore);
  color: #fff;
  font-family: var(--font-mono);
  font-size: calc(var(--tasto) * 0.3);
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.45), inset 0 2px 3px rgba(255, 255, 255, 0.25);
  cursor: pointer;
  touch-action: none;
  transition: transform 0.05s, box-shadow 0.05s;
}

.ctrl-pulsante-testo {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 4px;
}

.ctrl-pulsante.premuto {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.45), inset 0 2px 6px rgba(0, 0, 0, 0.35);
  filter: brightness(1.15);
}

.ctrl-pulsante-1 { --colore: #d64545; }
.ctrl-pulsante-2 { --colore: #e08a1e; }
.ctrl-pulsante-3 { --colore: #c9a400; }
.ctrl-pulsante-4 { --colore: #1f9d55; }
.ctrl-pulsante-5 { --colore: #1b5fd1; }
.ctrl-pulsante-6 { --colore: #7b4fd6; }


/* Finestra ⚙ del controller */
.ctrl-tabella {
  width: 100%;
  border-collapse: collapse;
}

.ctrl-tabella th {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--testo-tenue);
  text-align: left;
  padding: 0.2rem 0.4rem;
}

.ctrl-tabella td {
  padding: 0.2rem 0.4rem;
}

.dialogo .ctrl-tabella input[type="text"] {
  margin: 0;
  font-family: var(--font-mono);
}

.dialogo .ctrl-tabella input[type="text"]:disabled {
  opacity: 0.4;
}

.dialogo .ctrl-tabella select {
  margin: 0;
  width: auto;
}

.ctrl-pallino {
  display: inline-grid;
  place-items: center;
  width: 1.6em;
  height: 1.6em;
  border-radius: 50%;
  background: var(--colore);
  color: #fff;
  font-weight: 700;
}

.dialogo-sinistra {
  margin-right: auto;
}

.dialogo .ctrl-tabella input[type="text"],
.dialogo .ctrl-tabella select {
  padding: 0.35rem 0.5rem;
}
