﻿*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --primary-light: #eef2ff;
  --bg: #f5f3ff;
  --card: #ffffff;
  --text: #1e1b4b;
  --muted: #64748b;
  --border: #e0e7ff;
  --correct: #16a34a;
  --wrong: #dc2626;
  --option-hover: #eef2ff;
  --option-selected: #e0e7ff;
}

body { font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: #f1f5f9; color: var(--text); min-height: 100vh; }

/* ── SCREENS ── */
.screen { display: none; }
.screen.active { display: block; animation: screenIn .3s ease-out; }
@keyframes screenIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── START BOX ── */
.start-box {
  max-width: 1000px; margin: 0 auto; padding: 24px 20px 40px;
  position: relative; text-align: center;
}

/* ── SOCIAL ── */
.social-share { display: flex; gap: 8px; }
.social-btn {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%; color: #fff; text-decoration: none;
  transition: transform .15s, opacity .15s;
}
.social-btn:hover { transform: scale(1.12); opacity: .9; }
.social-btn svg { width: 17px; height: 17px; }
.social-wa { background: #25d366; }
.social-fb { background: #1877f2; }
.social-tg { background: #229ed9; }

/* ── TOP BAR ── */
.top-bar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 14px;
}
.back-hub {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600; color: var(--primary);
  text-decoration: none;
  background: var(--primary-light); border-radius: 20px; padding: 5px 14px;
  transition: background .2s;
}
.back-hub:hover { background: #c7d2fe; }

/* ── TITLE ── */
.start-box h1 { font-size: 28px; font-weight: 800; color: var(--primary-dark); margin-bottom: 4px; }
.start-sub { color: var(--muted); font-size: 15px; margin-bottom: 16px; }

/* ── STATS STRIP ── */
.stats-strip {
  background: var(--primary-light); border-radius: 10px; padding: 10px 14px;
  font-size: 13px; color: var(--primary-dark); margin-bottom: 16px;
  display: flex; gap: 16px; flex-wrap: wrap; justify-content: center;
}
.stat-chip { background: #e0e7ff; border: 1px solid #c7d2fe; border-radius: 20px; padding: 4px 12px; font-size: .8rem; color: #334; }
.stat-chip strong { color: var(--primary-dark); }
.stat-chip--full { background: #eef1ff; border-color: #c9d2f5; cursor: pointer; transition: all .2s; }
.stat-chip--full:hover { background: #dde4fb; transform: scale(1.03); }

/* ── MODALE (generica) ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px;
}
.modal-box {
  background: #fff; border-radius: 10px; width: 100%; max-width: 560px;
  max-height: 80vh; display: flex; flex-direction: column;
  box-shadow: 0 8px 30px rgba(0,0,0,.3);
}
.modal-box-wide { max-width: 720px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { color: var(--primary-dark); font-size: 1rem; }
.modal-close { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--muted); padding: 2px 6px; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 0; overflow-y: auto; flex: 1; font-size: .88rem; line-height: 1.7; color: var(--text); }

/* ── Modale statistiche complete ── */
.stats-modal-h { margin: 0 0 8px; font-size: .9rem; color: var(--primary-dark); }
.stats-modal-h:not(:first-child) { margin-top: 20px; }
.cat-stat-list { display: flex; flex-direction: column; gap: 6px; }
.cat-stat-row { display: grid; grid-template-columns: 1fr 90px 70px; align-items: center; gap: 8px; font-size: .8rem; }
.cat-stat-label { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-stat-bar-wrap { background: #eee; border-radius: 6px; height: 10px; overflow: hidden; }
.cat-stat-bar { height: 100%; border-radius: 6px; transition: width .3s; }
.cat-stat-pct { text-align: right; font-weight: 600; color: var(--text); white-space: nowrap; }
.cat-stat-n { font-weight: 400; opacity: .6; font-size: .82em; }
.hist-list { display: flex; flex-direction: column; gap: 4px; }
.hist-row { display: grid; grid-template-columns: 1fr 65px 60px; align-items: center; gap: 8px; font-size: .78rem; padding: 6px 8px; border-radius: 6px; background: var(--bg); }
.hist-date { color: var(--muted); }
.hist-score { font-weight: 600; text-align: right; }
.hist-pct { text-align: right; color: var(--muted); }
@media (max-width: 480px) {
  .cat-stat-row { grid-template-columns: 1fr 45px 75px; }
  .cat-stat-n { font-size: .7rem; }
}

/* ── INFO TOGGLE ── */
.info-toggle { margin-bottom: 20px; text-align: left; }
.info-toggle-btn {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  background: var(--primary-light); border: 1.5px solid var(--border); border-radius: 12px;
  padding: 12px 16px; font-size: 14px; font-weight: 600; color: var(--primary-dark);
  cursor: pointer; user-select: none; transition: background .2s;
}
.info-toggle-btn:hover { background: #e0e7ff; }
.info-toggle-btn[aria-expanded="true"] { border-radius: 12px 12px 0 0; border-bottom-color: transparent; }
.info-toggle-arrow { font-size: 11px; transition: transform .25s; }
.info-toggle-btn[aria-expanded="true"] .info-toggle-arrow { transform: rotate(180deg); }
.info-panel {
  background: #fff; border: 1.5px solid var(--border); border-top: none;
  border-radius: 0 0 12px 12px; padding: 16px 18px;
}
.info-panel[hidden] { display: none; }
.info-intro { font-size: 13px; color: var(--muted); line-height: 1.6; }
.info-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 16px;
}
@media (max-width: 560px) { .info-grid { grid-template-columns: repeat(2, 1fr); } }
.info-cell {
  background: var(--primary-light); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 10px; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
}
.info-num { font-size: 28px; font-weight: 800; color: var(--primary); line-height: 1; }
.info-label { font-size: 11px; color: var(--muted); line-height: 1.5; }
.info-label strong { color: var(--text); }

/* ── GRADO ── */
.grado-section { margin-bottom: 20px; }
.section-label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin-bottom: 10px; }
.grado-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 480px; margin: 0 auto; }
.grado-btn { background: #fff; border: 2px solid var(--border); border-radius: 14px; padding: 16px 12px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; transition: border-color .2s, box-shadow .2s; user-select: none; }
.grado-btn:hover { border-color: var(--primary); box-shadow: 0 4px 14px rgba(79,70,229,.12); }
.grado-btn.sel { border-color: var(--primary); background: var(--primary-light); }
.grado-icon { font-size: 28px; }
.grado-nome { font-weight: 700; font-size: 14px; color: var(--text); }
.grado-sub { font-size: 11px; color: var(--muted); }

/* ── FONTE ── */
.fonte-section { margin-bottom: 20px; }
.fonte-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 560px; margin: 0 auto; }
.fonte-btn { background: #fff; border: 2px solid var(--border); border-radius: 12px; padding: 12px 10px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px; transition: border-color .2s, box-shadow .2s; user-select: none; }
.fonte-btn:hover { border-color: var(--primary); box-shadow: 0 4px 14px rgba(79,70,229,.12); }
.fonte-btn.sel { border-color: var(--primary); background: var(--primary-light); }
.fonte-icon { font-size: 22px; }
.fonte-nome { font-weight: 700; font-size: 13px; color: var(--text); }
.fonte-sub { font-size: 11px; color: var(--muted); }

/* ── SEZIONI INFO ── */
.sezioni-info {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; justify-content: center;
}
.sezione-pill {
  background: #fff; border: 1px solid var(--border); border-radius: 20px;
  padding: 6px 14px; font-size: 12px; color: var(--text); font-weight: 500;
}
.sezione-pill span { color: var(--muted); font-weight: 400; margin-left: 4px; }

/* ── MODE CARDS ── */
.mode-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 24px; text-align: left; }
@media (max-width: 500px) { .mode-cards { grid-template-columns: 1fr; } .grado-grid { grid-template-columns: 1fr 1fr; } .fonte-grid { grid-template-columns: repeat(3,1fr); } }

.mode-card {
  background: var(--card); border: 1px solid #e2e8f0; border-radius: 12px;
  padding: 24px 20px; display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.mode-card:hover { border-color: var(--primary); transform: translateY(-3px); box-shadow: 0 10px 15px -3px rgba(0,0,0,0.08); }
.mode-icon { font-size: 28px; }
.mode-title { font-size: 16px; font-weight: 700; }
.mode-desc { font-size: 13px; color: var(--muted); line-height: 1.5; flex: 1; }

/* ── BUTTONS ── */
.btn-primary {
  background: var(--primary); color: #fff; border: none; border-radius: 10px;
  padding: 10px 18px; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background .2s; margin-top: 8px; user-select: none;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary-indigo {
  background: #4338ca; color: #fff; border: none; border-radius: 10px;
  padding: 10px 18px; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background .2s; margin-top: 8px; user-select: none;
}
.btn-secondary-indigo:hover { background: #3730a3; }
.btn-ripasso {
  background: #7c3aed; color: #fff; border: none; border-radius: 10px;
  padding: 10px 18px; font-size: 14px; font-weight: 600; cursor: pointer;
  margin-top: 8px; user-select: none;
}
.btn-ripasso:hover { background: #6d28d9; }
.category-select {
  width: 100%; border: 1.5px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 13px; color: var(--text);
  background: #fff; margin-top: 4px;
}

.start-footer { text-align: center; font-size: 12px; color: var(--muted); margin-top: 8px; }
.start-footer strong { color: var(--text); }
.visit-chip { margin-left: 14px; font-size: 11px; color: var(--muted); }

/* ── QUIZ SCREEN ── */
#screen-quiz { display: none; }
#screen-quiz.active { display: block; max-width: 860px; margin: 0 auto; padding: 8px; }

.quiz-mode-bar {
  background: var(--primary); color: #fff; text-align: center;
  font-size: .85rem; font-weight: 600; padding: 8px 16px; letter-spacing: .3px;
  border-radius: 8px; border: 1px solid transparent;
}

.sezione-bar { display: flex; gap: 4px; flex-wrap: wrap; padding: 8px 12px; background: var(--primary-light); border-bottom: 1px solid var(--border); }
.sez-pill { font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 20px; background: #fff; border: 1px solid var(--border); color: var(--muted); }
.sez-pill.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.num-row { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 14px; background: #fff; border-bottom: 1px solid var(--border); }
.num-btn { width: 30px; height: 30px; border-radius: 8px; border: 1px solid #e2e8f0; background: #ffffff; font-size: .85rem; font-weight: 600; cursor: pointer; color: #64748b; transition: all .15s ease; }
.num-btn:hover { background: #f8fafc; color: #1e293b; border-color: #cbd5e1; }
.num-btn.answered { background: var(--primary-light); border-color: var(--primary); color: var(--primary-dark); }
.num-btn.current { background: var(--primary); border-color: var(--primary); color: #fff; }
.num-btn.correct { background: #dcfce7; border-color: var(--correct); color: var(--correct); }
.num-btn.wrong { background: #fee2e2; border-color: var(--wrong); color: var(--wrong); }

.main-content { padding: 20px 16px; max-width: 760px; margin: 0 auto; width: 100%; }

.q-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 20px; }
.q-text { font-size: 16px; font-weight: 600; line-height: 1.55; flex: 1; }
.q-num { font-size: 13px; font-weight: 700; color: var(--primary); background: var(--primary-light); border-radius: 8px; padding: 4px 10px; white-space: nowrap; }

.options-list { display: flex; flex-direction: column; gap: 10px; }
.option-btn { background: #fff; border: 2px solid var(--border); border-radius: 12px; padding: 14px 16px; text-align: left; font-size: 14px; cursor: pointer; transition: border-color .15s, background .15s; line-height: 1.45; user-select: none; }
.option-btn:hover:not(:disabled) { border-color: var(--primary); background: var(--option-hover); }
.option-btn.selected { border-color: var(--primary); background: var(--option-selected); }
.option-btn.correct-ans { border-color: var(--correct); background: #f0fdf4; }
.option-btn.wrong-ans { border-color: var(--wrong); background: #fef2f2; }
.option-btn:disabled { cursor: default; }

.answer-feedback { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 16px; padding: 14px 16px; border-radius: 12px; background: #f8f9ff; border: 1px solid var(--border); }
.answer-feedback.correct-fb { background: #f0fdf4; border-color: #bbf7d0; }
.answer-feedback.wrong-fb { background: #fef2f2; border-color: #fecaca; }
#feedback-icon { font-size: 20px; }
#feedback-text { flex: 1; font-size: 13px; line-height: 1.4; }
.btn-avanti { background: var(--primary); color: #fff; border: none; border-radius: 8px; padding: 8px 18px; font-size: 13px; font-weight: 600; cursor: pointer; margin-left: auto; }
.btn-avanti:hover { background: var(--primary-dark); }

/* ── BOTTOM BAR ── */
.bottom-bar { background: #fff; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 12px; padding: 10px 16px; flex-wrap: wrap; }
.timer-box, .score-box { text-align: center; min-width: 70px; }
.timer-label, .score-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.timer-value { font-size: 22px; font-weight: 800; color: var(--primary-dark); font-variant-numeric: tabular-nums; }
.timer-value.warning { color: #dc2626; animation: blink .8s infinite; }
.score-value { font-size: 20px; font-weight: 800; color: var(--primary-dark); }
.nav-box { display: flex; gap: 8px; margin-left: auto; }
.btn-nav { width: 38px; height: 38px; border: 1.5px solid var(--border); border-radius: 8px; background: #fff; font-size: 14px; cursor: pointer; transition: all .15s; }
.btn-nav:hover { border-color: var(--primary); color: var(--primary); }
.btn-riepilogo { background: none; border: 1.5px solid var(--border); border-radius: 8px; padding: 8px 16px; cursor: pointer; font-size: 12px; font-weight: 600; color: var(--muted); user-select: none; -webkit-user-select: none; transition: all .15s; }
.btn-riepilogo:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }

@keyframes blink { 50% { opacity: 0; } }

/* ── RIEPILOGO ── */
#screen-riepilogo { display: none; }
#screen-riepilogo.active { display: block; max-width: 860px; margin: 0 auto; padding: 8px; }
.result-container { max-width: 760px; margin: 0 auto; padding: 20px 16px; }
.riepilogo-header { background: #fff; border-radius: 16px; padding: 20px 24px; margin-bottom: 16px; box-shadow: 0 2px 12px rgba(0,0,0,.06); }
.riepilogo-header h2 { font-size: 18px; font-weight: 700; margin-bottom: 12px; }
.riepilogo-header #riepilogo-result { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.riepilogo-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; align-items: center; }
.riepilogo-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; padding: 10px 14px; border-radius: 10px; margin-bottom: 6px; font-size: 13px; }
.riepilogo-row.correct { background: #f0fdf4; border: 1px solid #bbf7d0; }
.riepilogo-row.wrong { background: #fef2f2; border: 1px solid #fecaca; flex-direction: column; }
.riepilogo-row.skipped { background: #f8fafc; border: 1px solid #e2e8f0; }
.riepilogo-num { font-weight: 700; min-width: 32px; }
.riepilogo-q { flex: 1; line-height: 1.4; }
.riepilogo-ans { font-size: 12px; color: var(--correct); font-weight: 600; margin-left: 40px; }

/* ── RESULT ── */
#screen-result { display: none; }
#screen-result.active { display: block; max-width: 860px; margin: 0 auto; padding: 8px; }
.result-box { background: #fff; border-radius: 12px; padding: 40px 32px; text-align: center; box-shadow: 0 2px 16px rgba(0,0,0,.07); margin-bottom: 20px; }
#result-icon { font-size: 48px; margin-bottom: 12px; }
.result-box h2 { font-size: 22px; font-weight: 800; margin-bottom: 8px; color: var(--text); }
.result-box p { color: var(--muted); margin-bottom: 16px; }
#result-stats { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 16px; }
#result-sezioni { margin-bottom: 20px; }
.sez-result { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-radius: 8px; background: var(--primary-light); margin-bottom: 6px; font-size: 13px; }
.sez-result-label { font-weight: 600; }
.sez-result-score { font-weight: 700; color: var(--primary-dark); }
.result-errors { background: #fff; border-radius: 16px; padding: 20px 24px; box-shadow: 0 2px 12px rgba(0,0,0,.06); }
.errors-title { font-size: 16px; font-weight: 700; margin-bottom: 14px; }
.error-item { padding: 12px 14px; border-radius: 10px; background: #fef2f2; border: 1px solid #fecaca; margin-bottom: 8px; font-size: 13px; }
.error-q { font-weight: 600; margin-bottom: 6px; line-height: 1.4; }
.error-ans { color: var(--correct); font-size: 12px; }

/* ── ADS ── */
.ad-top {
  width: 100%; max-width: 100%; background: #f8f8f8; min-height: 0;
  overflow: hidden; padding: 0; display: flex; align-items: center; justify-content: center;
  border-bottom: 1px solid #e8e8e8;
}
.ad-top:not(:has(iframe)), .ad-top:has(ins[data-ad-status="unfilled"]) { display: none; }
.ad-bottom:not(:has(iframe)), .ad-bottom:has(ins[data-ad-status="unfilled"]) { display: none; }
.ad-bottom {
  width: 100%; max-width: 100%; background: #f8f8f8; min-height: 90px;
  display: flex; align-items: center; justify-content: center;
  border-top: 1px solid #e8e8e8; margin-top: 16px;
}
.ad-side {
  display: none; position: fixed; top: 50%; transform: translateY(-50%);
  width: 160px; z-index: 50;
}
.ad-side-right { right: 8px; }
.ad-side-left  { left: 8px; }
@media (min-width: 1300px) { .ad-side { display: block; } }

body:has(#screen-quiz.active) .ad-top,
body:has(#screen-quiz.active) #wa-float,
body:has(#screen-result.active) #wa-float,
body:has(#screen-riepilogo.active) #wa-float { display: none !important; }

.donate-link { white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 700; color: #b45309; background: #fff7e6;
  border: 1.5px solid #fbbf24; padding: 9px 20px; border-radius: 999px;
  text-decoration: none; transition: all .2s;
}
.donate-link:hover { background: #fbbf24; color: #fff; border-color: #fbbf24; }
.result-donate { text-align: center; margin-top: 16px; }
.result-donate a {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 700; color: #b45309; background: #fff7e6;
  border: 1.5px solid #fbbf24; padding: 9px 20px; border-radius: 999px;
  text-decoration: none; transition: all .2s;
}
.result-donate a:hover { background: #fbbf24; color: #fff; border-color: #fbbf24; }
