/* Global Pastel Theme */
:root {
  --bg-start: #f7e9ff;   /* pastel pink-violet */
  --bg-end:   #d9f0ff;   /* pastel baby blue */
  --primary:  #6aa9ff;   /* soft blue */
  --primary-700: #4d8fe8;
  --accent:   #ff9ecb;   /* soft pink */
  --accent-700: #f47fb4;
  --purple:   #a28bd4;
  --purple-700:#8e76c2;
  --success:  #78d9a5;   /* soft green */
  --success-700:#5fc28e;
  --danger:   #ff8e8e;   /* soft red */
  --danger-700:#e96f6f;
  --card:     #ffffff;
  --text:     #1f2230;
  --muted:    #646b7a;
  --ring:     rgba(0,0,0,0.08);
}

/* Base */
html, body { height: 100%; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 600px at 10% 10%, rgba(255, 158, 203, 0.12), transparent 60%),
              radial-gradient(1200px 600px at 90% 90%, rgba(106, 169, 255, 0.12), transparent 60%),
              linear-gradient(to right, var(--bg-start), var(--bg-end));
}
/* During quiz pages use flex centering, but allow scrolling layout when completed */
.center-page { display: flex; justify-content: center; align-items: center; min-height: 100vh; }
.center-page .quiz-container { margin-left: auto; margin-right: auto; }
.center-page.exam-completed { align-items: flex-start; }
.center-page.exam-completed .quiz-container { margin-top: 3rem; }

/* When the exam is completed, use a plain card background for continuous flow */
.center-page.exam-completed .quiz-container {
  background: var(--card);
  border: 1px solid rgba(0,0,0,0.06);
}

.container-card, .quiz-container {
  background: var(--card);
  border-radius: 20px;
  box-shadow: 0 10px 30px var(--ring);
  padding: 1.5rem 1.75rem;
}

h1, h2, h3 { color: var(--text); }
p { color: var(--muted); }

/* Buttons */
.btn, .choices a, .next-btn, .answers button {
  border-radius: 12px;
  border: 0;
  text-decoration: none;
  color: #fff;
  padding: 0.65rem 1.1rem;
  display: inline-block;
  cursor: pointer;
  box-shadow: 0 6px 16px var(--ring);
  transition: transform .12s ease, background .25s ease, box-shadow .25s ease;
}
.btn:hover, .choices a:hover, .next-btn:hover, .answers button:hover { transform: translateY(-1px); }

.btn-primary, .choices a { background: var(--primary); }
.btn-primary:hover, .choices a:hover { background: var(--primary-700); }

.btn-accent { background: var(--accent); }
.btn-accent:hover { background: var(--accent-700); }

.btn-purple { background: var(--purple); }
.btn-purple:hover { background: var(--purple-700); }

.btn-success { background: var(--success); }
.btn-success:hover { background: var(--success-700); }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger-700); }

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 2px solid rgba(0,0,0,0.06);
}
.btn-outline:hover { border-color: rgba(0,0,0,0.12); }

/* Quiz specifics */
.quiz-container {
  max-width: 1000px;
  width: 92%;
  /* Extra top padding to make room for counter + Abbandona */
  padding-top: 4.75rem;
  border-radius: 24px;
  background: linear-gradient(180deg, #ffffff 0%, #f6f7ff 100%);
  border: 1px solid rgba(0,0,0,0.04);
  margin-top: 2.25rem;
}
.question-counter { color: var(--muted); font-weight: 600; }

.question {
  font-size: clamp(1.15rem, 2.5vw + 0.8rem, 1.5rem);
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1.25rem;
  text-align: center;
  line-height: 1.3;
  overflow-wrap: anywhere; /* forza l'andare a capo su stringhe lunghe */
  word-break: break-word;
}
.question, .answers { max-width: 820px; margin-left: auto; margin-right: auto; }

.answers { display: flex; flex-direction: column; gap: 12px; }
.answers button {
  display: block;
  width: 100%;
  background: #f6f7ff;
  color: var(--text);
  border: 2px solid rgba(106,169,255,0.35);
  border-radius: 16px;
  padding: 0.9rem 1.1rem;
  text-align: left;
  box-shadow: 0 10px 20px var(--ring);
}
.answers button:hover { background: #eef3ff; border-color: var(--primary); }
.answers button:focus-visible { outline: 3px solid rgba(106,169,255,0.55); outline-offset: 2px; }

.next-btn {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 10px 20px var(--ring);
  display: block;
  margin: 1.25rem auto 0;
  padding: 0.9rem 1.2rem;
  border-radius: 12px;
  width: 100%;
  max-width: 820px;
  text-align: center;
}

/* Summary (results) */
.summary { border-top: 1px solid rgba(0,0,0,0.08) !important; padding-top: 1.25rem !important; }
.summary { max-width: 900px; margin-left: auto; margin-right: auto; }
.summary .actions { display:flex; gap:.6rem; flex-wrap: wrap; justify-content: center; margin: 0 0 1.1rem; }
.summary .cards { display: grid; gap: 18px; }
.answer-card {
  background: #ffffff;
  border-left: 6px solid var(--primary);
  border-radius: 14px;
  box-shadow: 0 6px 18px var(--ring);
  padding: 1rem 1.25rem;
}
.answer-card.is-correct { border-left-color: var(--success); }
.answer-card.is-wrong   { border-left-color: var(--danger); }
.answer-card .q-meta  { font-size: .9rem; color: var(--muted); margin-bottom: .25rem; }
.answer-card .q-title { font-size: 1.05rem; font-weight: 600; color: var(--text); margin: .2rem 0 .35rem; line-height: 1.35; }
.answer-card .user    { color: var(--danger-700); font-weight: 500; }
.answer-card .right   { color: var(--success-700); font-weight: 500; }

/* Result header card (end of exam) */
.result-card {
  background: var(--card);
  border-left: 8px solid var(--primary);
  border-radius: 18px;
  box-shadow: 0 12px 28px var(--ring);
  padding: 1rem 1.25rem;
  margin-bottom: .9rem;
}
.result-card.passed { border-left-color: var(--success); background-image: linear-gradient(180deg, #f6fff9 0%, #ffffff 100%); }
.result-card.failed { border-left-color: var(--danger);  background-image: linear-gradient(180deg, #fff6f6 0%, #ffffff 100%); }
.result-card .row-head { display:flex; align-items: center; justify-content: space-between; gap:.75rem; }
.badge { display:inline-block; padding:.25rem .6rem; border-radius:999px; font-size:.85rem; }
.badge.passed { background: #e9fbf2; color: #237a4b; border:1px solid rgba(35,122,75,.2); }
.badge.failed { background: #ffefef; color: #9a2f2f; border:1px solid rgba(154,47,47,.2); }
.score-big { font-weight: 900; font-size: 1.8rem; margin-top: .35rem; }
.result-card.passed .score-big { color: var(--success-700); }
.result-card.failed .score-big { color: var(--danger-700); }
.next-btn:hover { background: var(--primary-700); }

.score { color: var(--text); }

/* Summary cards (fallback if no inline styles) */
.summary .card {
  background: #ffffff;
  border-left: 6px solid var(--primary);
  border-radius: 14px;
  box-shadow: 0 6px 18px var(--ring);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

/* Quit button */
.quit-btn { background: var(--danger); }
.quit-btn:hover { background: var(--danger-700); }

/* Override inline summary buttons by id with !important */
#retryBtn { background: var(--primary) !important; }
#errorBtn { background: var(--danger) !important; }
#historyBtn { background: var(--purple) !important; }

/* Index choices tweaks */
.choices { display: grid; grid-template-columns: 1fr; gap: 0.8rem; }
.choices a.secondary { background: var(--accent); }
.choices a.secondary:hover { background: var(--accent-700); }
.choices a.green { background: var(--success); }
.choices a.green:hover { background: var(--success-700); }

/* Cronologia cards */
.history-card { background:#fff; border-radius:14px; box-shadow:0 8px 20px var(--ring); padding:1rem 1.25rem; border-left:6px solid var(--primary); }
.history-card.passed { border-left-color: var(--success); }
.history-card.failed { border-left-color: var(--danger); }
.tag { background: #eef3ff; color: var(--text); }

/* Generic modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: none; align-items: center; justify-content: center; z-index: 2000; }
.modal { background: var(--card); border-radius: 16px; padding: 1.25rem 1.5rem; width: min(92%, 540px); box-shadow: 0 10px 30px rgba(0,0,0,0.2); }
.modal h3 { margin: 0 0 .5rem; color: var(--text); }
.modal p { margin: 0 0 1rem; color: var(--muted); }
.modal .row { display: flex; gap: .5rem; justify-content: flex-end; }

/* Big Result Modal */
.modal-result { width: min(92%, 760px); text-align: center; padding: 2rem 2.2rem; }
.modal-result .hero {
  display: grid; gap: .4rem; justify-items: center; margin: .25rem 0 1.1rem;
}
.modal-result .hero .label { color: var(--muted); font-size: 1rem; }
.modal-result .hero .score { font-size: 4rem; font-weight: 900; line-height: .9; letter-spacing: .5px; }
.modal-result .hero .status { font-size: 1.2rem; font-weight: 800; margin-top: .15rem; }
.modal-result.passed .hero .score { color: var(--success-700); }
.modal-result.failed .hero .score { color: var(--danger-700); }
.modal-result.passed .hero .status { color: var(--success-700); }
.modal-result.failed .hero .status { color: var(--danger-700); }
.modal-result .meta { color: var(--muted); margin-top: .2rem; }
.modal-result .actions { display:flex; flex-wrap: wrap; gap: .5rem; justify-content: center; margin-top: .6rem; }
.modal-result .actions .btn { min-width: 160px; }
/* Extra congratulation line */
.modal-result .extra {
  margin-top: .6rem;
  font-size: 1.25rem;
  font-weight: 900;
  color: var(--accent-700);
}

/* Debug UI */
.debug-toggle { position:absolute; top: .8rem; right: 7.25rem; background: var(--purple); color:#fff; border:none; border-radius:10px; padding:.45rem .75rem; box-shadow:0 2px 8px var(--ring); cursor:pointer; }
.debug-toggle:hover { background: var(--purple-700); }
.debug-panel { position:absolute; top: 3rem; right: 1rem; background: var(--card); border:1px solid rgba(0,0,0,0.08); border-radius: 12px; box-shadow: 0 10px 20px var(--ring); padding:.75rem; display:none; width: 220px; }
.debug-panel h4 { margin:.2rem 0 .5rem; font-size: .95rem; color: var(--text); }
.debug-panel .btn { width: 100%; text-align:center; margin-top:.4rem; }

/* Small button utility */
.btn-sm { padding: .35rem .6rem; font-size: .85rem; border-radius: 8px; }

/* Toast notifications */
.toast {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%) translateY(10px);
  background: var(--card);
  color: var(--text);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 12px;
  padding: 0.6rem 0.9rem;
  box-shadow: 0 10px 20px var(--ring);
  z-index: 3000;
  opacity: 0;
  pointer-events: none;
}
.toast.show { animation: toast-in .22s ease forwards; }
.toast.out  { animation: toast-out .35s ease forwards; }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateX(-50%) translateY(0); }
  to   { opacity: 0; transform: translateX(-50%) translateY(10px); }
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .quiz-container { width: 96%; padding-top: 5rem; border-radius: 18px; }
  .question, .answers { max-width: 100%; }
  .answers { gap: 10px; }
  .answers button { border-radius: 14px; padding: 0.85rem 1rem; }
  .question-counter { top: .6rem; left: .75rem; font-size: .95rem; padding: .3rem .6rem; }
  .result-card { border-radius: 16px; }
  .score-big { font-size: 1.5rem; }
  .modal-result { width: min(96%, 640px); padding: 1.6rem 1.8rem; }
  .modal-result .hero .score { font-size: 3rem; }
}
@media (max-width: 480px) {
  .quiz-container { width: 98%; padding-top: 5.5rem; border-radius: 16px; }
  .answers { gap: 8px; }
  .answers button { border-radius: 12px; padding: 0.8rem .9rem; }
  .next-btn { max-width: 100%; }
  .modal-result .hero .score { font-size: 2.5rem; }
  .modal-result .actions .btn { min-width: 130px; }
}
