/* ============================================================
   QUIZ.CSS — LezIA
   Layout compatto in una schermata + Kids mode + Kahoot moments.
   ============================================================ */

/* ============================================================
   VARIABILI BASE
   ============================================================ */
:root{
  --navy:#1a2440;
  --blue:#5b8def;
  --violet:#9b5de5;
  --teal:#00c2a8;
  --green:#2fbf71;
  --red:#ef476f;
  --amber:#ffaa00;
  --pink:#ff5c8a;
  --ink:#2b2140;
  --ink-soft:#6b5f80;
  --bg:#f4f7fc;
  --bg-alt:#eef3fb;
  --surface:#ffffff;
  --border:#e0e8f5;
  --shadow-sm:0 2px 8px rgba(20,40,80,.06);
  --shadow-md:0 8px 24px rgba(20,40,80,.10);
  --shadow-lg:0 15px 40px rgba(20,40,80,.15);
  --font:'Plus Jakarta Sans',system-ui,-apple-system,sans-serif;
  --font-display:'Sora',var(--font);
  --radius:14px;
  --radius-lg:20px;
}
html[data-theme="dark"]{
  --navy:#e8eefc;
  --ink:#f3ecff;
  --ink-soft:#b0a3c9;
  --bg:#15112a;
  --bg-alt:#1e1838;
  --surface:#221c3a;
  --border:#3a3154;
  --shadow-sm:0 2px 8px rgba(0,0,0,.3);
  --shadow-md:0 8px 24px rgba(0,0,0,.4);
  --shadow-lg:0 15px 40px rgba(0,0,0,.5);
}

/* ============================================================
   RESET + BODY
   ============================================================ */
*{box-sizing:border-box;margin:0;padding:0}
html,body{height:100%}
body{
  font-family:var(--font);
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(91,141,239,.10), transparent 60%),
    radial-gradient(800px 400px at 100% 100%, rgba(155,93,229,.08), transparent 60%),
    var(--bg);
  color:var(--ink);
  height:100vh;
  height:100dvh;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:flex-start;
  padding:0.75rem;
  transition:background .3s,color .3s;
  line-height:1.4;
  overflow:hidden;
}
body.shake{animation:screenShake .4s ease}
@keyframes screenShake{
  0%,100%{transform:translateX(0)}
  20%{transform:translateX(-8px)}
  40%{transform:translateX(8px)}
  60%{transform:translateX(-5px)}
  80%{transform:translateX(5px)}
}

/* ============================================================
   TOGGLE TEMA
   ============================================================ */
.theme-toggle{
  position:fixed;top:.7rem;right:.7rem;width:38px;height:38px;
  border-radius:50%;border:2px solid var(--border);background:var(--surface);
  color:var(--ink);cursor:pointer;display:flex;align-items:center;justify-content:center;
  box-shadow:var(--shadow-md);z-index:100;transition:transform .2s,background .3s,border-color .3s;
}
.theme-toggle:hover{transform:scale(1.08) rotate(15deg)}
.theme-toggle svg{width:16px;height:16px;stroke-width:2}
html[data-theme="dark"] .icon-moon{display:none}
html[data-theme="dark"] .icon-sun{display:block!important}
.icon-sun{display:none}

/* ============================================================
   CONTAINER
   ============================================================ */
.quiz-wrap{
  width:100%;
  max-width:880px;
  margin:0 auto;
  height:100%;
  display:flex;
  flex-direction:column;
  min-height:0;
}

/* ============================================================
   SELEZIONE LIVELLO
   ============================================================ */
.level-select{
  animation:fadeSlideIn .5s cubic-bezier(.4,0,.2,1);
  display:flex;
  flex-direction:column;
  height:100%;
  overflow-y:auto;
  padding:.4rem 0 1rem;
  scrollbar-width:thin;
  scrollbar-color:var(--border) transparent;
}
.level-select[hidden]{display:none}
.level-select::-webkit-scrollbar{width:6px}
.level-select::-webkit-scrollbar-thumb{background:var(--border);border-radius:99px}

.level-select-header{
  text-align:center;
  margin-bottom:1.4rem;
  flex-shrink:0;
  padding:0 .5rem;
}
.level-select-header h1{
  font-family:var(--font-display);
  font-size:clamp(1.35rem,3.6vw,2rem);
  font-weight:800;
  background:linear-gradient(135deg,var(--blue),var(--violet) 60%,var(--pink));
  -webkit-background-clip:text;background-clip:text;-webkit-text-fill-color:transparent;
  line-height:1.1;
  margin-bottom:.4rem;
  letter-spacing:-.02em;
}
.level-select-header p{
  color:var(--ink-soft);
  font-size:clamp(.85rem,1.6vw,.95rem);
  max-width:520px;
  margin:0 auto;
  line-height:1.4;
}

.level-cards{
  display:grid;
  grid-template-columns:1fr;
  gap:.85rem;
}
@media (min-width:640px){
  .level-cards{grid-template-columns:repeat(3,1fr)}
}

/* ============================================================
   LEVEL CARD
   ============================================================ */
.level-card{
  --level-color:var(--blue);
  position:relative;
  background:var(--surface);
  border:2px solid var(--border);
  border-radius:var(--radius-lg);
  padding:1.6rem .9rem 1rem;
  cursor:pointer;
  transition:transform .3s cubic-bezier(.4,0,.2,1),box-shadow .3s,border-color .3s;
  overflow:hidden;
  text-align:center;
  font-family:var(--font);
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:.35rem;
  min-height:210px;
}
.level-card::before{
  content:'';
  position:absolute;
  top:0;left:0;right:0;
  height:90px;
  background:linear-gradient(180deg,
    color-mix(in srgb, var(--level-color) 22%, transparent) 0%,
    transparent 100%);
  z-index:0;
  pointer-events:none;
}
.level-card::after{
  content:'';
  position:absolute;
  top:0;left:0;right:0;
  height:5px;
  background:linear-gradient(90deg, var(--level-color), color-mix(in srgb, var(--level-color) 40%, white));
  z-index:2;
}
.level-card > *{position:relative;z-index:1}

.level-card:hover:not(.locked){
  transform:translateY(-6px) scale(1.015);
  box-shadow:0 20px 40px -10px color-mix(in srgb, var(--level-color) 40%, transparent);
  border-color:var(--level-color);
}
.level-card:active:not(.locked){transform:translateY(-2px) scale(1.005)}

.level-card.unlocked:not(.completed):not(.locked){
  animation:levelPulse 2.6s ease-in-out infinite;
}
@keyframes levelPulse{
  0%,100%{box-shadow:0 0 0 0 color-mix(in srgb, var(--level-color) 0%, transparent)}
  50%{box-shadow:0 0 0 6px color-mix(in srgb, var(--level-color) 18%, transparent)}
}

.level-card.locked{
  cursor:not-allowed;
  opacity:.55;
  background:var(--bg-alt);
  filter:saturate(.4);
}
.level-card.locked::before{background:linear-gradient(180deg,rgba(120,120,140,.15),transparent)}
.level-card.locked::after{background:linear-gradient(90deg,#9aa0b5,#c0c4d4)}
.level-card.locked:hover{transform:none;box-shadow:none}

.level-card.completed::after{
  background:linear-gradient(90deg,var(--amber),var(--pink));
}

.level-card-icon-wrap{
  width:64px;height:64px;
  border-radius:50%;
  display:flex;align-items:center;justify-content:center;
  background:linear-gradient(135deg,
    color-mix(in srgb, var(--level-color) 20%, var(--surface)),
    color-mix(in srgb, var(--level-color) 6%, var(--surface)));
  border:2px solid color-mix(in srgb, var(--level-color) 35%, var(--border));
  margin-bottom:.15rem;
  transition:transform .3s cubic-bezier(.4,0,.2,1);
  flex-shrink:0;
}
.level-card:hover:not(.locked) .level-card-icon-wrap{
  transform:scale(1.08) rotate(-4deg);
}
.level-card-icon{
  font-size:2.1rem;line-height:1;
  filter:drop-shadow(0 3px 6px rgba(0,0,0,.12));
}
.level-card.locked .level-card-icon{filter:grayscale(1) opacity(.5)}

.level-card-name{
  font-family:var(--font-display);
  font-size:1.05rem;
  font-weight:800;
  color:var(--navy);
  letter-spacing:-.01em;
  line-height:1.15;
}
html[data-theme="dark"] .level-card-name{color:var(--ink)}

.level-card-desc{
  font-size:.78rem;
  color:var(--ink-soft);
  line-height:1.35;
  padding:0 .3rem;
  min-height:2.1em;
  display:flex;align-items:center;justify-content:center;
}

.level-card-stars{
  display:flex;
  justify-content:center;
  gap:.15rem;
  margin:.4rem 0 .15rem;
}
.lvl-star{
  font-size:1.15rem;
  line-height:1;
  color:var(--border);
  filter:drop-shadow(0 1px 1px rgba(0,0,0,.05));
  transition:transform .3s,color .3s;
}
.lvl-star.earned{
  color:#ffc233;
  text-shadow:0 2px 6px rgba(255,194,51,.5);
  animation:starPop .5s cubic-bezier(.68,-.55,.27,1.55) backwards;
}
.lvl-star.earned:nth-child(1){animation-delay:.05s}
.lvl-star.earned:nth-child(2){animation-delay:.15s}
.lvl-star.earned:nth-child(3){animation-delay:.25s}
@keyframes starPop{
  0%{transform:scale(0) rotate(-90deg)}
  100%{transform:scale(1) rotate(0)}
}

.level-card-status{
  display:inline-flex;
  align-items:center;
  gap:.3rem;
  margin-top:.3rem;
  font-size:.7rem;
  font-weight:800;
  text-transform:uppercase;
  letter-spacing:.05em;
  padding:.35rem .85rem;
  border-radius:99px;
  border:2px solid;
  transition:transform .2s;
}
.level-card-status .status-icon{
  font-size:.85rem;
  line-height:1;
}
.level-card-status.play{
  background:color-mix(in srgb, var(--level-color) 14%, transparent);
  border-color:var(--level-color);
  color:var(--level-color);
}
.level-card-status.completed{
  background:linear-gradient(135deg,rgba(47,191,113,.15),rgba(255,170,0,.15));
  border-color:var(--green);
  color:var(--green);
}
.level-card-status.locked{
  background:rgba(107,95,128,.08);
  border-color:var(--border);
  color:var(--ink-soft);
}

/* ============================================================
   QUIZ ATTIVO — GRID COMPATTA
   Banner + progress + HUD su 2 righe, poi stage.
   ============================================================ */
.quiz-active{
  display:grid;
  grid-template-columns:1fr auto;
  grid-template-rows:auto auto 1fr;
  gap:.5rem;
  flex:1;
  min-height:0;
  animation:fadeSlideIn .4s cubic-bezier(.4,0,.2,1);
}
.quiz-active[hidden]{display:none}

/* ============================================================
   BANNER LIVELLO (riga 1)
   ============================================================ */
.level-banner{
  grid-column:1 / -1;
  grid-row:1;
  display:flex;
  align-items:center;
  gap:.6rem;
  background:linear-gradient(135deg,
    color-mix(in srgb, var(--level-color,var(--blue)) 10%, var(--surface)),
    var(--surface));
  border:1.5px solid color-mix(in srgb, var(--level-color,var(--blue)) 25%, var(--border));
  border-radius:14px;
  padding:.55rem .9rem .85rem;
  box-shadow:var(--shadow-sm);
  position:relative;
  overflow:hidden;
  flex-shrink:0;
}
.level-banner::before{
  content:'';
  position:absolute;
  left:0;top:0;bottom:0;
  width:4px;
  background:var(--level-color,var(--blue));
}
.level-banner-icon{font-size:1.15rem;line-height:1;flex-shrink:0}
.level-banner-text{display:flex;flex-direction:column;flex:1;min-width:0}
.level-banner-label{
  font-size:.55rem;font-weight:800;text-transform:uppercase;
  letter-spacing:.06em;color:var(--ink-soft);line-height:1;
}
.level-banner-name{
  font-family:var(--font-display);font-size:.92rem;font-weight:800;
  color:var(--navy);line-height:1.15;
}
html[data-theme="dark"] .level-banner-name{color:var(--ink)}
.level-banner-exit{
  font-family:var(--font);font-size:.68rem;font-weight:700;
  padding:.3rem .7rem;border-radius:99px;
  border:1.5px solid var(--border);background:var(--surface);
  color:var(--ink-soft);cursor:pointer;transition:all .2s;flex-shrink:0;
}
.level-banner-exit:hover{
  border-color:var(--level-color,var(--blue));
  color:var(--level-color,var(--blue));
}

/* ============================================================
   PROGRESS BAR — integrata nel banner (riga 1, ancorata al fondo)
   ============================================================ */
.progress-wrap{
  grid-column:1 / -1;
  grid-row:1;
  align-self:end;
  height:4px;
  margin:0;
  background:rgba(0,0,0,.05);
  border:none;
  border-radius:0 0 14px 14px;
  box-shadow:none;
  overflow:hidden;
  z-index:5;
  padding:0;
  position:relative;
}
html[data-theme="dark"] .progress-wrap{
  background:rgba(255,255,255,.06);
}
.progress-bar{
  height:100%;
  width:0%;
  border-radius:0;
  background:linear-gradient(90deg, var(--blue), var(--violet));
  background-size:100% 100%;
  animation:none;
  transition:width .5s cubic-bezier(.4,0,.2,1);
}
.progress-bar::after{ display:none; }

/* ============================================================
   HUD (riga 2, colonna 1)
   ============================================================ */
.hud{
  grid-column:1;
  grid-row:2;
  display:grid;
  grid-template-columns:repeat(3,1fr);
  gap:.35rem;
  align-self:center;
}
.hud-item{
  background:var(--surface);
  border:1.5px solid var(--border);
  border-radius:12px;
  padding:.35rem .55rem;
  display:flex;
  align-items:center;
  gap:.4rem;
  box-shadow:var(--shadow-sm);
  transition:transform .2s,border-color .2s;
  min-width:0;
}
.hud-item.pulse{
  animation:hudBang .6s cubic-bezier(.68,-.55,.27,1.55);
  border-color:var(--amber)!important;
}
@keyframes hudBang{
  0%{transform:scale(1)}
  40%{transform:scale(1.15) rotate(-2deg)}
  70%{transform:scale(.95) rotate(1deg)}
  100%{transform:scale(1) rotate(0)}
}
.hud-icon{font-size:.95rem;line-height:1;flex-shrink:0}
.hud-content{display:flex;flex-direction:column;min-width:0}
.hud-label{
  font-size:.52rem;font-weight:800;text-transform:uppercase;
  letter-spacing:.05em;color:var(--ink-soft);line-height:1;
}
.hud-value{
  font-family:var(--font-display);font-size:.88rem;font-weight:800;
  color:var(--navy);line-height:1.15;
}
html[data-theme="dark"] .hud-value{color:var(--ink)}
.hud-value.streak-active{
  color:var(--amber);
  animation:streakGlow 1s ease infinite alternate;
}
@keyframes streakGlow{
  from{text-shadow:0 0 4px rgba(255,170,0,.4)}
  to{text-shadow:0 0 12px rgba(255,170,0,.9)}
}

/* ============================================================
   TIMER (riga 2, colonna 2)
   ============================================================ */
.timer-wrap{
  grid-column:2;
  grid-row:2;
  display:flex;
  align-items:center;
  justify-content:center;
  padding-right:.15rem;
  transition:opacity .3s;
}
.timer-wrap.hidden{display:none}
.timer-circle{width:46px;height:46px;position:relative}
.timer-circle svg{transform:rotate(-90deg);width:100%;height:100%}
.timer-circle .track{fill:none;stroke:var(--border);stroke-width:6}
.timer-circle .progress{
  fill:none;stroke:var(--green);stroke-width:6;stroke-linecap:round;
  stroke-dasharray:188.5;stroke-dashoffset:0;
  transition:stroke-dashoffset 1s linear,stroke .3s;
}
.timer-circle.warning .progress{stroke:var(--amber)}
.timer-circle.danger .progress{stroke:var(--red);animation:timerPulse .5s ease infinite alternate}
@keyframes timerPulse{from{opacity:1}to{opacity:.55}}
.timer-text{
  position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);
  font-family:var(--font-display);font-size:.95rem;font-weight:800;
  color:var(--navy);
}
html[data-theme="dark"] .timer-text{color:var(--ink)}
.timer-text.danger{color:var(--red);animation:timerPulse .5s ease infinite alternate}

/* ============================================================
   STAGE (riga 3)
   ============================================================ */
#quizStage{
  grid-column:1 / -1;
  grid-row:3;
  min-height:0;
  display:flex;
  flex-direction:column;
}

/* ============================================================
   CARD DOMANDA
   ============================================================ */
.question-card{
  background:var(--surface);
  border-radius:var(--radius-lg);
  padding:1rem 1.25rem 0;
  box-shadow:var(--shadow-md);
  border:1px solid var(--border);
  animation:fadeSlideIn .4s cubic-bezier(.4,0,.2,1);
  position:relative;
  flex:1;
  min-height:0;
  display:flex;
  flex-direction:column;
  overflow:hidden;
}
@keyframes fadeSlideIn{from{opacity:0;transform:translateY(14px)}to{opacity:1;transform:translateY(0)}}
.question-card.exit{animation:fadeSlideOut .28s ease forwards}
@keyframes fadeSlideOut{to{opacity:0;transform:translateY(-14px)}}

.question-num{
  display:inline-flex;align-items:center;justify-content:center;
  width:26px;height:26px;border-radius:50%;
  background:linear-gradient(135deg,var(--blue),var(--violet));
  color:#fff;font-weight:800;font-size:.78rem;
  margin-bottom:.5rem;
  box-shadow:0 4px 10px rgba(91,141,239,.35);
  flex-shrink:0;
}
.question-text{
  font-family:var(--font-display);
  font-size:clamp(.95rem,1.6vw,1.08rem);
  font-weight:700;
  color:var(--navy);
  line-height:1.35;
  margin-bottom:.75rem;
}
html[data-theme="dark"] .question-text{color:var(--ink)}

/* ============================================================
   OPZIONI (con shape ▲◆●■ colorate)
   ============================================================ */
.options{display:flex;flex-direction:column;gap:.4rem}

.option{--opt-color:#8a94b0;}
.option:nth-child(1){--opt-color:#e85555;}   /* rosso   ▲ */
.option:nth-child(2){--opt-color:#4b7ee5;}   /* blu     ◆ */
.option:nth-child(3){--opt-color:#e5b54b;}   /* giallo  ● */
.option:nth-child(4){--opt-color:#4bc994;}   /* verde   ■ */
.option:nth-child(5){--opt-color:#b18beb;}   /* viola   ★ */
.option:nth-child(6){--opt-color:#ee9bc0;}   /* rosa    ♥ */

.option{
  display:flex;align-items:center;gap:.7rem;
  width:100%;text-align:left;
  background:var(--bg-alt);
  border:1.5px solid var(--border);
  border-radius:12px;
  padding:.6rem .85rem;
  cursor:pointer;
  font-family:var(--font);
  font-size:clamp(.85rem,1.4vw,.92rem);
  font-weight:600;
  color:var(--ink);
  transition:all .2s cubic-bezier(.4,0,.2,1);
  position:relative;
  overflow:hidden;
  animation:fadeSlideIn .35s cubic-bezier(.4,0,.2,1) backwards;
}
.option:nth-child(1){animation-delay:.04s}
.option:nth-child(2){animation-delay:.08s}
.option:nth-child(3){animation-delay:.12s}
.option:nth-child(4){animation-delay:.16s}
.option:nth-child(5){animation-delay:.20s}
.option:nth-child(6){animation-delay:.24s}

.option:hover:not(.locked){
  border-color:var(--opt-color);
  background:var(--surface);
  transform:translateX(3px);
  box-shadow:0 4px 14px color-mix(in srgb, var(--opt-color) 25%, transparent);
}
.option:hover:not(.locked) .option-letter{
  background:var(--opt-color);
  border-color:var(--opt-color);
  color:#fff;
}

.option-letter{
  flex-shrink:0;
  width:26px;height:26px;
  border-radius:50%;
  background:var(--surface);
  border:1.5px solid var(--border);
  display:flex;align-items:center;justify-content:center;
  font-weight:900;font-size:.85rem;
  color:var(--ink-soft);
  transition:all .2s;
}
.option:nth-child(1) .option-letter{color:#e85555;border-color:#e85555;}
.option:nth-child(2) .option-letter{color:#4b7ee5;border-color:#4b7ee5;}
.option:nth-child(3) .option-letter{color:#e5b54b;border-color:#e5b54b;}
.option:nth-child(4) .option-letter{color:#4bc994;border-color:#4bc994;}
.option:nth-child(5) .option-letter{color:#b18beb;border-color:#b18beb;}
.option:nth-child(6) .option-letter{color:#ee9bc0;border-color:#ee9bc0;}

.option-text{flex:1;line-height:1.35}

.option.selected{border-color:var(--opt-color);background:rgba(91,141,239,.08)}
.option.selected .option-letter{background:var(--opt-color);border-color:var(--opt-color);color:#fff}

.option.correct{
  border-color:var(--green);
  background:rgba(47,191,113,.12);
  animation:pulseCorrect .5s ease;
}
.option.correct .option-letter{
  background:var(--green);border-color:var(--green);color:#fff;
}
.option.incorrect{
  border-color:var(--red);
  background:rgba(239,71,111,.12);
  animation:shakeOpt .4s ease;
}
.option.incorrect .option-letter{
  background:var(--red);border-color:var(--red);color:#fff;
}
.option.locked{cursor:default}
@keyframes pulseCorrect{
  0%{transform:scale(1)}
  50%{transform:scale(1.015)}
  100%{transform:scale(1)}
}
@keyframes shakeOpt{
  0%,100%{transform:translateX(0)}
  25%{transform:translateX(-6px)}
  75%{transform:translateX(6px)}
}
.option-feedback{flex-shrink:0;width:18px;height:18px;display:none}
.option.correct .option-feedback,
.option.incorrect .option-feedback{display:block}

/* ============================================================
   SPIEGAZIONE
   ============================================================ */
.explanation{
  margin-top:.65rem;
  padding:.65rem .85rem;
  border-radius:12px;
  background:var(--bg-alt);
  border-left:4px solid var(--blue);
  font-size:clamp(.8rem,1.3vw,.86rem);
  color:var(--ink-soft);
  line-height:1.45;
  display:none;
  animation:fadeSlideIn .3s ease;
}
.explanation.show{display:block}
.explanation strong{color:var(--ink)}

/* ============================================================
   AZIONI
   ============================================================ */
.actions{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:.5rem;
  padding:.7rem 0;
  border-top:1px solid var(--border);
  background:var(--surface);
  flex-shrink:0;
  margin-top:.6rem;
}
.btn{
  font-family:var(--font);
  font-weight:700;
  font-size:clamp(.82rem,1.3vw,.9rem);
  padding:.6rem 1.15rem;
  border-radius:12px;
  border:none;
  cursor:pointer;
  transition:all .2s cubic-bezier(.4,0,.2,1);
  display:inline-flex;
  align-items:center;
  gap:.4rem;
  flex-shrink:0;
}
.btn-primary{
  background:linear-gradient(135deg,var(--blue),var(--violet));
  color:#fff;
  box-shadow:0 6px 16px rgba(91,141,239,.35);
}
.btn-primary:hover:not(:disabled){
  transform:translateY(-2px);
  box-shadow:0 10px 22px rgba(91,141,239,.45);
}
.btn-primary:disabled{opacity:.5;cursor:not-allowed;box-shadow:none}
.btn-ghost{
  background:transparent;
  color:var(--ink-soft);
  border:1.5px solid var(--border);
}
.btn-ghost:hover{border-color:var(--blue);color:var(--blue)}
.btn svg{width:14px;height:14px;stroke-width:2.5}

/* ============================================================
   RISULTATI
   ============================================================ */
.results-card{
  background:var(--surface);
  border-radius:var(--radius-lg);
  padding:1.5rem 1.25rem;
  box-shadow:var(--shadow-lg);
  border:1px solid var(--border);
  text-align:center;
  animation:fadeSlideIn .45s cubic-bezier(.4,0,.2,1);
  position:relative;
  overflow:hidden;
  flex:1;
  min-height:0;
  overflow-y:auto;
  scrollbar-width:thin;
  scrollbar-color:var(--border) transparent;
}
.results-card::-webkit-scrollbar{width:6px}
.results-card::-webkit-scrollbar-thumb{background:var(--border);border-radius:99px}
.results-card::before{
  content:'';
  position:absolute;top:-50%;left:-50%;width:200%;height:200%;
  background:radial-gradient(circle,rgba(91,141,239,.08),transparent 60%);
  animation:rotateBg 20s linear infinite;
  pointer-events:none;
}
@keyframes rotateBg{from{transform:rotate(0)}to{transform:rotate(360deg)}}
.results-emoji{
  font-size:2.8rem;
  line-height:1;
  margin-bottom:.4rem;
  animation:bounceIn .6s cubic-bezier(.68,-.55,.27,1.55);
  position:relative;z-index:1;
}
@keyframes bounceIn{
  0%{transform:scale(0)}
  60%{transform:scale(1.15)}
  100%{transform:scale(1)}
}
.results-title{
  font-family:var(--font-display);
  font-size:1.25rem;font-weight:800;
  color:var(--navy);
  margin-bottom:.2rem;
  position:relative;z-index:1;
}
html[data-theme="dark"] .results-title{color:var(--ink)}
.results-score{
  font-family:var(--font-display);
  font-size:2.6rem;font-weight:800;
  background:linear-gradient(135deg,var(--blue),var(--violet));
  -webkit-background-clip:text;background-clip:text;-webkit-text-fill-color:transparent;
  line-height:1;
  margin:.2rem 0;
  position:relative;z-index:1;
}
.results-message{
  color:var(--ink-soft);
  font-size:.88rem;
  margin-bottom:.85rem;
  position:relative;z-index:1;
}
.stars{
  display:flex;justify-content:center;gap:.35rem;
  margin:.4rem 0 .8rem;
  position:relative;z-index:1;
}
.star{
  font-size:2rem;
  line-height:1;
  filter:grayscale(1) opacity(.3);
  transition:all .3s cubic-bezier(.68,-.55,.27,1.55);
}
.star.earned{
  filter:none;
  animation:starPop .5s cubic-bezier(.68,-.55,.27,1.55) forwards;
}
.star.earned:nth-child(1){animation-delay:.1s}
.star.earned:nth-child(2){animation-delay:.3s}
.star.earned:nth-child(3){animation-delay:.5s}

.next-level-preview{
  background:linear-gradient(135deg,rgba(91,141,239,.08),rgba(155,93,229,.08));
  border:2px dashed var(--blue);
  border-radius:12px;
  padding:.7rem .9rem;
  margin:.6rem 0 .9rem;
  position:relative;z-index:1;
  text-align:left;
}
.next-level-preview .nlp-label{
  font-size:.6rem;font-weight:800;text-transform:uppercase;
  letter-spacing:.05em;color:var(--blue);margin-bottom:.2rem;
}
.next-level-preview .nlp-name{
  font-family:var(--font-display);font-size:.95rem;font-weight:800;
  color:var(--navy);margin-bottom:.15rem;
}
html[data-theme="dark"] .next-level-preview .nlp-name{color:var(--ink)}
.next-level-preview .nlp-desc{font-size:.78rem;color:var(--ink-soft)}

.best-score{
  background:var(--bg-alt);
  border-radius:12px;
  padding:.6rem .8rem;
  margin-bottom:.8rem;
  font-size:.8rem;
  color:var(--ink-soft);
  border:1px dashed var(--border);
  position:relative;z-index:1;
}
.best-score strong{color:var(--amber);font-size:.92rem}

.results-actions{
  display:flex;gap:.5rem;justify-content:center;flex-wrap:wrap;
  position:relative;z-index:1;
}

.summary{
  text-align:left;
  margin:1rem 0;
  border-top:1px solid var(--border);
  padding-top:.85rem;
  position:relative;z-index:1;
}
.summary h3{
  font-family:var(--font-display);font-size:.9rem;
  color:var(--navy);margin-bottom:.6rem;text-align:center;
}
html[data-theme="dark"] .summary h3{color:var(--ink)}
.summary-item{
  display:flex;gap:.55rem;align-items:flex-start;
  padding:.55rem .7rem;
  border-radius:10px;
  margin-bottom:.35rem;
  font-size:.82rem;
  background:var(--bg-alt);
  border-left:3px solid var(--border);
}
.summary-item.ok{border-left-color:var(--green)}
.summary-item.ko{border-left-color:var(--red)}
.summary-icon{flex-shrink:0;font-size:.95rem;line-height:1.2}
.summary-text{flex:1;color:var(--ink-soft)}
.summary-text strong{color:var(--ink);display:block;margin-bottom:.1rem}

/* ============================================================
   KAHOOT MOMENTS — overlay, floating points, streak, confetti
   ============================================================ */
.floating-points{
  position:fixed;
  pointer-events:none;
  font-family:var(--font-display);
  font-size:2rem;
  font-weight:900;
  color:var(--green);
  text-shadow:
    0 3px 0 rgba(255,255,255,.4),
    0 6px 16px rgba(47,191,113,.55);
  animation:floatUp 1.4s cubic-bezier(.68,-.55,.27,1.55) forwards;
  z-index:999;
}
.floating-points.streak-bonus{
  color:var(--amber);
  text-shadow:
    0 3px 0 rgba(255,255,255,.4),
    0 6px 16px rgba(255,170,0,.7);
}
@keyframes floatUp{
  0%{opacity:0;transform:translateY(0) scale(.4) rotate(-8deg)}
  15%{opacity:1;transform:translateY(-14px) scale(1.15) rotate(3deg)}
  35%{transform:translateY(-24px) scale(1.05) rotate(-2deg)}
  100%{opacity:0;transform:translateY(-110px) scale(1.1) rotate(0)}
}

.streak-banner{
  position:fixed;top:50%;left:50%;
  transform:translate(-50%,-50%) scale(0);
  background:linear-gradient(135deg,#ff5c8a,#ffaa00);
  color:#fff;
  font-family:var(--font-display);font-weight:800;
  font-size:1.25rem;
  padding:.85rem 1.6rem;
  border-radius:99px;
  box-shadow:0 15px 40px rgba(255,92,138,.6);
  z-index:1000;
  pointer-events:none;
  animation:streakPop 1.5s ease forwards;
}
@keyframes streakPop{
  0%{transform:translate(-50%,-50%) scale(0);opacity:0}
  20%{transform:translate(-50%,-50%) scale(1.1);opacity:1}
  40%{transform:translate(-50%,-50%) scale(1);opacity:1}
  80%{transform:translate(-50%,-50%) scale(1);opacity:1}
  100%{transform:translate(-50%,-50%) scale(.8);opacity:0}
}

.confetti{
  position:fixed;
  width:10px;height:10px;
  top:-10px;
  z-index:998;
  pointer-events:none;
  animation:confettiFall linear forwards;
}
@keyframes confettiFall{
  0%{transform:translateY(0) rotate(0);opacity:1}
  100%{transform:translateY(100vh) rotate(720deg);opacity:0}
}

/* Overlay feedback a tutto schermo */
.feedback-overlay{
  position:fixed;
  inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  z-index:2000;
  pointer-events:none;
  animation:overlayFade 900ms ease forwards;
  padding:1rem;
}
.feedback-overlay .feedback-text{
  font-family:var(--font-display);
  font-size:clamp(2.4rem,7vw,4.5rem);
  font-weight:900;
  letter-spacing:-.02em;
  line-height:1;
  padding:1.2rem 2.8rem;
  border-radius:28px;
  color:#fff;
  transform:rotate(-3deg);
  text-align:center;
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:.4rem;
  animation:overlayPop 900ms cubic-bezier(.68,-.55,.27,1.55);
}
.feedback-overlay .feedback-emoji{
  font-size:clamp(2.5rem,6vw,3.5rem);
  line-height:1;
  filter:drop-shadow(0 4px 10px rgba(0,0,0,.2));
}
.feedback-overlay .feedback-points{
  font-size:clamp(1.3rem,3vw,1.8rem);
  font-weight:800;
  background:rgba(255,255,255,.22);
  padding:.35rem 1rem;
  border-radius:99px;
  margin-top:.3rem;
}
.feedback-overlay.is-correct .feedback-text{
  background:linear-gradient(135deg,#2fbf71,#4dd18a);
  box-shadow:0 20px 60px rgba(47,191,113,.5),
             0 0 0 8px rgba(47,191,113,.15);
  text-shadow:0 3px 12px rgba(0,0,0,.15);
}
.feedback-overlay.is-wrong .feedback-text{
  background:linear-gradient(135deg,#ef476f,#e87a7a);
  box-shadow:0 20px 60px rgba(239,71,111,.5),
             0 0 0 8px rgba(239,71,111,.15);
  text-shadow:0 3px 12px rgba(0,0,0,.15);
}
@keyframes overlayFade{
  0%{opacity:0}
  10%{opacity:1}
  80%{opacity:1}
  100%{opacity:0}
}
@keyframes overlayPop{
  0%{transform:rotate(-3deg) scale(.5)}
  30%{transform:rotate(-3deg) scale(1.08)}
  50%{transform:rotate(-3deg) scale(.98)}
  70%{transform:rotate(-3deg) scale(1)}
  100%{transform:rotate(-3deg) scale(1)}
}

/* ============================================================
   KIDS MODE — palette pastello, look amichevole per la primaria
   ============================================================ */
body.mode-kids{
  --bg:#f7f9ff;
  --bg-alt:#eef3fc;
  --surface:#ffffff;
  --border:#dfe7f5;
  --ink:#2b3552;
  --ink-soft:#7a869e;
  --blue:#6fa8e8;
  --violet:#a48ce0;
  --pink:#ee9bc0;
  --green:#5fc99a;
  --amber:#f0b95c;
  --red:#e87a7a;
  --font-display:'Plus Jakarta Sans',system-ui,sans-serif;

  background:
    radial-gradient(circle at 0% 0%, rgba(164,140,224,.10), transparent 45%),
    radial-gradient(circle at 100% 100%, rgba(111,168,232,.10), transparent 45%),
    #f7f9ff;
}

body.mode-kids .level-select-header h1{
  background:linear-gradient(135deg,#6fa8e8,#a48ce0);
  -webkit-background-clip:text;background-clip:text;
  -webkit-text-fill-color:transparent;
}
body.mode-kids .level-select-header p{color:#7a869e;}

body.mode-kids .level-card{
  border-width:2px;
  border-radius:22px;
  min-height:230px;
  padding:1.6rem 1rem 1rem;
}
body.mode-kids .level-card::before{height:100px}
body.mode-kids .level-card::after{height:6px;border-radius:22px 22px 0 0}
body.mode-kids .level-card:hover:not(.locked){
  transform:translateY(-4px);
  box-shadow:0 16px 32px -10px color-mix(in srgb, var(--level-color) 35%, transparent);
}
body.mode-kids .level-card-icon-wrap{
  width:76px;height:76px;
  border-width:2px;
  box-shadow:0 4px 14px color-mix(in srgb, var(--level-color) 25%, transparent);
}
body.mode-kids .level-card-icon{font-size:2.4rem}
body.mode-kids .level-card-name{font-size:1.18rem}
body.mode-kids .level-card-desc{font-size:.85rem}
body.mode-kids .lvl-star{font-size:1.3rem}
body.mode-kids .level-card-status{padding:.4rem .95rem;font-size:.72rem}

body.mode-kids .level-banner{
  padding:.6rem .95rem .9rem;
  border-radius:16px;
}
body.mode-kids .progress-wrap{
  border-radius:0 0 16px 16px;
}
body.mode-kids .level-banner-icon{font-size:1.25rem}
body.mode-kids .level-banner-name{font-size:.98rem}
body.mode-kids .level-banner-exit{
  padding:.35rem .8rem;
  font-size:.72rem;
  border-radius:99px;
}

body.mode-kids .hud-item[data-hud="progress"]{
  background:linear-gradient(135deg,
    color-mix(in srgb, var(--level-color,var(--blue)) 14%, #fff),
    color-mix(in srgb, var(--level-color,var(--blue)) 6%, #fff));
  border:2px solid color-mix(in srgb, var(--level-color,var(--blue)) 30%, var(--border));
}
body.mode-kids .hud-item[data-hud="progress"] .hud-value{color:#2b3552;}

body.mode-kids .question-card{
  border-radius:24px;
  border:1.5px solid #e4ebf8;
  padding:1.2rem 1.35rem 0;
  box-shadow:
    0 4px 12px rgba(111,168,232,.08),
    0 12px 28px rgba(111,168,232,.10);
}
body.mode-kids .question-num{
  width:36px;height:36px;
  font-size:.9rem;
  background:linear-gradient(135deg,#6fa8e8,#a48ce0);
  box-shadow:0 4px 10px rgba(111,168,232,.30);
}
body.mode-kids .question-text{
  font-size:clamp(1.05rem,1.8vw,1.18rem);
  color:#2b3552;
  margin-bottom:.9rem;
}

body.mode-kids .option{
  padding:.8rem 1rem;
  border-width:2px;
  border-radius:14px;
  font-size:clamp(.9rem,1.5vw,1rem);
}
body.mode-kids .option-letter{
  width:32px;height:32px;
  font-size:.9rem;
  border-width:2px;
}
body.mode-kids .option.correct{
  background:#e8f7ef;
  box-shadow:0 4px 12px rgba(95,201,154,.22);
}
body.mode-kids .option.incorrect{
  background:#fdeaea;
  box-shadow:0 4px 12px rgba(232,122,122,.20);
}

body.mode-kids .explanation{
  border-radius:14px;
  border:1.5px solid #f0e0b8;
  border-left:4px solid #f0b95c;
  background:#fffbf0;
  padding:.8rem .95rem .8rem 1rem;
  font-size:clamp(.86rem,1.4vw,.95rem);
  color:#6b5a3d;
  position:relative;
}
body.mode-kids .explanation::before{
  content:'💡';
  position:absolute;
  top:-13px;left:14px;
  font-size:1.3rem;
  filter:drop-shadow(0 2px 4px rgba(240,185,92,.35));
  background:#fffbf0;
  padding:0 4px;
  border-radius:50%;
}
body.mode-kids .explanation strong{color:#2b3552}

body.mode-kids .btn{
  padding:.75rem 1.4rem;
  font-size:clamp(.88rem,1.4vw,.95rem);
  border-radius:12px;
}
body.mode-kids .btn-primary{
  background:linear-gradient(135deg,#6fa8e8,#a48ce0);
  box-shadow:0 5px 14px rgba(111,168,232,.30);
}
body.mode-kids .btn-primary:hover:not(:disabled){
  transform:translateY(-2px);
  box-shadow:0 8px 20px rgba(111,168,232,.40);
}
body.mode-kids .btn-ghost{
  border-width:1.5px;
  border-color:#dfe7f5;
  background:#fff;
  color:#7a869e;
}
body.mode-kids .btn-ghost:hover{
  border-color:#6fa8e8;
  color:#6fa8e8;
}
body.mode-kids .actions{
  padding:.85rem 0;
  border-top:1px solid #eef3fc;
}

body.mode-kids .timer-circle{width:52px;height:52px}
body.mode-kids .timer-circle .track{stroke:#e4ebf8}
body.mode-kids .timer-circle .progress{stroke:#5fc99a}
body.mode-kids .timer-text{font-size:1.05rem;color:#2b3552}

body.mode-kids .results-card{
  border-radius:24px;
  border:1.5px solid #e4ebf8;
  padding:1.7rem 1.3rem;
  background:#fff;
  box-shadow:
    0 4px 12px rgba(111,168,232,.08),
    0 12px 28px rgba(111,168,232,.12);
}
body.mode-kids .results-emoji{font-size:3.4rem}
body.mode-kids .results-title{font-size:1.4rem;color:#2b3552}
body.mode-kids .results-score{font-size:2.8rem}
body.mode-kids .results-message{font-size:.95rem;color:#7a869e}
body.mode-kids .star{font-size:2.1rem}
body.mode-kids .next-level-preview{
  border-radius:14px;
  border:1.5px dashed #6fa8e8;
  background:linear-gradient(135deg,rgba(111,168,232,.06),rgba(164,140,224,.06));
}
body.mode-kids .best-score{
  border-radius:14px;
  border:1.5px dashed #dfe7f5;
}
body.mode-kids .feedback-overlay .feedback-text{
  font-size:clamp(2.6rem,8vw,5rem);
  padding:1.4rem 3rem;
}
body.mode-kids .floating-points{font-size:2.4rem;}

/* ============================================================
   RESPONSIVE — mobile
   ============================================================ */
@media (max-width:640px){
  body{padding:.5rem}
  .quiz-wrap{max-width:100%}
  .level-select-header{margin-bottom:1rem}
  .level-cards{gap:.7rem}
  .level-card{padding:1.3rem .8rem .9rem;min-height:190px}
  .level-card-icon-wrap{width:56px;height:56px}
  .level-card-icon{font-size:1.8rem}
  .level-card-name{font-size:.98rem}
  .level-card-desc{font-size:.74rem}

  .level-banner{padding:.4rem .7rem .7rem;gap:.5rem}
  .level-banner-icon{font-size:1rem}
  .level-banner-name{font-size:.85rem}
  .level-banner-exit{font-size:.62rem;padding:.25rem .55rem}

  .hud{gap:.3rem}
  .hud-item{padding:.3rem .45rem;gap:.35rem}
  .hud-icon{font-size:.85rem}
  .hud-value{font-size:.8rem}
  .hud-label{font-size:.48rem}

  .timer-circle{width:40px;height:40px}
  .timer-text{font-size:.82rem}

  .question-card{padding:.85rem 1rem 0}
  .question-text{font-size:.95rem;margin-bottom:.65rem}
  .option{padding:.55rem .75rem;font-size:.85rem;gap:.55rem}
  .option-letter{width:24px;height:24px;font-size:.78rem}

  .actions{gap:.4rem;padding:.6rem 0}
  .btn{padding:.55rem 1rem;font-size:.8rem}

  .results-card{padding:1.2rem .9rem}
  .results-emoji{font-size:2.4rem}
  .results-title{font-size:1.1rem}
  .results-score{font-size:2.2rem}
  .star{font-size:1.7rem}
}

/* Schermi molto bassi (landscape telefono) */
@media (max-height:600px){
  .level-select-header h1{font-size:1.15rem}
  .level-select-header p{font-size:.8rem}
  .level-card{padding:1rem .7rem .7rem;min-height:auto}
  .level-card-icon-wrap{width:46px;height:46px}
  .level-card-icon{font-size:1.5rem}
  .level-card-desc{display:none}
  .lvl-star{font-size:1rem}

  .question-card{padding:.7rem .9rem 0}
  .question-text{font-size:.9rem;margin-bottom:.5rem}
  .option{padding:.5rem .7rem;font-size:.82rem}
  .option-letter{width:22px;height:22px;font-size:.7rem}
  .actions{padding:.5rem 0;margin-top:.4rem}
  .btn{padding:.5rem .85rem;font-size:.78rem}
  .hud-item{padding:.28rem .5rem}
  .timer-circle{width:38px;height:38px}

  body.mode-kids .level-card{min-height:auto;padding:1rem .8rem .7rem}
  body.mode-kids .level-card-icon-wrap{width:52px;height:52px}
  body.mode-kids .level-card-icon{font-size:1.7rem}
  body.mode-kids .lvl-star{font-size:1rem}
  body.mode-kids .option{padding:.55rem .75rem;font-size:.85rem}
  body.mode-kids .option-letter{width:26px;height:26px;font-size:.78rem}
}

/* Fallback per browser senza color-mix */
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .level-card::before{background:linear-gradient(180deg, rgba(91,141,239,.12), transparent)}
  .level-card-icon-wrap{background:var(--bg-alt);border-color:var(--border)}
  .level-card:hover:not(.locked){box-shadow:var(--shadow-lg)}
  .level-card.unlocked:not(.completed):not(.locked){animation:none}
  .level-banner{background:var(--surface)}
  .option:hover:not(.locked){box-shadow:var(--shadow-sm)}
}

/* Accessibilità: rispetta chi preferisce meno motion */
@media (prefers-reduced-motion: reduce){
  .feedback-overlay,
  .feedback-overlay .feedback-text,
  .floating-points,
  .hud-item.pulse,
  .level-card.unlocked:not(.completed):not(.locked){animation-duration:.01ms!important}
  .progress-bar{transition:none}
}

/* ============================================================
   KIDS: opzioni su 2 colonne (stile Kahoot)
   ============================================================ */
body.mode-kids .options{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:.55rem;
}

body.mode-kids .option{
  padding:.85rem .9rem;
  min-height:64px;
  align-items:center;
}

body.mode-kids .option-text{
  font-size:clamp(.85rem,1.4vw,.98rem);
  line-height:1.25;
}

body.mode-kids .option-letter{
  width:30px;
  height:30px;
  font-size:.85rem;
  flex-shrink:0;
}

/* Se il numero di opzioni è dispari, l'ultima occupa tutta la riga */
body.mode-kids .options > .option:last-child:nth-child(odd){
  grid-column:1 / -1;
}

/* Su mobile le opzioni lunghe non stanno in 2 colonne: torna a 1 */
@media (max-width:520px){
  body.mode-kids .options{
    grid-template-columns:1fr;
  }
  body.mode-kids .option{
    min-height:auto;
  }
}

/* Landscape telefono: torna a 1 colonna */
@media (max-height:600px){
  body.mode-kids .options{
    grid-template-columns:1fr;
  }
  body.mode-kids .option{
    min-height:auto;
  }
}

/* ============================================================
   KIDS: numero + domanda sulla stessa riga
   ============================================================ */
body.mode-kids .question-card{
  display:grid;
  grid-template-columns:auto 1fr;
  column-gap:.7rem;
  row-gap:0;
}
body.mode-kids .question-num{
  grid-column:1;
  grid-row:1;
  margin-bottom:0;
  align-self:start;
  margin-top:.15rem;   /* allinea otticamente col testo */
}
body.mode-kids .question-text{
  grid-column:2;
  grid-row:1;
  margin-bottom:.9rem;
}
/* Options, spiegazione e azioni occupano tutta la larghezza */
body.mode-kids .options,
body.mode-kids .explanation,
body.mode-kids .actions{
  grid-column:1 / -1;
}

/* ============================================================
   KIDS: opzioni Kahoot — compatte, colorate a tinta piena
   ============================================================ */

/* Griglia 2 colonne con gap minimo */
body.mode-kids .options{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:.45rem;
}

/* Riquadro colorato pieno, basso */
body.mode-kids .option{
  --c1: #e85555;
  --c2: #e85555;
  padding:.55rem .7rem;
  min-height:52px;
  border:none;
  border-radius:12px;
  background:linear-gradient(135deg, var(--c1), var(--c2));
  color:#fff;
  box-shadow:0 3px 0 rgba(0,0,0,.14), 0 6px 14px rgba(0,0,0,.10);
  transform:none;
  transition:transform .15s, box-shadow .15s;
  font-weight:700;
  font-size:clamp(.85rem,1.3vw,.95rem);
  gap:.5rem;
}
body.mode-kids .option:nth-child(1){--c1:#e85555; --c2:#d13f3f;}
body.mode-kids .option:nth-child(2){--c1:#4b7ee5; --c2:#3a68c8;}
body.mode-kids .option:nth-child(3){--c1:#e5b54b; --c2:#c99a2e;}
body.mode-kids .option:nth-child(4){--c1:#4bc994; --c2:#33a878;}
body.mode-kids .option:nth-child(5){--c1:#a48ce0; --c2:#8a6fcf;}
body.mode-kids .option:nth-child(6){--c1:#ee9bc0; --c2:#d47aa6;}

/* Hover: solleva leggermente */
body.mode-kids .option:hover:not(.locked){
  transform:translateY(-2px);
  box-shadow:0 5px 0 rgba(0,0,0,.14), 0 10px 18px rgba(0,0,0,.14);
}
body.mode-kids .option:active:not(.locked){
  transform:translateY(1px);
  box-shadow:0 2px 0 rgba(0,0,0,.14);
}

/* Numero/forma nel pallino bianco semitrasparente */
body.mode-kids .option-letter{
  width:26px;
  height:26px;
  background:rgba(255,255,255,.22);
  border:1.5px solid rgba(255,255,255,.55);
  color:#fff;
  font-size:.78rem;
  font-weight:900;
}
body.mode-kids .option:hover:not(.locked) .option-letter{
  background:#fff;
  border-color:#fff;
  color:var(--c1);
}
body.mode-kids .option:nth-child(1) .option-letter,
body.mode-kids .option:nth-child(2) .option-letter,
body.mode-kids .option:nth-child(3) .option-letter,
body.mode-kids .option:nth-child(4) .option-letter,
body.mode-kids .option:nth-child(5) .option-letter,
body.mode-kids .option:nth-child(6) .option-letter{
  color:#fff;
  border-color:rgba(255,255,255,.55);
}

body.mode-kids .option-text{
  color:#fff;
  line-height:1.2;
  font-weight:700;
}

/* Corretto: diventa verde brillante, indipendente dal colore originale */
body.mode-kids .option.correct{
  background:linear-gradient(135deg,#2fbf71,#25a862);
  color:#fff;
  border:none;
  box-shadow:0 3px 0 rgba(0,0,0,.14), 0 8px 20px rgba(47,191,113,.45);
}
body.mode-kids .option.correct .option-letter{
  background:#fff;
  border-color:#fff;
  color:#2fbf71;
}
body.mode-kids .option.correct .option-text{color:#fff}

/* Sbagliato: diventa rosso/rosa intenso */
body.mode-kids .option.incorrect{
  background:linear-gradient(135deg,#ef476f,#cf2f56);
  color:#fff;
  border:none;
  box-shadow:0 3px 0 rgba(0,0,0,.14), 0 8px 20px rgba(239,71,111,.45);
}
body.mode-kids .option.incorrect .option-letter{
  background:#fff;
  border-color:#fff;
  color:#ef476f;
}
body.mode-kids .option.incorrect .option-text{color:#fff}

/* Le altre opzioni (non scelte) diventano opache */
body.mode-kids .option.locked:not(.correct):not(.incorrect){
  opacity:.45;
  filter:grayscale(.4);
}

/* Ultima opzione su riga intera se il numero è dispari */
body.mode-kids .options > .option:last-child:nth-child(odd){
  grid-column:1 / -1;
}

/* Mobile: torna a 1 colonna */
@media (max-width:520px){
  body.mode-kids .options{grid-template-columns:1fr;}
}
@media (max-height:600px){
  body.mode-kids .options{grid-template-columns:1fr;}
  body.mode-kids .option{min-height:44px;padding:.45rem .65rem;}
}
/* ============================================================
   FIX — hover colorato + layout compatto (kids)
   ============================================================ */

/* 1. HOVER: mantiene il gradiente colorato e il testo bianco */
body.mode-kids .option:hover:not(.locked){
  background:linear-gradient(135deg, var(--c1), var(--c2)) !important;
  color:#fff !important;
  transform:translateY(-2px);
  box-shadow:0 5px 0 rgba(0,0,0,.14), 0 10px 18px rgba(0,0,0,.14);
}
body.mode-kids .option:hover:not(.locked) .option-text{
  color:#fff !important;
}
body.mode-kids .option:hover:not(.locked) .option-letter{
  background:#fff;
  border-color:#fff;
  color:var(--c1);
}

/* 2. LAYOUT COMPATTO: contenuto ancorato in alto, niente righe gonfiate */
body.mode-kids .question-card{
  align-content:start;
  padding:.9rem 1.1rem .7rem;
  row-gap:.3rem;
}

/* 3. Riduci ulteriormente gli spazi interni */
body.mode-kids .question-text{
  margin-bottom:.35rem;
}
body.mode-kids .question-num{
  margin-top:.1rem;
}
body.mode-kids .options{
  gap:.4rem;
}
body.mode-kids .option{
  min-height:46px;
  padding:.5rem .7rem;
}
body.mode-kids .option-letter{
  width:26px;
  height:26px;
  font-size:.78rem;
}
body.mode-kids .actions{
  margin-top:.55rem;
  padding:.55rem 0;
}
body.mode-kids .explanation{
  margin-top:.45rem;
  padding:.55rem .8rem;
}
/* ============================================================
   FIX 2 — bilanciamento spazi (kids)
   ============================================================ */

body.mode-kids .question-card{
  padding:1.1rem 1.3rem .9rem;
  row-gap:.55rem;      /* respiro tra le righe della grid */
}

body.mode-kids .question-text{
  margin-bottom:.55rem;
  line-height:1.4;
}

body.mode-kids .question-num{
  margin-top:.2rem;
}

body.mode-kids .options{
  gap:.55rem;          /* respiro tra le opzioni */
  margin-top:.35rem;   /* stacco dalla domanda */
}

body.mode-kids .option{
  min-height:54px;
  padding:.65rem .85rem;
}

body.mode-kids .option-letter{
  width:28px;
  height:28px;
  font-size:.82rem;
}

body.mode-kids .actions{
  margin-top:.9rem;    /* stacco prima dei pulsanti */
  padding:.75rem 0;
}

body.mode-kids .explanation{
  margin-top:.7rem;
  padding:.7rem .9rem;
}

/* ============================================================
   FIX 3 — bilanciamento definitivo (kids)
   Card in alto, pulsanti ancorati in basso, spazio distribuito bene
   ============================================================ */

body.mode-kids .question-card{
  padding:1.1rem 1.3rem .9rem;
  row-gap:.55rem;
  justify-content:flex-start;   /* contenuto parte dall'alto */
}

body.mode-kids .question-text{
  margin-bottom:.55rem;
  line-height:1.4;
}

body.mode-kids .question-num{
  margin-top:.2rem;
}

body.mode-kids .options{
  gap:.55rem;
  margin-top:.35rem;
  margin-bottom:auto;    /* 🔑 spinge tutto il resto in fondo */
}

body.mode-kids .option{
  min-height:54px;
  padding:.65rem .85rem;
}

body.mode-kids .option-letter{
  width:28px;
  height:28px;
  font-size:.82rem;
}

body.mode-kids .actions{
  margin-top:.9rem;      /* spazio sopra i pulsanti */
  padding:.75rem 0 0;
  border-top:1px solid #eef3fc;
}

body.mode-kids .explanation{
  margin-top:.7rem;
  padding:.7rem .9rem;
}/* ============================================================
   FIX 4 — layout definitivo kids + rifiniture
   ============================================================ */

/* 1. La card prende SOLO l'altezza necessaria → niente vuoto sotto */
body.mode-kids .question-card{
  flex:0 1 auto;
}

/* 2. Stage ancorato in alto, non stirato */
body.mode-kids #quizStage{
  flex:0 1 auto;
}

/* 3. Pulsanti più chiari anche da disabilitati */
body.mode-kids .btn-primary:disabled{
  background:linear-gradient(135deg,#c8cde0,#b8bee0);
  color:#fff;
  opacity:.7;
  box-shadow:0 3px 10px rgba(120,130,180,.20);
}

/* 4. Avanti ATTIVO: più luminoso e "chiama" il click */
body.mode-kids .btn-primary:not(:disabled){
  background:linear-gradient(135deg,#5b8def,#a48ce0);
  box-shadow:
    0 5px 0 #4a6fc4,
    0 10px 22px rgba(91,141,239,.45);
  animation:avantiPulse 2s ease-in-out infinite;
}
body.mode-kids .btn-primary:not(:disabled):hover{
  transform:translateY(-2px);
  box-shadow:
    0 7px 0 #4a6fc4,
    0 14px 26px rgba(91,141,239,.55);
}
@keyframes avantiPulse{
  0%,100%{box-shadow:0 5px 0 #4a6fc4, 0 10px 22px rgba(91,141,239,.35)}
  50%{box-shadow:0 5px 0 #4a6fc4, 0 10px 22px rgba(91,141,239,.55), 0 0 0 4px rgba(91,141,239,.15)}
}

/* 5. Numeri A/B/C/D più leggibili */
body.mode-kids .option-letter{
  background:#fff;
  border:2px solid #fff;
  color:var(--c1);
  font-size:.85rem;
  font-weight:900;
  box-shadow:0 2px 4px rgba(0,0,0,.10);
}

/* 6. Question-number più grande e visibile */
body.mode-kids .question-num{
  width:40px;
  height:40px;
  font-size:1rem;
  box-shadow:
    0 4px 0 rgba(91,141,239,.35),
    0 6px 14px rgba(91,141,239,.30);
}

/* 7. "Cambia livello" più discreto */
body.mode-kids .level-banner-exit{
  border-color:#e4ebf8;
  color:#7a869e;
}

/* 8. Distanza minima per separare chiaramente livello e domanda */
body.mode-kids .level-banner{
  margin-bottom:.15rem;
}

/* ============================================================
   FIX 5 — lettera A/B/C/D visibile nel pallino bianco
   ============================================================ */

body.mode-kids .option .option-letter,
body.mode-kids .option:nth-child(1) .option-letter,
body.mode-kids .option:nth-child(2) .option-letter,
body.mode-kids .option:nth-child(3) .option-letter,
body.mode-kids .option:nth-child(4) .option-letter,
body.mode-kids .option:nth-child(5) .option-letter,
body.mode-kids .option:nth-child(6) .option-letter{
  background:#fff !important;
  border:2px solid #fff !important;
  color:var(--c1, #e85555) !important;
  font-weight:900;
  box-shadow:0 2px 4px rgba(0,0,0,.10);
}

/* Hover: pallino resta bianco, lettera prende colore del box */
body.mode-kids .option:hover:not(.locked) .option-letter{
  background:#fff !important;
  border-color:#fff !important;
  color:var(--c1) !important;
}

/* Corretto: pallino bianco, lettera verde */
body.mode-kids .option.correct .option-letter{
  background:#fff !important;
  border-color:#fff !important;
  color:#2fbf71 !important;
}

/* Sbagliato: pallino bianco, lettera rossa */
body.mode-kids .option.incorrect .option-letter{
  background:#fff !important;
  border-color:#fff !important;
  color:#ef476f !important;
}
/* ============================================================
   FIX 6 — split orizzontale: sinistra gioco, destra domanda
   ============================================================ */

/* HUD da grid a flex con due gruppi separati */
body.mode-kids .hud{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:.5rem;
  width:100%;
}

/* I primi due hud-item (PUNTI, STREAK) → gruppo sinistro */
body.mode-kids .hud-item[data-hud="score"],
body.mode-kids .hud-item[data-hud="streak"]{
  flex:0 1 auto;
}

/* Il terzo hud-item (DOMANDA) → gruppo destro, spinto a destra */
body.mode-kids .hud-item[data-hud="progress"]{
  margin-left:auto;
  flex:0 1 auto;
}

/* Separatore visivo tra i due gruppi: una barra verticale sottile */
body.mode-kids .hud::after{
  content:'';
  order:1;                    /* mettilo tra i due gruppi */
  display:none;               /* disattivato di default */
}

/* --- Variante 2: righe separate (più ariosa) --- */
/* Attiva questa se preferisci due RIGHE distinte invece di due gruppi */

/*
body.mode-kids .hud{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:.5rem;
}
body.mode-kids .hud-item[data-hud="score"],
body.mode-kids .hud-item[data-hud="streak"]{
}
  /* resta nella colonna sinistra */

body.mode-kids .hud-item[data-hud="progress"]{
  grid-column:2;
}
*/

/* --- Stile per differenziare visivamente i due gruppi --- */

/* Gruppo sinistro (gioco): sfondo pieno, colorato */
body.mode-kids .hud-item[data-hud="score"],
body.mode-kids .hud-item[data-hud="streak"]{
  background:linear-gradient(135deg, rgba(91,141,239,.10), rgba(164,140,224,.08));
  border-color:rgba(91,141,239,.25);
}

/* Gruppo destro (domanda): accento sul bordo */
body.mode-kids .hud-item[data-hud="progress"]{
  background:#fff;
  border:1.5px solid rgba(91,141,239,.35);
  box-shadow:0 2px 6px rgba(91,141,239,.10);
  padding:.35rem .75rem;
}

/* Etichetta "DOMANDA" più marcata */
body.mode-kids .hud-item[data-hud="progress"] .hud-label{
  color:#5b8def;
  font-weight:900;
}

body.mode-kids .hud-item[data-hud="progress"] .hud-value{
  color:#5b8def;
  font-size:.95rem;
}

/* Mobile: torna a impilare i due gruppi */
@media (max-width:520px){
  body.mode-kids .hud{
    flex-wrap:wrap;
  }
  body.mode-kids .hud-item[data-hud="progress"]{
    margin-left:0;
    width:100%;
    justify-content:center;
  }
}

/* ============================================================
   FIX 7 — Top bar in riga unica: Livello | Punti | Streak | Domanda | Timer
   ============================================================ */

.quiz-active{
  display:grid;
  grid-template-columns:auto auto auto 1fr auto;
  grid-template-rows:auto auto 1fr;
  gap:.5rem .4rem;
  flex:1;
  min-height:0;
}

/* --- Banner livello compatto (non più full-width) --- */
.level-banner{
  grid-column:1;
  grid-row:1;
  width:auto;
  min-width:0;
  padding:.4rem .7rem .4rem .8rem;
  border-radius:12px;
  gap:.45rem;
  align-self:stretch;
}
.level-banner::before{width:3px}
.level-banner-icon{font-size:1rem}
.level-banner-label{font-size:.48rem;letter-spacing:.05em}
.level-banner-name{font-size:.82rem}
.level-banner-exit{
  padding:.22rem .5rem;
  font-size:.6rem;
  border-radius:8px;
  margin-left:.3rem;
}

/* --- HUD: "flatten" dei figli nella grid del genitore --- */
.hud{display:contents}

.hud-item[data-hud="score"]{
  grid-column:2;
  grid-row:1;
  align-self:stretch;
}
.hud-item[data-hud="streak"]{
  grid-column:3;
  grid-row:1;
  align-self:stretch;
}
.hud-item[data-hud="progress"]{
  grid-column:4;
  grid-row:1;
  align-self:stretch;
  justify-self:start;
  margin-left:auto;    /* spinge la domanda verso destra */
  padding:.3rem .7rem;
}

/* --- Timer a destra --- */
.timer-wrap{
  grid-column:5;
  grid-row:1;
  align-self:center;
  padding:0;
}
.timer-wrap.hidden{display:none}

/* --- Progress bar: riga dedicata sotto la top bar --- */
.progress-wrap{
  grid-column:1 / -1;
  grid-row:2;
  align-self:center;
  height:5px;
  border-radius:99px;
  background:rgba(91,141,239,.08);
  border:none;
  overflow:hidden;
  margin:0;
  position:static;   /* rimuove l'overlay sul banner */
}
.progress-bar{
  border-radius:99px;
  background:linear-gradient(90deg,var(--blue),var(--violet));
}

/* --- Stage --- */
#quizStage{
  grid-column:1 / -1;
  grid-row:3;
  min-height:0;
  display:flex;
  flex-direction:column;
}

/* --- HUD item più compatti --- */
.hud-item{
  padding:.3rem .6rem;
  border-radius:10px;
  gap:.35rem;
}
.hud-icon{font-size:.9rem}
.hud-label{font-size:.48rem}
.hud-value{font-size:.85rem}

/* --- Kids: override del vecchio .hud a griglia --- */
body.mode-kids .hud{display:contents}

/* --- Kids: banner ancora più stretto --- */
body.mode-kids .level-banner{
  padding:.45rem .75rem;
  border-radius:12px;
}

/* --- Mobile: la top bar si spezza in 2 righe --- */
@media (max-width:720px){
  .quiz-active{
    grid-template-columns:1fr 1fr 1fr;
    grid-template-rows:auto auto auto 1fr;
  }
  .level-banner{grid-column:1 / -1;grid-row:1}
  .hud-item[data-hud="score"]{grid-column:1;grid-row:2}
  .hud-item[data-hud="streak"]{grid-column:2;grid-row:2}
  .hud-item[data-hud="progress"]{
    grid-column:3;grid-row:2;
    margin-left:0;
  }
  .timer-wrap{
    grid-column:3;grid-row:2;
    justify-self:end;
    position:absolute;
    right:.75rem;
    top:50%;
    transform:translateY(-50%);
    z-index:5;
  }
  .progress-wrap{grid-column:1 / -1;grid-row:3}
  #quizStage{grid-column:1 / -1;grid-row:4}
}
/* ============================================================
   TEEN MODE — look sobrio e professionale per la secondaria
   ============================================================ */

/* --- Card domanda: compatta, pulsanti in fondo --- */
body.mode-teen .question-card,
body:not(.mode-kids) .question-card{
  flex:0 1 auto;
  padding:1.1rem 1.3rem .8rem;
}

body:not(.mode-kids) #quizStage{
  flex:0 1 auto;
}

/* --- Opzioni: neutre di default --- */
body:not(.mode-kids) .options{
  display:flex;
  flex-direction:column;
  gap:.5rem;
}

body:not(.mode-kids) .option{
  background:#f7f9fc;
  border:1.5px solid #e5eaf3;
  color:#1a2440;
  padding:.75rem 1rem;
  border-radius:12px;
  font-weight:600;
  transition:all .15s ease;
  box-shadow:none;
}

body:not(.mode-kids) .option:hover:not(.locked){
  background:#fff;
  border-color:#5b8def;
  transform:translateX(3px);
  box-shadow:0 4px 14px rgba(91,141,239,.15);
}
body:not(.mode-kids) .option:hover:not(.locked) .option-letter{
  background:#5b8def;
  border-color:#5b8def;
  color:#fff;
}

/* --- Pallini A/B/C/D neutri --- */
body:not(.mode-kids) .option-letter{
  width:28px;
  height:28px;
  border-radius:8px;      /* quadrotto arrotondato = più "tech" */
  background:#fff;
  border:1.5px solid #dde5f0;
  color:#7a86a1;
  font-size:.85rem;
  font-weight:800;
  transition:all .15s ease;
}

/* --- Correct: verde pulito --- */
body:not(.mode-kids) .option.correct{
  background:#e8f7ef;
  border-color:#2fbf71;
  color:#1a7a48;
}
body:not(.mode-kids) .option.correct .option-letter{
  background:#2fbf71;
  border-color:#2fbf71;
  color:#fff;
}

/* --- Incorrect: rosso pulito --- */
body:not(.mode-kids) .option.incorrect{
  background:#fdeaea;
  border-color:#ef476f;
  color:#a12b45;
}
body:not(.mode-kids) .option.incorrect .option-letter{
  background:#ef476f;
  border-color:#ef476f;
  color:#fff;
}

/* --- Le opzioni non scelte si attenuano --- */
body:not(.mode-kids) .option.locked:not(.correct):not(.incorrect){
  opacity:.45;
}

/* --- HUD: pillole più strette --- */
body:not(.mode-kids) .hud-item{
  padding:.3rem .65rem;
  border-radius:10px;
  border:1px solid #e5eaf3;
  background:#fff;
  box-shadow:none;
}
body:not(.mode-kids) .hud-icon{font-size:.9rem}
body:not(.mode-kids) .hud-label{font-size:.5rem;color:#8a94b0}
body:not(.mode-kids) .hud-value{font-size:.85rem;color:#1a2440}

/* --- HUD DOMANDA: un po' più marcato (accento blu) --- */
body:not(.mode-kids) .hud-item[data-hud="progress"]{
  border-color:#c9d7f0;
  background:linear-gradient(135deg,#f5f9ff,#eaf1ff);
}
body:not(.mode-kids) .hud-item[data-hud="progress"] .hud-label{
  color:#5b8def;
}
body:not(.mode-kids) .hud-item[data-hud="progress"] .hud-value{
  color:#3a5fc8;
}

/* --- Banner livello: sobrio --- */
body:not(.mode-kids) .level-banner{
  background:#fff;
  border:1.5px solid #e5eaf3;
  padding:.4rem .7rem;
  border-radius:12px;
}
body:not(.mode-kids) .level-banner::before{
  background:#5b8def;
  width:3px;
}
body:not(.mode-kids) .level-banner-name{color:#1a2440;font-size:.85rem}
body:not(.mode-kids) .level-banner-exit{
  border-color:#e5eaf3;
  background:#f7f9fc;
  color:#7a86a1;
}
body:not(.mode-kids) .level-banner-exit:hover{
  border-color:#5b8def;
  background:#fff;
  color:#5b8def;
}

/* --- Progress bar: visibile --- */
body:not(.mode-kids) .progress-wrap{
  height:5px;
  background:#eef3fc;
}
body:not(.mode-kids) .progress-bar{
  background:linear-gradient(90deg,#5b8def,#7C5CFC);
}

/* --- Question-num: sobrio --- */
body:not(.mode-kids) .question-num{
  width:32px;
  height:32px;
  font-size:.85rem;
  background:linear-gradient(135deg,#5b8def,#7C5CFC);
  border-radius:10px;
}

/* --- Question-text: leggermente più piccolo --- */

body:not(.mode-kids) .question-text{
  font-size:clamp(1rem,1.6vw,1.15rem);
  margin-bottom:.85rem;
  color: var(--navy);
}
html[data-theme="dark"] body:not(.mode-kids) .question-text {
  color: var(--ink);
}

/* --- Pulsanti --- */
body:not(.mode-kids) .btn-primary{
  background:linear-gradient(135deg,#5b8def,#7C5CFC);
  border-radius:10px;
  box-shadow:0 3px 10px rgba(91,141,239,.28);
}
body:not(.mode-kids) .btn-primary:hover:not(:disabled){
  box-shadow:0 6px 16px rgba(91,141,239,.38);
}
body:not(.mode-kids) .btn-ghost{
  border:1.5px solid #e5eaf3;
  color:#7a86a1;
  border-radius:10px;
}
body:not(.mode-kids) .btn-ghost:hover{
  border-color:#5b8def;
  color:#5b8def;
  background:#f5f9ff;
}

/* --- Spiegazione: pulita --- */
body:not(.mode-kids) .explanation{
  background:#f5f9ff;
  border-left:3px solid #5b8def;
  border-radius:10px;
  color:#4a5578;
  padding:.65rem .9rem;
  font-size:.85rem;
}

/* --- Actions --- */
body:not(.mode-kids) .actions{
  margin-top:.9rem;
  padding:.8rem 0 0;
  border-top:1px solid #eef3fc;
}

/* --- Timeout / "tempo scaduto" --- */
body:not(.mode-kids) .timer-circle .progress{stroke:#5b8def}
body:not(.mode-kids) .timer-circle.warning .progress{stroke:#f0b95c}
body:not(.mode-kids) .timer-circle.danger .progress{stroke:#ef476f}
body:not(.mode-kids) .timer-text{color:#1a2440}