/* =====================================================================
   ScuolaGames - tema "quaderno a quadretti"
   Il mondo del gioco è il quaderno di scuola: carta a quadretti,
   inchiostro blu, pastelli, figurine adesive e il timbro della maestra.
   ===================================================================== */

:root {
  --sg-carta: #FBFDFF;
  --sg-quadretto: #D9E6F6;
  --sg-margine: #FF8A8A;          /* riga rossa del margine */
  --sg-inchiostro: #1D3E8A;       /* blu penna: testo principale */
  --sg-inchiostro-2: #4E68A8;
  --sg-matita: #8A94A6;
  --sg-rosso: #FF5A5F;
  --sg-giallo: #FFC93C;
  --sg-verde: #2FB36E;
  --sg-viola: #7B5CFF;
  --sg-oro: #F5B800;
  --sg-bianco: #FFFFFF;
  --sg-ombra-figurina: 0 3px 0 rgba(29, 62, 138, .18), 0 10px 22px rgba(29, 62, 138, .14);

  --sg-materia: #4D96FF;           /* sovrascritti a runtime dalla materia */
  --sg-materia-2: #6BCBFF;

  --sg-font-titoli: "Baloo 2", "Arial Rounded MT Bold", system-ui, sans-serif;
  --sg-font-testo: "Andika", "Segoe UI", system-ui, sans-serif;  /* Andika: font per chi impara a leggere */

  --sg-raggio-s: 14px;
  --sg-raggio-m: 22px;
  --sg-raggio-l: 32px;
  --sg-tocco: 68px;                /* dimensione minima dei bottoni da toccare */
  --sg-hud-h: 76px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body.sg {
  margin: 0;
  overflow: hidden;
  font-family: var(--sg-font-testo);
  font-size: 1.15rem;
  line-height: 1.5;
  color: var(--sg-inchiostro);
  background-color: var(--sg-carta);
  background-image:
    linear-gradient(var(--sg-quadretto) 1px, transparent 1px),
    linear-gradient(90deg, var(--sg-quadretto) 1px, transparent 1px);
  background-size: 28px 28px;
  background-position: -1px -1px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

body.sg::before {               /* margine rosso del quaderno */
  content: "";
  position: fixed;
  top: 0; bottom: 0; left: 56px;
  width: 2px;
  background: var(--sg-margine);
  opacity: .55;
  pointer-events: none;
  z-index: 0;
}

.sg h1, .sg h2, .sg h3, .sg .sg-titolo {
  font-family: var(--sg-font-titoli);
  font-weight: 800;
  line-height: 1.05;
  margin: 0;
  letter-spacing: -.01em;
}

.sg :focus-visible {
  outline: 4px solid var(--sg-viola);
  outline-offset: 4px;
}

/* ---------------------------------------------------------------------
   Contenitore app e schermate
   --------------------------------------------------------------------- */
#sg-app { position: fixed; inset: 0; z-index: 1; display: flex; flex-direction: column; }

.sg-stage {
  position: relative;
  flex: 1;
  overflow: hidden;
}

.sg-screen {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 24px 40px 80px;  /* lascia libero il margine rosso */
  display: flex;
  flex-direction: column;
  align-items: center;
  -webkit-overflow-scrolling: touch;
}

.sg-screen[hidden] { display: none !important; }

.sg-screen.entra   { animation: sg-entra .42s cubic-bezier(.2, .9, .3, 1.2) both; }
.sg-screen.esce    { animation: sg-esce .28s ease-in both; pointer-events: none; }
.sg-screen.indietro.entra { animation-name: sg-entra-sx; }
.sg-screen.indietro.esce  { animation-name: sg-esce-dx; }

@keyframes sg-entra    { from { opacity: 0; transform: translateX(60px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes sg-esce     { to   { opacity: 0; transform: translateX(-60px) scale(.98); } }
@keyframes sg-entra-sx { from { opacity: 0; transform: translateX(-60px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes sg-esce-dx  { to   { opacity: 0; transform: translateX(60px) scale(.98); } }

.sg-wrap { width: 100%; max-width: 1080px; }

.sg-intestazione { width: 100%; max-width: 1080px; display: flex; align-items: center; gap: 16px; margin: 4px 0 24px; }
.sg-intestazione h1 { font-size: clamp(2rem, 4.4vw, 3.2rem); }
.sg-intestazione p  { margin: 4px 0 0; color: var(--sg-inchiostro-2); }

/* ---------------------------------------------------------------------
   HUD (barra in alto)
   --------------------------------------------------------------------- */
.sg-hud {
  height: var(--sg-hud-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px 10px 80px;
  position: relative;
  z-index: 5;
}
.sg-hud[hidden] { display: none; }

.sg-hud .sg-spazio { flex: 1; }

.sg-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 52px;
  padding: 0 16px 0 8px;
  border-radius: 999px;
  background: var(--sg-bianco);
  border: 3px solid var(--sg-inchiostro);
  box-shadow: 0 3px 0 var(--sg-inchiostro);
  font-family: var(--sg-font-titoli);
  font-weight: 800;
  font-size: 1.25rem;
  white-space: nowrap;
}
.sg-chip .sg-chip-ico { font-size: 1.6rem; line-height: 1; }
.sg-chip .sg-avatar-mini { width: 40px; height: 40px; }

.sg-chip-livello small { font-family: var(--sg-font-testo); font-weight: 700; font-size: .85rem; color: var(--sg-inchiostro-2); }

.sg-barra-livello { width: 90px; height: 10px; border-radius: 6px; background: var(--sg-quadretto); overflow: hidden; }
.sg-barra-livello > i { display: block; height: 100%; background: linear-gradient(90deg, var(--sg-giallo), var(--sg-oro)); border-radius: 6px; transition: width .8s cubic-bezier(.2,.9,.3,1); }

.sg-punti.pulsa { animation: sg-pulsa .6s ease; }
@keyframes sg-pulsa { 40% { transform: scale(1.18) rotate(-3deg); } }

.sg-icon-btn {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 3px solid var(--sg-inchiostro);
  background: var(--sg-bianco);
  box-shadow: 0 3px 0 var(--sg-inchiostro);
  font-size: 1.5rem;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  transition: transform .12s;
  color: var(--sg-inchiostro);
  padding: 0;
}
.sg-icon-btn:active { transform: translateY(3px); box-shadow: none; }
.sg-icon-btn[aria-pressed="false"] { opacity: .55; }

/* ---------------------------------------------------------------------
   Bottoni
   --------------------------------------------------------------------- */
.sg-btn {
  min-height: var(--sg-tocco);
  padding: 10px 30px;
  border: 3px solid var(--sg-inchiostro);
  border-radius: var(--sg-raggio-m);
  background: var(--sg-giallo);
  color: var(--sg-inchiostro);
  font-family: var(--sg-font-titoli);
  font-weight: 800;
  font-size: 1.5rem;
  box-shadow: 0 5px 0 var(--sg-inchiostro);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: transform .1s, box-shadow .1s;
}
.sg-btn:active { transform: translateY(5px); box-shadow: 0 0 0 var(--sg-inchiostro); }
.sg-btn:disabled { opacity: .45; cursor: not-allowed; }
.sg-btn-secondario { background: var(--sg-bianco); }
.sg-btn-verde { background: var(--sg-verde); color: var(--sg-bianco); }
.sg-btn-grande { font-size: 2rem; min-height: 92px; padding: 14px 48px; border-radius: var(--sg-raggio-l); }

/* ---------------------------------------------------------------------
   Figurina (carta adesiva con bordo bianco, leggermente storta)
   --------------------------------------------------------------------- */
.sg-figurina {
  position: relative;
  background: var(--sg-bianco);
  border-radius: var(--sg-raggio-m);
  padding: 10px;
  box-shadow: var(--sg-ombra-figurina);
  transform: rotate(var(--rot, 0deg));
  transition: transform .18s cubic-bezier(.2,.9,.3,1.4);
  cursor: pointer;
  border: 0;
  text-align: center;
  color: var(--sg-inchiostro);
  font: inherit;
}
.sg-figurina:hover  { transform: rotate(0deg) translateY(-4px) scale(1.03); }
.sg-figurina:active { transform: rotate(0deg) scale(.97); }

.sg-figurina-dentro {
  border-radius: calc(var(--sg-raggio-m) - 6px);
  background: linear-gradient(160deg, var(--c1, var(--sg-materia)), var(--c2, var(--sg-materia-2)));
  color: var(--sg-bianco);
  padding: 18px 14px;
  min-height: 150px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  overflow: hidden;
  position: relative;
}
.sg-figurina-dentro img.sg-illustrazione { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.sg-figurina-dentro .sg-emoji-grande { font-size: 4rem; line-height: 1; filter: drop-shadow(0 4px 0 rgba(0,0,0,.15)); }
.sg-figurina .sg-nome {
  font-family: var(--sg-font-titoli);
  font-weight: 800;
  font-size: 1.45rem;
  margin-top: 10px;
  line-height: 1.1;
}
.sg-figurina .sg-sotto { font-size: .95rem; color: var(--sg-inchiostro-2); margin-top: 2px; }

.sg-griglia {
  width: 100%;
  max-width: 1080px;
  display: grid;
  gap: 28px;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

/* Classi: numeri giganti scritti a pennarello */
.sg-classe .sg-figurina-dentro { min-height: 180px; }
.sg-classe .sg-numero-classe {
  font-family: var(--sg-font-titoli);
  font-weight: 800;
  font-size: 6.5rem;
  line-height: .9;
  color: var(--sg-bianco);
  text-shadow: 0 6px 0 rgba(0,0,0,.14);
}

.sg-avanzamento { height: 12px; background: rgba(255,255,255,.35); border-radius: 8px; width: 80%; overflow: hidden; position: relative; z-index: 1; }
.sg-avanzamento > i { display: block; height: 100%; background: var(--sg-bianco); border-radius: 8px; }

.sg-in-arrivo { filter: grayscale(.7); opacity: .65; }
.sg-in-arrivo .sg-sotto::after { content: " · in arrivo"; }

/* ---------------------------------------------------------------------
   Splash / benvenuto
   --------------------------------------------------------------------- */
.sg-splash { justify-content: center; text-align: center; gap: 22px; }
.sg-logo {
  font-family: var(--sg-font-titoli);
  font-weight: 800;
  font-size: clamp(2.4rem, 12.5vw, 7.5rem);
  white-space: nowrap;
  line-height: .9;
  color: var(--sg-inchiostro);
  letter-spacing: -.03em;
}
.sg-logo span { display: inline-block; animation: sg-lettera 2.4s ease-in-out infinite; }
.sg-logo span:nth-child(odd)  { color: var(--sg-rosso); }
.sg-logo span:nth-child(3n)   { color: var(--sg-verde); }
.sg-logo span:nth-child(4n)   { color: var(--sg-viola); }
@keyframes sg-lettera { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-8px) rotate(-3deg); } }
.sg-logo span:nth-child(2) { animation-delay: .1s; }  .sg-logo span:nth-child(3) { animation-delay: .2s; }
.sg-logo span:nth-child(4) { animation-delay: .3s; }  .sg-logo span:nth-child(5) { animation-delay: .4s; }
.sg-logo span:nth-child(6) { animation-delay: .5s; }  .sg-logo span:nth-child(7) { animation-delay: .6s; }
.sg-logo span:nth-child(8) { animation-delay: .7s; }  .sg-logo span:nth-child(9) { animation-delay: .8s; }
.sg-logo span:nth-child(10) { animation-delay: .9s; } .sg-logo span:nth-child(11) { animation-delay: 1s; }

.sg-mascotte { width: min(260px, 50vw); height: auto; }
.sg-mascotte-emoji { font-size: clamp(6rem, 18vw, 10rem); line-height: 1; animation: sg-galleggia 3s ease-in-out infinite; }
@keyframes sg-galleggia { 50% { transform: translateY(-12px) rotate(4deg); } }

.sg-fumetto {
  position: relative;
  background: var(--sg-bianco);
  border: 3px solid var(--sg-inchiostro);
  border-radius: var(--sg-raggio-m);
  padding: 14px 22px;
  max-width: 560px;
  font-size: 1.3rem;
  box-shadow: 0 4px 0 var(--sg-inchiostro);
}
.sg-fumetto::after {
  content: "";
  position: absolute;
  left: 50%; bottom: -16px;
  width: 26px; height: 26px;
  background: var(--sg-bianco);
  border-right: 3px solid var(--sg-inchiostro);
  border-bottom: 3px solid var(--sg-inchiostro);
  transform: translateX(-50%) rotate(45deg);
}
.sg-fumetto.sopra::after { top: -16px; bottom: auto; transform: translateX(-50%) rotate(225deg); }

/* ---------------------------------------------------------------------
   Profilo: soprannome + avatar
   --------------------------------------------------------------------- */
.sg-campo {
  width: 100%;
  max-width: 520px;
  height: 76px;
  border: 3px solid var(--sg-inchiostro);
  border-radius: var(--sg-raggio-m);
  font-family: var(--sg-font-titoli);
  font-weight: 700;
  font-size: 2rem;
  text-align: center;
  color: var(--sg-inchiostro);
  background: var(--sg-bianco);
  box-shadow: inset 0 4px 0 rgba(29,62,138,.08);
  user-select: text;
}
.sg-campo::placeholder { color: var(--sg-matita); }

.sg-avatar-griglia { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; max-width: 620px; width: 100%; }
@media (max-width: 640px) { .sg-avatar-griglia { grid-template-columns: repeat(4, 1fr); } }

.sg-avatar-scelta {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 4px solid transparent;
  background: var(--sg-bianco);
  box-shadow: var(--sg-ombra-figurina);
  font-size: 2.6rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 0;
  transition: transform .15s;
}
.sg-avatar-scelta[aria-pressed="true"] { border-color: var(--sg-viola); transform: scale(1.1) rotate(-4deg); }
.sg-avatar-scelta img, .sg-avatar-mini img { width: 100%; height: 100%; object-fit: cover; }
.sg-avatar-mini { border-radius: 50%; overflow: hidden; display: inline-grid; place-items: center; font-size: 1.6rem; background: var(--sg-quadretto); }

.sg-codice-magico {
  font-family: var(--sg-font-titoli);
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: .18em;
  background: var(--sg-giallo);
  border: 3px dashed var(--sg-inchiostro);
  border-radius: var(--sg-raggio-s);
  padding: 6px 18px;
  user-select: all;
}

/* ---------------------------------------------------------------------
   Percorso (sentiero disegnato a matita)
   --------------------------------------------------------------------- */
.sg-percorso { width: 100%; max-width: 760px; position: relative; padding-bottom: 60px; }
.sg-percorso-unita { margin: 18px 0 8px; text-align: center; }
.sg-percorso-unita .sg-cartello {
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--sg-materia);
  color: var(--sg-bianco);
  font-family: var(--sg-font-titoli);
  font-weight: 800;
  font-size: 1.5rem;
  padding: 8px 22px;
  border-radius: 999px;
  border: 3px solid var(--sg-inchiostro);
  box-shadow: 0 4px 0 var(--sg-inchiostro);
}
.sg-percorso-unita p { margin: 8px 0 0; color: var(--sg-inchiostro-2); font-size: 1rem; }

.sg-sentiero { position: relative; display: flex; flex-direction: column; align-items: center; gap: 30px; padding: 40px 0 16px; }
.sg-sentiero svg.sg-linea { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.sg-sentiero svg.sg-linea path { fill: none; stroke: var(--sg-matita); stroke-width: 5; stroke-linecap: round; stroke-dasharray: 2 14; }

.sg-tappa {
  position: relative;
  z-index: 1;
  display: flex; flex-direction: column; align-items: center;
  border: 0; background: transparent; padding: 0;
  cursor: pointer;
  color: var(--sg-inchiostro);
  font: inherit;
  transform: translateX(calc(var(--x, 0px) * var(--xs, 1)));
}
.sg-tappa .sg-bollino {
  position: relative;
  width: 112px; height: 112px;
  border-radius: 50%;
  background: var(--sg-bianco);
  padding: 7px;
  box-shadow: var(--sg-ombra-figurina);
  transition: transform .18s cubic-bezier(.2,.9,.3,1.4);
}
.sg-tappa .sg-bollino > span {
  width: 100%; height: 100%;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 3rem;
  background: linear-gradient(160deg, var(--sg-materia), var(--sg-materia-2));
  overflow: hidden;
}
.sg-tappa .sg-bollino img { width: 100%; height: 100%; object-fit: cover; }
.sg-tappa:hover .sg-bollino { transform: scale(1.07) rotate(-4deg); }
.sg-tappa .sg-etichetta {
  margin-top: 8px;
  background: var(--sg-bianco);
  border: 2px solid var(--sg-inchiostro);
  border-radius: 12px;
  padding: 2px 12px;
  font-family: var(--sg-font-titoli);
  font-weight: 700;
  font-size: 1.1rem;
  max-width: 230px;
  text-align: center;
}
.sg-tappa .sg-stelline { font-size: 1.3rem; letter-spacing: 2px; height: 1.4em; }
.sg-tappa .sg-stelline .spenta { filter: grayscale(1); opacity: .3; }

.sg-tappa.bloccata { cursor: not-allowed; }
.sg-tappa.bloccata .sg-bollino > span { background: #C9D3E3; filter: grayscale(1); }
.sg-tappa.bloccata .sg-bollino::after {
  content: "🔒"; position: absolute; right: -2px; top: -2px; font-size: 1.8rem;
}
.sg-tappa.prossima .sg-bollino { animation: sg-chiama 1.6s ease-in-out infinite; }
@keyframes sg-chiama {
  0%, 100% { box-shadow: var(--sg-ombra-figurina), 0 0 0 0 rgba(255, 201, 60, .9); }
  50%      { box-shadow: var(--sg-ombra-figurina), 0 0 0 16px rgba(255, 201, 60, 0); }
}
.sg-tappa.prossima::before {
  content: "Tocca a te!";
  position: absolute; top: -34px;
  background: var(--sg-rosso); color: var(--sg-bianco);
  font-family: var(--sg-font-titoli); font-weight: 800;
  padding: 2px 12px; border-radius: 10px;
  white-space: nowrap;
}

/* ---------------------------------------------------------------------
   Lezione: lavagna della spiegazione + area di gioco
   --------------------------------------------------------------------- */
.sg-lavagna {
  width: 100%; max-width: 860px;
  background: #24433A;
  background-image: radial-gradient(ellipse at 30% 20%, rgba(255,255,255,.08), transparent 60%);
  border: 14px solid #B07A47;
  border-radius: 18px;
  box-shadow: 0 10px 0 #8A5C33, 0 22px 40px rgba(0,0,0,.2);
  color: #F4F7F2;
  padding: 28px 32px;
  font-size: 1.45rem;
  line-height: 1.55;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 24px;
  align-items: center;
}
.sg-lavagna h2 { font-size: 2.3rem; color: #FFF6C9; margin-bottom: 10px; }
.sg-lavagna .sg-lavagna-fig { width: 180px; aspect-ratio: 1; border-radius: 16px; display: grid; place-items: center; font-size: 6rem; overflow: hidden; background: rgba(255,255,255,.07); }
.sg-lavagna .sg-lavagna-fig img { width: 100%; height: 100%; object-fit: cover; }
@media (max-width: 720px) { .sg-lavagna { grid-template-columns: 1fr; text-align: center; } .sg-lavagna .sg-lavagna-fig { margin: 0 auto; width: 140px; font-size: 4.5rem; } }

.sg-obiettivi { width: 100%; max-width: 860px; margin-top: 18px; font-size: .95rem; color: var(--sg-inchiostro-2); }
.sg-obiettivi summary { cursor: pointer; font-weight: 700; }
.sg-obiettivi li { margin: 6px 0; }

.sg-gioco-testa { width: 100%; max-width: 980px; display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.sg-gioco-testa h2 { font-size: clamp(1.6rem, 3.4vw, 2.3rem); }
.sg-consegna { font-size: 1.25rem; color: var(--sg-inchiostro-2); margin: 2px 0 0; display: flex; align-items: center; gap: 8px; }
.sg-btn-ascolta { width: 44px; height: 44px; font-size: 1.2rem; flex: 0 0 auto; }

.sg-progresso { flex: 1; max-width: 360px; margin-left: auto; height: 22px; border: 3px solid var(--sg-inchiostro); border-radius: 14px; background: var(--sg-bianco); overflow: hidden; }
.sg-progresso > i { display: block; height: 100%; width: 0; background: repeating-linear-gradient(45deg, var(--sg-verde) 0 14px, #45C985 14px 28px); transition: width .5s cubic-bezier(.2,.9,.3,1); }

.sg-area { width: 100%; max-width: 980px; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: safe center; gap: 26px; min-height: 0; }

.sg-domanda {
  font-family: var(--sg-font-titoli);
  font-weight: 800;
  font-size: clamp(2rem, 5vw, 3.4rem);
  text-align: center;
  line-height: 1.15;
}
.sg-figura { font-size: clamp(3.4rem, 9vw, 6rem); line-height: 1.1; text-align: center; letter-spacing: .06em; word-break: break-word; }
.sg-figura img { max-height: 220px; max-width: 100%; border-radius: var(--sg-raggio-m); }

.sg-opzioni { display: flex; flex-wrap: wrap; gap: 20px; justify-content: center; width: 100%; }
.sg-opzione {
  min-width: 150px;
  min-height: 110px;
  padding: 14px 26px;
  border-radius: var(--sg-raggio-m);
  border: 4px solid var(--sg-inchiostro);
  background: var(--sg-bianco);
  box-shadow: 0 6px 0 var(--sg-inchiostro);
  font-family: var(--sg-font-titoli);
  font-weight: 800;
  font-size: clamp(1.8rem, 4.2vw, 3rem);
  color: var(--sg-inchiostro);
  cursor: pointer;
  transition: transform .1s, box-shadow .1s, background .2s;
}
.sg-opzione:active { transform: translateY(6px); box-shadow: 0 0 0 var(--sg-inchiostro); }
.sg-opzione.giusta  { background: var(--sg-verde); color: var(--sg-bianco); animation: sg-salta .5s ease; }
.sg-opzione.sbagliata { background: var(--sg-rosso); color: var(--sg-bianco); animation: sg-scuoti .45s ease; }
.sg-opzione.spenta  { opacity: .35; pointer-events: none; }

@keyframes sg-salta  { 30% { transform: translateY(-14px) scale(1.06); } 60% { transform: translateY(2px); } }
@keyframes sg-scuoti { 20%, 60% { transform: translateX(-10px) rotate(-2deg); } 40%, 80% { transform: translateX(10px) rotate(2deg); } }

/* Vero / Falso */
.sg-vf { display: flex; gap: 28px; }
.sg-vf .sg-opzione { min-width: 210px; min-height: 130px; }
.sg-vf .vero  { border-color: #1C7A4A; box-shadow: 0 6px 0 #1C7A4A; }
.sg-vf .falso { border-color: #B8323A; box-shadow: 0 6px 0 #B8323A; }

/* Memory */
.sg-memory {
  display: grid; gap: 14px; width: 100%;
  /* le carte devono stare tutte nello schermo: la larghezza dipende anche dall'altezza disponibile */
  max-width: min(820px, calc((100dvh - var(--sg-hud-h) - 190px) / var(--righe, 3) * var(--col, 4)));
  grid-template-columns: repeat(var(--col, 4), 1fr);
}
.sg-carta { aspect-ratio: 1; perspective: 900px; border: 0; padding: 0; background: transparent; cursor: pointer; }
.sg-carta-giro { position: relative; width: 100%; height: 100%; transition: transform .45s cubic-bezier(.2,.9,.3,1.2); transform-style: preserve-3d; }
.sg-carta.girata .sg-carta-giro, .sg-carta.trovata .sg-carta-giro { transform: rotateY(180deg); }
.sg-carta-faccia {
  position: absolute; inset: 0;
  border-radius: var(--sg-raggio-s);
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: grid; place-items: center;
  border: 4px solid var(--sg-bianco);
  box-shadow: var(--sg-ombra-figurina);
  font-family: var(--sg-font-titoli);
  font-weight: 800;
  font-size: clamp(1.3rem, 3.4vw, 2.4rem);
  text-align: center;
  padding: 6px;
  overflow: hidden;
}
.sg-carta-dorso {
  background-color: var(--sg-materia);
  background-image: radial-gradient(circle at 50% 50%, rgba(255,255,255,.35) 0 18%, transparent 19%),
                    repeating-linear-gradient(45deg, rgba(255,255,255,.12) 0 10px, transparent 10px 20px);
  color: var(--sg-bianco);
  font-size: 2.4rem;
}
.sg-carta-fronte { background: var(--sg-bianco); color: var(--sg-inchiostro); transform: rotateY(180deg); }
.sg-carta-fronte img { width: 100%; height: 100%; object-fit: contain; }
.sg-carta.trovata .sg-carta-fronte { background: #E3F8EC; border-color: var(--sg-verde); }
.sg-carta.no .sg-carta-fronte { background: #FFE5E6; }

/* Ordina (trascina) */
.sg-ordina-zona { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; min-height: 112px; width: 100%; padding: 14px; border-radius: var(--sg-raggio-m); }
.sg-ordina-zona.arrivo { border: 4px dashed var(--sg-matita); background: rgba(255,255,255,.7); }
.sg-tessera {
  min-width: 100px; min-height: 84px;
  padding: 10px 20px;
  border-radius: var(--sg-raggio-s);
  border: 4px solid var(--sg-inchiostro);
  background: var(--sg-giallo);
  box-shadow: 0 5px 0 var(--sg-inchiostro);
  font-family: var(--sg-font-titoli);
  font-weight: 800;
  font-size: clamp(1.4rem, 3.6vw, 2.4rem);
  color: var(--sg-inchiostro);
  cursor: grab;
  touch-action: none;
  display: inline-flex; align-items: center; justify-content: center;
}
.sg-tessera.trascina { cursor: grabbing; z-index: 50; box-shadow: 0 16px 24px rgba(29,62,138,.3); transform: rotate(-4deg) scale(1.08); }
.sg-tessera.posata { background: var(--sg-bianco); }
.sg-segnaposto { min-width: 100px; min-height: 84px; border-radius: var(--sg-raggio-s); border: 3px dashed var(--sg-matita); }

/* Conta */
.sg-conta-oggetti { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; max-width: 720px; }
.sg-conta-oggetti button {
  font-size: clamp(3rem, 7vw, 4.6rem);
  background: transparent; border: 0; padding: 4px; cursor: pointer; line-height: 1;
  transition: transform .15s;
  position: relative;
}
.sg-conta-oggetti button.contato { transform: scale(.88); filter: saturate(.6); }
.sg-conta-oggetti button.contato::after {
  content: attr(data-n);
  position: absolute; right: -4px; top: -6px;
  font-family: var(--sg-font-titoli); font-weight: 800; font-size: 1.2rem;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--sg-viola); color: var(--sg-bianco);
  display: grid; place-items: center;
}

/* Completa la parola */
.sg-parola { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.sg-parola .sg-lettera {
  min-width: 70px; height: 92px;
  display: grid; place-items: center;
  font-family: var(--sg-font-titoli); font-weight: 800;
  font-size: 3.2rem;
  border-bottom: 5px solid var(--sg-inchiostro);
  padding: 0 6px;
}
.sg-parola .sg-buco { color: var(--sg-viola); border-bottom-style: dashed; min-width: 96px; animation: sg-lampeggia 1.2s ease-in-out infinite; }
.sg-parola .sg-buco.pieno { animation: none; color: var(--sg-verde); }
@keyframes sg-lampeggia { 50% { background: rgba(123, 92, 255, .1); } }

/* Feedback sul giro */
.sg-feedback {
  position: fixed; left: 50%; top: 42%;
  transform: translate(-50%, -50%) scale(.6);
  font-family: var(--sg-font-titoli); font-weight: 800;
  font-size: clamp(2.6rem, 8vw, 5rem);
  pointer-events: none; z-index: 60; opacity: 0;
  text-shadow: 0 5px 0 rgba(29, 62, 138, .25);
  white-space: nowrap;
}
.sg-feedback.mostra { animation: sg-feedback 1s cubic-bezier(.2,.9,.3,1.3) both; }
.sg-feedback.bene { color: var(--sg-verde); }
.sg-feedback.male { color: var(--sg-rosso); }
@keyframes sg-feedback {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.5) rotate(-8deg); }
  25% { opacity: 1; transform: translate(-50%, -50%) scale(1.1) rotate(3deg); }
  70% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0); }
  100% { opacity: 0; transform: translate(-50%, -70%) scale(.95); }
}

.sg-punti-volanti {
  position: fixed; z-index: 61; pointer-events: none;
  font-family: var(--sg-font-titoli); font-weight: 800; font-size: 1.8rem;
  color: var(--sg-oro);
  text-shadow: 0 2px 0 var(--sg-inchiostro);
  animation: sg-vola 1s ease-out forwards;
}
@keyframes sg-vola { to { transform: translateY(-90px); opacity: 0; } }

/* ---------------------------------------------------------------------
   Risultato: il timbro della maestra (momento principale)
   --------------------------------------------------------------------- */
.sg-risultato { justify-content: center; text-align: center; gap: 18px; }
.sg-pagella {
  position: relative;
  background: var(--sg-bianco);
  border-radius: 8px;
  padding: 40px 44px 30px;
  width: min(560px, 100%);
  box-shadow: 0 2px 0 var(--sg-quadretto), 0 18px 40px rgba(29,62,138,.18);
  background-image: linear-gradient(transparent 39px, var(--sg-quadretto) 40px);
  background-size: 100% 40px;
}
.sg-pagella h2 { font-size: 2.6rem; }
.sg-stelle-grandi { display: flex; justify-content: center; gap: 12px; margin: 18px 0 6px; font-size: 5rem; line-height: 1; }
.sg-stelle-grandi span { opacity: 0; transform: scale(3) rotate(-30deg); }
.sg-stelle-grandi span.on   { animation: sg-stella .5s cubic-bezier(.2,.9,.3,1.4) forwards; }
.sg-stelle-grandi span.off  { animation: sg-stella-off .4s ease forwards; }
@keyframes sg-stella     { to { opacity: 1; transform: scale(1) rotate(0); } }
@keyframes sg-stella-off { to { opacity: .25; transform: scale(1); filter: grayscale(1); } }

.sg-timbro {
  position: absolute;
  right: -26px; top: -30px;
  width: 150px; height: 150px;
  border-radius: 50%;
  border: 6px double var(--sg-rosso);
  color: var(--sg-rosso);
  display: grid; place-items: center;
  font-family: var(--sg-font-titoli); font-weight: 800;
  font-size: 1.7rem;
  line-height: 1;
  text-align: center;
  background: rgba(255, 90, 95, .06);
  opacity: 0;
  transform: rotate(-16deg) scale(2.6);
  mix-blend-mode: multiply;
}
.sg-timbro.batti { animation: sg-timbro .38s cubic-bezier(.5, 0, .7, 1.4) forwards; }
@keyframes sg-timbro {
  0%   { opacity: 0; transform: rotate(-16deg) scale(2.6); }
  70%  { opacity: 1; transform: rotate(-12deg) scale(.92); }
  100% { opacity: .92; transform: rotate(-12deg) scale(1); }
}
.sg-pagella.scossa { animation: sg-colpo .3s ease; }
@keyframes sg-colpo { 30% { transform: translateY(5px) scale(.99); } }

.sg-totale-punti { font-family: var(--sg-font-titoli); font-weight: 800; font-size: 3rem; color: var(--sg-inchiostro); }
.sg-totale-punti small { display: block; font-size: 1.1rem; font-family: var(--sg-font-testo); color: var(--sg-inchiostro-2); }
.sg-azioni { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; margin-top: 10px; }

/* Traguardo sbloccato (popup) */
.sg-popup {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center;
  background: rgba(29, 62, 138, .55);
  backdrop-filter: blur(3px);
  padding: 20px;
}
.sg-popup[hidden] { display: none; }
.sg-popup-card {
  background: var(--sg-bianco);
  border: 4px solid var(--sg-inchiostro);
  border-radius: var(--sg-raggio-l);
  box-shadow: 0 8px 0 var(--sg-inchiostro);
  padding: 30px 34px;
  text-align: center;
  max-width: 460px;
  animation: sg-entra .5s cubic-bezier(.2,.9,.3,1.4);
}
.sg-medaglia { width: 160px; height: 160px; margin: 0 auto 12px; display: grid; place-items: center; font-size: 6rem; border-radius: 50%; background: radial-gradient(circle, #FFF3C4, var(--sg-giallo)); box-shadow: 0 0 0 8px #FFF3C4, 0 0 40px rgba(245,184,0,.6); animation: sg-gira 6s linear infinite; overflow: hidden; }
.sg-medaglia img { width: 100%; height: 100%; object-fit: cover; }
@keyframes sg-gira { from { box-shadow: 0 0 0 8px #FFF3C4, 0 0 30px rgba(245,184,0,.5); } 50% { box-shadow: 0 0 0 14px #FFF3C4, 0 0 60px rgba(245,184,0,.8); } }

/* Traguardi (album delle figurine) */
.sg-album { width: 100%; max-width: 1080px; display: grid; gap: 22px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.sg-badge { text-align: center; }
.sg-badge .sg-medaglia-piccola { width: 120px; height: 120px; margin: 0 auto; border-radius: 50%; display: grid; place-items: center; font-size: 3.6rem; background: radial-gradient(circle, #FFF3C4, var(--sg-giallo)); box-shadow: var(--sg-ombra-figurina); overflow: hidden; }
.sg-badge .sg-medaglia-piccola img { width: 100%; height: 100%; object-fit: cover; }
.sg-badge.chiuso .sg-medaglia-piccola { background: #E6ECF5; filter: grayscale(1); opacity: .5; }
.sg-badge h3 { font-size: 1.2rem; margin-top: 10px; }
.sg-badge p { margin: 2px 0 0; font-size: .9rem; color: var(--sg-inchiostro-2); }

/* Coriandoli */
#sg-coriandoli { position: fixed; inset: 0; pointer-events: none; z-index: 70; }

/* Caricamento */
.sg-caricamento { display: flex; flex-direction: column; align-items: center; gap: 14px; margin: auto; font-family: var(--sg-font-titoli); font-weight: 700; font-size: 1.4rem; }
.sg-matita-gira { font-size: 3.4rem; animation: sg-scrive 1s ease-in-out infinite; }
@keyframes sg-scrive { 50% { transform: translate(18px, -6px) rotate(18deg); } }

.sg-errore-box { background: #FFE5E6; border: 3px solid var(--sg-rosso); border-radius: var(--sg-raggio-m); padding: 18px 24px; max-width: 560px; text-align: center; }

/* Banner rotazione su telefoni in verticale durante il gioco */
.sg-nota { font-size: .95rem; color: var(--sg-inchiostro-2); }

/* ---------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------- */
@media (max-width: 720px) {
  body.sg::before { left: 22px; }
  .sg-screen { padding: 16px 16px 32px 34px; }
  .sg-hud { padding: 8px 10px 8px 34px; gap: 8px; height: 64px; }
  .sg-chip { height: 44px; font-size: 1.05rem; padding: 0 12px 0 6px; }
  .sg-chip .sg-avatar-mini { width: 32px; height: 32px; }
  .sg-icon-btn { width: 44px; height: 44px; font-size: 1.2rem; }
  .sg-chip-livello .sg-barra-livello, .sg-chip-livello small { display: none; }
  .sg-griglia { grid-template-columns: repeat(2, 1fr); gap: 16px; }
  .sg-classe .sg-numero-classe { font-size: 4.6rem; }
  .sg-tappa .sg-bollino { width: 92px; height: 92px; }
  .sg-timbro { width: 112px; height: 112px; font-size: 1.25rem; right: -10px; top: -26px; }
  .sg-pagella { padding: 36px 22px 24px; }
}

@media (max-width: 720px) {
  .sg-sentiero { --xs: .45; }
  .sg-gioco-testa { flex-wrap: wrap; }
  .sg-progresso { flex: 0 0 100%; max-width: none; margin-left: 0; height: 18px; }
}
@media (max-width: 480px) {
  .sg-chip-livello, .sg-chip-stelle, #sg-hud-nome { display: none; }
  .sg-hud { gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .sg-stelle-grandi span { opacity: 1; transform: none; }
  .sg-timbro { opacity: .92; transform: rotate(-12deg); }
}

.sg-tessera.sbagliata { background: var(--sg-rosso); color: var(--sg-bianco); animation: sg-scuoti .45s ease; }

.sg-img-fill { position: absolute; inset: 0; }
.sg-figurina-dentro.con-img .sg-emoji-grande { display: none; }
.sg-figurina-dentro.con-img .sg-numero-classe { text-shadow: 0 4px 0 rgba(0,0,0,.35), 0 0 24px rgba(0,0,0,.35); }
.sg-avatar-scelta > span, .sg-bollino > span > .sg-illustrazione, .sg-lavagna-fig .sg-illustrazione { width: 100%; height: 100%; display: grid; place-items: center; }

/* ---------------------------------------------------------------------
   Scelta della scuola e dell'indirizzo
   --------------------------------------------------------------------- */
.sg-griglia-grande { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.sg-griglia-grande .sg-figurina-dentro { min-height: 200px; }
.sg-settore { font-size: 1.6rem; margin: 28px 0 14px; color: var(--sg-inchiostro-2); }
.sg-settore:first-child { margin-top: 0; }
.sg-indirizzo .sg-nome { font-size: 1.2rem; }
.sg-indirizzo .sg-figurina-dentro { min-height: 120px; }
.sg-indirizzo .sg-emoji-grande { font-size: 3.2rem; }
@media (max-width: 720px) { .sg-griglia-grande { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------------
   Testi lunghi (frasi in inglese, superiori): carattere più piccolo
   --------------------------------------------------------------------- */
.sg-domanda.lunga { font-size: clamp(1.5rem, 3.2vw, 2.3rem); max-width: 900px; }
.sg-domanda.lunghissima { font-size: clamp(1.25rem, 2.6vw, 1.8rem); font-family: var(--sg-font-testo); font-weight: 700; }
.sg-opzione.lunga { font-size: clamp(1.15rem, 2.4vw, 1.6rem); min-height: 84px; max-width: 100%; }
.sg-opzione.lunghissima { font-size: clamp(1rem, 2vw, 1.3rem); flex: 1 1 100%; text-align: left; font-family: var(--sg-font-testo); font-weight: 700; }
.sg-tessera.lunga { font-size: clamp(1.05rem, 2.2vw, 1.4rem); }
.sg-tessera.lunghissima { font-size: clamp(.95rem, 1.8vw, 1.15rem); font-family: var(--sg-font-testo); font-weight: 700; max-width: 100%; }
.sg-carta-faccia { overflow-wrap: anywhere; hyphens: auto; line-height: 1.1; }
.sg-carta-fronte.lunga { font-size: clamp(.95rem, 2vw, 1.4rem); }
.sg-carta-fronte.lunghissima { font-size: clamp(.8rem, 1.6vw, 1.1rem); }

/* Scelta della voce */
.sg-voci { margin-top: 40px; text-align: center; }
.sg-voci-righe { display: flex; flex-direction: column; gap: 14px; max-width: 760px; margin: 14px auto 0; }
.sg-voce-riga { display: grid; grid-template-columns: 90px 1fr auto; gap: 12px; align-items: center; text-align: left; background: var(--sg-bianco); border: 3px solid var(--sg-inchiostro); border-radius: var(--sg-raggio-m); padding: 12px 16px; }
.sg-voce-riga small { grid-column: 2 / -1; }
.sg-voce-riga .sg-btn { min-height: 52px; font-size: 1.15rem; padding: 6px 18px; }
.sg-voce-select { font-size: 1rem; border: 2px solid var(--sg-inchiostro-2); }
@media (max-width: 600px) { .sg-voce-riga { grid-template-columns: 1fr; } .sg-voce-riga small { grid-column: auto; } }

/* Amministratore: pulsanti di salto (solo test) */
.sg-btn-admin { background: #EDE7FF; border-style: dashed; border-color: var(--sg-viola); box-shadow: 0 5px 0 var(--sg-viola); color: #4B2FBF; font-size: 1.2rem; min-height: 56px; padding: 6px 18px; }
.sg-gioco-testa .sg-btn-admin { flex: 0 0 auto; }
body.sg-admin #sg-hud-profilo::after { content: "ADMIN"; font-family: var(--sg-font-testo); font-size: .7rem; font-weight: 700; background: var(--sg-viola); color: #fff; border-radius: 6px; padding: 1px 6px; margin-left: 4px; }
body.sg-admin .sg-tappa.bloccata { cursor: pointer; }

/* Parti in inglese dentro i testi italiani ({graffe} nei dati): evidenziate e lette dalla voce inglese */
.sg-en { font-style: italic; font-weight: 600; color: var(--sg-viola); }
.sg-lavagna .sg-en { color: #FFE58A; font-weight: 500; }

/* =====================================================================
   TEMI PER ETÀ
   html[data-tema]: "neutro" (ingresso, prima di scegliere la scuola),
   "primaria" (quaderno a quadretti, lo stile qui sopra), "medie", "superiori".
   Lo imposta SG.tema in sg-core.js in base alla scuola scelta.
   ===================================================================== */

/* ---------- Basi comuni ai temi "da grandi" (neutro, medie, superiori) ---------- */
html:is([data-tema="neutro"], [data-tema="medie"], [data-tema="superiori"]) body.sg::before { display: none; }   /* niente margine rosso */
html:is([data-tema="neutro"], [data-tema="medie"], [data-tema="superiori"]) .sg-screen { padding: 24px 24px 40px; }
html:is([data-tema="neutro"], [data-tema="medie"], [data-tema="superiori"]) .sg-hud { padding: 10px 20px; }
html:is([data-tema="neutro"], [data-tema="medie"], [data-tema="superiori"]) .sg-figurina { transform: none; }
html:is([data-tema="neutro"], [data-tema="medie"], [data-tema="superiori"]) .sg-figurina:hover { transform: translateY(-3px); }
html:is([data-tema="neutro"], [data-tema="medie"], [data-tema="superiori"]) .sg-figurina:active { transform: scale(.98); }
html:is([data-tema="neutro"], [data-tema="medie"], [data-tema="superiori"]) .sg-tessera.trascina { transform: scale(1.04); }
@media (max-width: 720px) {
  html:is([data-tema="neutro"], [data-tema="medie"], [data-tema="superiori"]) .sg-screen { padding: 16px 16px 32px; }
  html:is([data-tema="neutro"], [data-tema="medie"], [data-tema="superiori"]) .sg-hud { padding: 8px 12px; }
}

/* ---------- Basi comuni a neutro e superiori: linee sottili, ombre morbide ---------- */
html:is([data-tema="neutro"], [data-tema="superiori"]) {
  --sg-font-titoli: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --sg-font-testo: "Figtree", "Segoe UI", system-ui, sans-serif;
  --sg-raggio-s: 10px;
  --sg-raggio-m: 14px;
  --sg-raggio-l: 18px;
  --sg-tocco: 52px;
  --sg-hud-h: 68px;
  --sg-ombra-figurina: 0 1px 2px rgba(18, 24, 43, .06), 0 8px 24px rgba(18, 24, 43, .07);
}
html:is([data-tema="neutro"], [data-tema="superiori"]) body.sg { background-image: none; font-size: 1.05rem; }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg h1,
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg h2,
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg h3 { font-weight: 700; letter-spacing: -.02em; }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg :focus-visible { outline: 3px solid var(--sg-accento); outline-offset: 3px; }

html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-chip,
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-icon-btn {
  border: 1px solid var(--sg-linea); box-shadow: 0 1px 2px rgba(18,24,43,.06); background: var(--sg-superficie); color: var(--sg-inchiostro);
}
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-chip { height: 44px; font-family: var(--sg-font-testo); font-weight: 700; font-size: 1.02rem; padding: 0 14px 0 6px; }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-chip .sg-chip-ico { font-size: 1.2rem; }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-chip .sg-avatar-mini { width: 32px; height: 32px; }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-icon-btn { width: 44px; height: 44px; font-size: 1.15rem; }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-icon-btn:active { transform: scale(.94); box-shadow: none; }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-barra-livello { background: var(--sg-linea); height: 6px; }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-barra-livello > i { background: var(--sg-oro); }

html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-btn {
  border: 1px solid transparent; box-shadow: 0 1px 2px rgba(18,24,43,.12); border-radius: 12px;
  font-family: var(--sg-font-testo); font-weight: 700; font-size: 1.1rem; padding: 10px 24px;
  background: var(--sg-accento); color: #fff;
}
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-btn:hover { filter: brightness(1.06); }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-btn:active { transform: translateY(1px); box-shadow: none; }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-btn-secondario { background: var(--sg-superficie); color: var(--sg-inchiostro); border-color: var(--sg-linea); }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-btn-verde { background: var(--sg-accento); color: #fff; }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-btn-grande { font-size: 1.25rem; min-height: 60px; padding: 12px 36px; border-radius: 14px; }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-btn-admin { background: #EEF0FF; color: #3B3FB0; border: 1px dashed #6D72E0; box-shadow: none; font-size: 1rem; min-height: 44px; }

html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-campo {
  border: 1px solid var(--sg-linea); border-radius: 12px; font-family: var(--sg-font-testo); font-weight: 600;
  font-size: 1.35rem; height: 60px; box-shadow: inset 0 1px 2px rgba(18,24,43,.05); color: var(--sg-inchiostro); background: var(--sg-superficie);
}
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-campo:focus { outline: 3px solid color-mix(in srgb, var(--sg-accento) 35%, transparent); border-color: var(--sg-accento); }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-avatar-griglia { max-width: 560px; gap: 10px; }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-avatar-scelta { border: 2px solid var(--sg-linea); box-shadow: none; font-size: 2.1rem; }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-avatar-scelta[aria-pressed="true"] { border-color: var(--sg-accento); transform: none; box-shadow: 0 0 0 4px color-mix(in srgb, var(--sg-accento) 22%, transparent); }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-avatar-mini { background: var(--sg-sfondo); }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-codice-magico { font-family: var(--sg-font-testo); font-size: 1.7rem; background: var(--sg-sfondo); border: 1px dashed var(--sg-inchiostro-2); }

html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-intestazione h1 { font-size: clamp(1.7rem, 3.4vw, 2.5rem); }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-intestazione > span[aria-hidden] { font-size: 2rem !important; }

/* Schede di scelta (scuola, indirizzo, anno, materia): orizzontali e sobrie */
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-figurina {
  padding: 0; border: 1px solid var(--sg-linea); border-radius: var(--sg-raggio-m); overflow: hidden; text-align: left;
  background: var(--sg-superficie); display: flex; flex-direction: column;
}
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-figurina:hover { border-color: color-mix(in srgb, var(--sg-accento) 45%, var(--sg-linea)); }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-figurina-dentro { border-radius: 0; min-height: 110px; align-items: flex-start; justify-content: flex-end; padding: 14px 16px; }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-figurina-dentro .sg-emoji-grande { font-size: 2.6rem; filter: none; }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-figurina .sg-nome { font-size: 1.15rem; margin: 12px 16px 0; }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-figurina .sg-sotto { margin: 4px 16px 14px; font-size: .92rem; }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-classe .sg-figurina-dentro { min-height: 120px; }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-classe .sg-numero-classe { font-size: 3.6rem; text-shadow: none; }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-griglia { gap: 18px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-griglia-grande { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-indirizzo .sg-figurina-dentro { min-height: 76px; }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-indirizzo .sg-emoji-grande { font-size: 2rem; }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-settore { font-size: 1.15rem; font-family: var(--sg-font-testo); }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-avanzamento { height: 6px; }

html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-caricamento { font-family: var(--sg-font-testo); font-size: 1.05rem; color: var(--sg-inchiostro-2); }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-matita-gira { font-size: 0; width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--sg-linea); border-top-color: var(--sg-accento); animation: sg-ruota .8s linear infinite; }
@keyframes sg-ruota { to { transform: rotate(360deg); } }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-errore-box { border-width: 1px; border-radius: 12px; }

html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-popup { background: rgba(18, 24, 43, .45); }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-popup-card { border: 1px solid var(--sg-linea); box-shadow: 0 24px 60px rgba(18,24,43,.25); border-radius: 20px; }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-popup-card h2 { font-size: 1.6rem !important; }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-medaglia { width: 120px; height: 120px; font-size: 4.2rem; }
html:is([data-tema="neutro"], [data-tema="superiori"]) .sg-voce-riga { border: 1px solid var(--sg-linea); }

/* =====================================================================
   NEUTRO: l'ingresso. Grafite su grigio carta, nessun colore finché
   non si sceglie la scuola; le tre fasce colorate annunciano i tre mondi.
   ===================================================================== */
html[data-tema="neutro"] {
  --sg-sfondo: #F3F4F6;
  --sg-superficie: #FFFFFF;
  --sg-inchiostro: #1E2430;
  --sg-inchiostro-2: #5D6676;
  --sg-linea: #DCE0E6;
  --sg-accento: #27324A;
  --sg-carta: var(--sg-sfondo);
  --sg-matita: #9AA3B2;
}
html[data-tema="neutro"] body.sg { background-color: var(--sg-sfondo); color: var(--sg-inchiostro); }

/* Benvenuto neutro */
.sg-ingresso { justify-content: center; align-items: flex-start; }
.sg-ingresso-box { width: 100%; max-width: 760px; margin: auto; display: flex; flex-direction: column; gap: 28px; }
.sg-marchio { font-family: var(--sg-font-titoli); font-weight: 800; font-size: clamp(3rem, 10vw, 6.2rem); line-height: .92; letter-spacing: -.045em; margin: 0; color: var(--sg-inchiostro); }
.sg-ingresso-testo { font-size: clamp(1.1rem, 2.2vw, 1.3rem); color: var(--sg-inchiostro-2); max-width: 34em; margin: 0; line-height: 1.5; }
.sg-fasce { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; border-radius: 14px; overflow: hidden; border: 1px solid var(--sg-linea); background: var(--sg-superficie); }
.sg-fascia { padding: 16px 18px 18px; border-top: 6px solid var(--f); }
.sg-fascia + .sg-fascia { border-left: 1px solid var(--sg-linea); }
.sg-fascia strong { display: block; font-family: var(--sg-font-titoli); font-size: 1.2rem; color: var(--sg-inchiostro); }
.sg-fascia span { display: block; font-size: .9rem; color: var(--sg-inchiostro-2); margin-top: 2px; }
.sg-ingresso-azioni { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.sg-ingresso-azioni .sg-nota { margin: 0; }
@media (max-width: 600px) { .sg-fasce { grid-template-columns: 1fr; } .sg-fascia + .sg-fascia { border-left: 0; border-top-width: 6px; } }

/* =====================================================================
   SUPERIORI: pulito e adulto. Inchiostro blu notte, accento indaco,
   ambra per punti e stelle. La lavagna diventa una scheda di studio.
   ===================================================================== */
html[data-tema="superiori"] {
  --sg-sfondo: #EDF0F5;
  --sg-superficie: #FFFFFF;
  --sg-inchiostro: #131A2E;
  --sg-inchiostro-2: #4E5871;
  --sg-linea: #D6DCE7;
  --sg-accento: #3446C2;
  --sg-oro: #E3A02F;
  --sg-verde: #1F9D63;
  --sg-rosso: #D2453F;
  --sg-viola: #3446C2;
  --sg-carta: var(--sg-sfondo);
  --sg-quadretto: #E3E8F0;
  --sg-matita: #A3ACBD;
}
html[data-tema="superiori"] body.sg { background-color: var(--sg-sfondo); color: var(--sg-inchiostro); }

/* Percorso */
html[data-tema="superiori"] .sg-percorso-unita .sg-cartello { border: 0; box-shadow: none; font-family: var(--sg-font-testo); font-weight: 700; font-size: 1.1rem; border-radius: 10px; padding: 8px 16px; }
html[data-tema="superiori"] .sg-sentiero svg.sg-linea path { stroke-width: 2; stroke-dasharray: none; stroke: var(--sg-linea); }
html[data-tema="superiori"] .sg-tappa .sg-bollino { width: 84px; height: 84px; padding: 4px; box-shadow: 0 0 0 1px var(--sg-linea), var(--sg-ombra-figurina); }
html[data-tema="superiori"] .sg-tappa .sg-bollino > span { font-size: 2.1rem; }
html[data-tema="superiori"] .sg-tappa:hover .sg-bollino { transform: scale(1.05); }
html[data-tema="superiori"] .sg-tappa .sg-etichetta { border: 0; background: transparent; font-family: var(--sg-font-testo); font-weight: 700; font-size: 1rem; }
html[data-tema="superiori"] .sg-tappa .sg-stelline { font-size: 1rem; }
html[data-tema="superiori"] .sg-tappa.bloccata .sg-bollino::after { font-size: 1.2rem; }
html[data-tema="superiori"] .sg-tappa.prossima::before { content: "Prossima"; background: var(--sg-accento); font-family: var(--sg-font-testo); font-weight: 700; font-size: .85rem; border-radius: 6px; top: -28px; }
html[data-tema="superiori"] .sg-tappa.prossima .sg-bollino { animation: none; box-shadow: 0 0 0 3px var(--sg-accento), var(--sg-ombra-figurina); }
@media (max-width: 720px) { html[data-tema="superiori"] .sg-tappa .sg-bollino { width: 72px; height: 72px; } }

/* Lavagna -> scheda di studio */
html[data-tema="superiori"] .sg-lavagna {
  background: var(--sg-superficie); background-image: none; color: var(--sg-inchiostro);
  border: 1px solid var(--sg-linea); border-left: 6px solid var(--sg-materia); border-radius: 14px;
  box-shadow: var(--sg-ombra-figurina); font-size: 1.15rem; line-height: 1.65; padding: 26px 30px; max-width: 900px;
}
html[data-tema="superiori"] .sg-lavagna h2 { color: var(--sg-inchiostro); font-size: 1.35rem; }
html[data-tema="superiori"] .sg-lavagna p { max-width: 68ch; margin: 0; }
html[data-tema="superiori"] .sg-lavagna .sg-lavagna-fig { width: 132px; font-size: 4rem; background: var(--sg-sfondo); border-radius: 12px; }
html[data-tema="superiori"] .sg-lavagna .sg-en { color: var(--sg-accento); }
html[data-tema="superiori"] .sg-en { color: var(--sg-accento); font-weight: 600; }
html[data-tema="superiori"] .sg-obiettivi { font-size: .9rem; }

/* Giochi */
html[data-tema="superiori"] .sg-gioco-testa h2 { font-size: clamp(1.3rem, 2.6vw, 1.7rem); }
html[data-tema="superiori"] .sg-consegna { font-size: 1.05rem; }
html[data-tema="superiori"] .sg-progresso { border: 0; height: 8px; background: var(--sg-linea); border-radius: 6px; }
html[data-tema="superiori"] .sg-progresso > i { background: var(--sg-accento); }
html[data-tema="superiori"] .sg-domanda { font-family: var(--sg-font-titoli); font-weight: 600; font-size: clamp(1.45rem, 3.2vw, 2.2rem); max-width: 860px; letter-spacing: -.015em; }
html[data-tema="superiori"] .sg-domanda.lunga { font-size: clamp(1.25rem, 2.6vw, 1.7rem); }
html[data-tema="superiori"] .sg-domanda.lunghissima { font-size: clamp(1.1rem, 2.2vw, 1.4rem); }
html[data-tema="superiori"] .sg-figura { font-size: clamp(2.6rem, 6vw, 4rem); }
html[data-tema="superiori"] .sg-opzioni { gap: 12px; max-width: 900px; }
html[data-tema="superiori"] .sg-opzione {
  min-width: 140px; min-height: 64px; padding: 12px 22px; border: 1px solid var(--sg-linea); border-radius: 12px;
  box-shadow: 0 1px 2px rgba(18,24,43,.06); font-family: var(--sg-font-testo); font-weight: 600; font-size: clamp(1.05rem, 2vw, 1.3rem);
  background: var(--sg-superficie); color: var(--sg-inchiostro);
}
html[data-tema="superiori"] .sg-opzione:hover { border-color: var(--sg-accento); }
html[data-tema="superiori"] .sg-opzione:active { transform: translateY(1px); box-shadow: none; }
html[data-tema="superiori"] .sg-opzione.lunga, html[data-tema="superiori"] .sg-opzione.lunghissima { font-size: clamp(1rem, 1.8vw, 1.15rem); }
html[data-tema="superiori"] .sg-opzione.giusta { background: var(--sg-verde); border-color: var(--sg-verde); color: #fff; animation: none; }
html[data-tema="superiori"] .sg-opzione.sbagliata { background: var(--sg-rosso); border-color: var(--sg-rosso); color: #fff; }
html[data-tema="superiori"] .sg-vf .sg-opzione { min-width: 180px; min-height: 76px; }
html[data-tema="superiori"] .sg-vf .vero, html[data-tema="superiori"] .sg-vf .falso { box-shadow: 0 1px 2px rgba(18,24,43,.06); }
html[data-tema="superiori"] .sg-vf .vero { border-color: #9BD3B7; }
html[data-tema="superiori"] .sg-vf .falso { border-color: #EDB0AD; }
html[data-tema="superiori"] .sg-carta-faccia { border: 1px solid var(--sg-linea); box-shadow: 0 1px 2px rgba(18,24,43,.06); font-family: var(--sg-font-testo); font-weight: 600; font-size: clamp(.95rem, 2vw, 1.25rem); border-radius: 12px; }
html[data-tema="superiori"] .sg-carta-dorso { background-image: none; background-color: var(--sg-inchiostro); color: rgba(255,255,255,.5); font-size: 1.6rem; border-color: var(--sg-inchiostro); }
html[data-tema="superiori"] .sg-carta-fronte.lunga { font-size: clamp(.9rem, 1.7vw, 1.1rem); }
html[data-tema="superiori"] .sg-carta-fronte.lunghissima { font-size: clamp(.8rem, 1.5vw, 1rem); }
html[data-tema="superiori"] .sg-carta.trovata .sg-carta-fronte { background: #E6F5EE; border-color: var(--sg-verde); }
html[data-tema="superiori"] .sg-tessera { border: 1px solid var(--sg-linea); background: var(--sg-superficie); box-shadow: 0 1px 2px rgba(18,24,43,.08); font-family: var(--sg-font-testo); font-weight: 600; font-size: clamp(1rem, 2vw, 1.25rem); min-height: 56px; border-radius: 10px; }
html[data-tema="superiori"] .sg-tessera.posata { background: #EEF0FB; border-color: #B9C0EE; }
html[data-tema="superiori"] .sg-ordina-zona.arrivo { border: 2px dashed var(--sg-linea); background: rgba(255,255,255,.6); }
html[data-tema="superiori"] .sg-segnaposto { min-height: 56px; border: 2px dashed var(--sg-linea); }
html[data-tema="superiori"] .sg-feedback { font-family: var(--sg-font-titoli); font-weight: 700; font-size: clamp(1.8rem, 5vw, 3rem); text-shadow: none; }
html[data-tema="superiori"] .sg-punti-volanti { color: var(--sg-oro); text-shadow: none; font-family: var(--sg-font-testo); font-size: 1.3rem; }
html[data-tema="superiori"] .sg-mascotte-emoji { font-size: 3.4rem; animation: none; }

/* Risultato: scheda con punteggio, il timbro diventa un sigillo */
html[data-tema="superiori"] .sg-pagella { background-image: none; border: 1px solid var(--sg-linea); border-radius: 18px; box-shadow: var(--sg-ombra-figurina); }
html[data-tema="superiori"] .sg-pagella h2 { font-size: 1.9rem; }
html[data-tema="superiori"] .sg-stelle-grandi { font-size: 3.2rem; }
html[data-tema="superiori"] .sg-timbro { border: 3px solid var(--sg-accento); color: var(--sg-accento); background: #F1F3FD; font-family: var(--sg-font-testo); font-size: 1.15rem; width: 112px; height: 112px; mix-blend-mode: normal; }
html[data-tema="superiori"] .sg-totale-punti { font-family: var(--sg-font-titoli); font-size: 2.4rem; }

/* =====================================================================
   MEDIE: via di mezzo. Restano colori e rilievo dei bottoni, ma niente
   quaderno a quadretti, niente figurine storte, carattere più maturo.
   ===================================================================== */
html[data-tema="medie"] {
  --sg-font-titoli: "Nunito", "Segoe UI", system-ui, sans-serif;
  --sg-font-testo: "Figtree", "Segoe UI", system-ui, sans-serif;
  --sg-carta: #F4F8FC;
  --sg-quadretto: #DCE6F2;
  --sg-inchiostro: #17325E;
  --sg-inchiostro-2: #4A5F85;
  --sg-giallo: #FFC24A;
  --sg-viola: #0E8F8F;
  --sg-tocco: 60px;
}
html[data-tema="medie"] body.sg {
  background-image: radial-gradient(var(--sg-quadretto) 1.4px, transparent 1.5px);
  background-size: 26px 26px; font-size: 1.1rem;
}
html[data-tema="medie"] .sg-chip, html[data-tema="medie"] .sg-icon-btn { border-width: 2px; box-shadow: 0 2px 0 var(--sg-inchiostro); }
html[data-tema="medie"] .sg-chip { height: 46px; font-size: 1.1rem; }
html[data-tema="medie"] .sg-icon-btn { width: 46px; height: 46px; font-size: 1.25rem; }
html[data-tema="medie"] .sg-btn { border-width: 2px; box-shadow: 0 3px 0 var(--sg-inchiostro); font-size: 1.3rem; border-radius: 16px; }
html[data-tema="medie"] .sg-btn:active { transform: translateY(3px); }
html[data-tema="medie"] .sg-btn-grande { font-size: 1.6rem; min-height: 72px; }
html[data-tema="medie"] .sg-opzione { border-width: 2px; box-shadow: 0 4px 0 var(--sg-inchiostro); font-size: clamp(1.4rem, 3.2vw, 2.2rem); min-height: 88px; }
html[data-tema="medie"] .sg-opzione:active { transform: translateY(4px); }
html[data-tema="medie"] .sg-domanda { font-size: clamp(1.7rem, 4vw, 2.7rem); }
html[data-tema="medie"] .sg-tessera { border-width: 2px; box-shadow: 0 3px 0 var(--sg-inchiostro); }
html[data-tema="medie"] .sg-progresso { border-width: 2px; height: 16px; }
html[data-tema="medie"] .sg-percorso-unita .sg-cartello { border-width: 2px; box-shadow: 0 3px 0 var(--sg-inchiostro); font-size: 1.3rem; }
html[data-tema="medie"] .sg-tappa .sg-etichetta { border-width: 1.5px; }
html[data-tema="medie"] .sg-lavagna { border-width: 10px; box-shadow: 0 6px 0 #8A5C33, 0 16px 30px rgba(0,0,0,.16); font-size: 1.3rem; }
html[data-tema="medie"] .sg-campo { border-width: 2px; font-size: 1.6rem; height: 66px; }
html[data-tema="medie"] .sg-popup-card { border-width: 2px; box-shadow: 0 5px 0 var(--sg-inchiostro); }
html[data-tema="medie"] .sg-tappa.prossima::before { content: "Tocca a te"; }

/* ---------- Ritocchi: profilo, livello, indirizzi a elenco ---------- */
html[data-tema="neutro"] .sg-profilo .sg-intestazione { max-width: 560px; }
html:is([data-tema="neutro"], [data-tema="superiori"]) #sg-hud-livello-nome { display: none; }   /* "Semino curioso" & co. sono nomi da bambini */

/* Superiori: gli indirizzi sono tanti e con nomi lunghi -> schede orizzontali compatte */
html[data-tema="superiori"] .sg-settore { margin: 26px 0 12px; font-size: 1rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--sg-inchiostro-2); }
html[data-tema="superiori"] .sg-settore:first-child { margin-top: 0; }
html[data-tema="superiori"] .sg-indirizzo.sg-figurina {
  display: grid; grid-template-columns: 56px 1fr; grid-template-rows: auto auto; align-content: center;
  column-gap: 14px; padding: 14px 16px; min-height: 88px;
}
html[data-tema="superiori"] .sg-indirizzo .sg-figurina-dentro {
  grid-row: 1 / span 2; width: 56px; height: 56px; min-height: 0; padding: 0; border-radius: 12px;
  align-items: center; justify-content: center; background: color-mix(in srgb, var(--sg-accento) 9%, #fff);
}
html[data-tema="superiori"] .sg-indirizzo .sg-emoji-grande { font-size: 1.8rem; }
html[data-tema="superiori"] .sg-indirizzo .sg-nome { margin: 0; align-self: end; font-size: 1.05rem; line-height: 1.2; }
html[data-tema="superiori"] .sg-indirizzo .sg-sotto { margin: 3px 0 0; align-self: start; font-size: .88rem; line-height: 1.35; }
html[data-tema="superiori"] .sg-indirizzo .sg-sotto:empty { display: none; }
html[data-tema="superiori"] .sg-griglia:has(.sg-indirizzo) { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
html[data-tema="superiori"] .sg-indirizzo:not(:has(.sg-sotto)) .sg-nome { grid-row: 1 / span 2; align-self: center; }
@media (max-width: 720px) {
  html[data-tema="superiori"] .sg-lavagna { text-align: left; padding: 20px 18px; font-size: 1.05rem; }
  html[data-tema="superiori"] .sg-lavagna .sg-lavagna-fig { width: 64px; height: 64px; font-size: 2.2rem; margin: 0; }
}
