:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --card-soft: #f1f3f9;
  --text: #1f2430;
  --muted: #6b7280;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --correct: #16a34a;
  --wrong: #dc2626;
  --border: #e3e7ef;
}

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

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  padding: 1rem;
}

/* margin:auto centers on both axes but, unlike align/justify-center,
   does not clip when the content is taller than the viewport. */
.app { width: 100%; max-width: 640px; margin: auto; }

.screen {
  display: none;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2.5rem;
  box-shadow: 0 12px 40px rgba(31, 36, 48, 0.08);
  animation: fade 0.35s ease;
}
.screen.active { display: block; }

@keyframes fade {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.brand { font-size: 2rem; text-align: center; margin-bottom: 0.5rem; }
.subtitle { text-align: center; color: var(--muted); margin-bottom: 2rem; }

/* Home: contenitore trasparente con due card distinte */
.screen.home {
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
}
.screen.home .brand { margin-bottom: 1.5rem; }

.home-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.75rem;
  box-shadow: 0 12px 40px rgba(31, 36, 48, 0.08);
  margin-bottom: 1.5rem;
}
.home-card:last-child { margin-bottom: 0; }
/* La card della simulazione risalta con un bordo colorato in alto */
.sim-card { border-top: 4px solid var(--primary); }

.card-title {
  font-size: 1.3rem;
  text-align: center;
  margin-bottom: 0.2rem;
}
.card-sub {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}

.results-footer { text-align: center; margin-top: 1.5rem; }

/* Easter egg "Tommy": overlay a schermo intero quando la simulazione fallisce */
.tommy-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(15, 23, 42, 0.9);
  animation: fade 0.3s ease;
}
.tommy-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  max-width: 420px;
  width: 100%;
}
.tommy-img {
  max-width: 100%;
  max-height: 70vh;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.tommy-caption {
  color: #fff;
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
}
.tommy-overlay .btn { max-width: 260px; }

.count-label {
  display: block;
  text-align: center;
  font-weight: 600;
  margin-bottom: 0.6rem;
}
/* stacco tra il pulsante Allenamento e le sue impostazioni */
#start-btn + .count-label {
  margin-top: 1.75rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.sim-hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
  margin: 0.9rem 0 0;
}
.count-input {
  display: block;
  width: 100%;
  padding: 0.9rem 1.1rem;
  font-size: 1.1rem;
  text-align: center;
  color: var(--text);
  background: var(--card-soft);
  border: 2px solid var(--border);
  border-radius: 12px;
  margin-bottom: 0.6rem;
}
.count-input:focus { outline: none; border-color: var(--primary); }
.available {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.btn.small {
  display: inline-block;
  width: auto;
  padding: 0.45rem 0.8rem;
  font-size: 0.82rem;
  background: var(--card-soft);
  color: var(--primary);
  border: 1px solid var(--border);
}
.btn.small:hover { background: #eef0fb; }

.sections-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.sections-head .count-label { margin-bottom: 0; }
.sections-actions { display: flex; gap: 0.5rem; }

.sections-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.section-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem 0.9rem;
  background: var(--card-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.9rem;
}
.section-item:hover { border-color: var(--primary); }
.section-item input { width: 1.1rem; height: 1.1rem; accent-color: var(--primary); cursor: pointer; }
.section-item .name { flex: 1; }
.section-item .count { color: var(--muted); font-size: 0.82rem; }

.btn {
  display: block;
  width: 100%;
  padding: 0.9rem 1.2rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn:disabled { opacity: 0.6; cursor: default; }

.hidden { display: none !important; }

.quiz-head { display: flex; justify-content: space-between; margin-bottom: 1rem; }
.pill {
  background: var(--card-soft);
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--muted);
}
.timer { font-variant-numeric: tabular-nums; }

.progress-bar {
  height: 6px;
  background: var(--card-soft);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 1.5rem;
}
#progress-fill {
  height: 100%;
  width: 0;
  background: var(--primary);
  transition: width 0.3s ease;
}

.question { font-size: 1.35rem; line-height: 1.4; margin-bottom: 0.6rem; }
.question-category {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--card-soft);
  display: inline-block;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  margin-bottom: 1.5rem;
}
.question-category:empty { display: none; }

.answers { display: flex; flex-direction: column; gap: 0.75rem; }

.answer {
  text-align: left;
  padding: 1rem 1.1rem;
  background: var(--card-soft);
  border: 2px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.answer:hover:not(:disabled) { border-color: var(--primary); background: #eef0fb; }
.answer:disabled { cursor: default; }
.answer.correct { border-color: var(--correct); background: rgba(22, 163, 74, 0.12); }
.answer.wrong { border-color: var(--wrong); background: rgba(220, 38, 38, 0.1); }
/* simulazione: risposta selezionata (senza rivelare se è giusta) */
.answer.selected { border-color: var(--primary); background: #eef0fb; }

/* simulazione: barra di navigazione */
.sim-nav { margin-top: 1.5rem; }
.nav-row {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 6.5rem;
}
.nav-row .btn { flex: 1; }
.sim-nav .btn.small { padding: 0.8rem; font-size: 0.95rem; }
.sim-nav .btn.small:disabled { opacity: 0.45; cursor: default; }

/* timer in esaurimento */
.timer.warning { background: rgba(220, 38, 38, 0.12); color: #b91c1c; font-weight: 700; }

.feedback {
  margin-top: 1.25rem;
  padding: 0.9rem 1.1rem;
  border-radius: 12px;
  font-weight: 600;
}
.feedback.right { background: rgba(22, 163, 74, 0.12); color: #15803d; }
.feedback.wrong { background: rgba(220, 38, 38, 0.1); color: #b91c1c; }

.explanation {
  margin-top: 0.75rem;
  padding: 0.9rem 1.1rem;
  border-radius: 12px;
  background: var(--card-soft);
  border-left: 4px solid var(--primary);
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--text);
}
.explanation strong { display: block; margin-bottom: 0.3rem; color: var(--primary); }

#next-btn { margin-top: 1.5rem; }

.score-circle {
  width: 140px;
  height: 140px;
  margin: 1rem auto 1.5rem;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: conic-gradient(var(--primary) var(--pct, 0%), var(--card-soft) 0);
}
.score-circle span { font-size: 2.5rem; font-weight: 700; }
.score-circle small { color: var(--muted); }
.summary-text { text-align: center; color: var(--muted); margin-bottom: 1.5rem; }

.sim-outcome {
  text-align: center;
  font-weight: 800;
  font-size: 1.15rem;
  padding: 0.7rem 1rem;
  border-radius: 12px;
  margin-bottom: 1.5rem;
  letter-spacing: 0.02em;
}
.sim-outcome.pass { background: rgba(22, 163, 74, 0.14); color: #15803d; }
.sim-outcome.fail { background: rgba(220, 38, 38, 0.12); color: #b91c1c; }

.sim-breakdown {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 1.75rem;
}
.sim-breakdown .stat {
  flex: 1;
  min-width: 90px;
  text-align: center;
  padding: 0.75rem 0.5rem;
  background: var(--card-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.sim-breakdown .stat b { display: block; font-size: 1.4rem; }
.sim-breakdown .stat span { font-size: 0.78rem; color: var(--muted); }
.sim-breakdown .stat.ok b { color: var(--correct); }
.sim-breakdown .stat.no b { color: var(--wrong); }

.review-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 1.75rem;
  max-height: 320px;
  overflow-y: auto;
}
.review-item {
  padding: 0.85rem 1rem;
  border-radius: 10px;
  background: var(--card-soft);
  border-left: 4px solid var(--border);
  font-size: 0.92rem;
}
.review-item.ok { border-left-color: var(--correct); }
.review-item.no { border-left-color: var(--wrong); }
.review-item .q { display: block; margin-bottom: 0.3rem; font-weight: 600; }
.review-item .a { color: var(--muted); font-size: 0.85rem; display: block; }
.review-item .a.given-wrong { color: #b91c1c; }
.review-item .a.expl {
  margin-top: 0.4rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--border);
  line-height: 1.45;
}
.review-item .a.expl strong { color: var(--primary); }
