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

:root {
  --primary: #0d9488;
  --primary-dark: #0f766e;
  --primary-light: #ccfbf1;
  --bg: #f0fdf9;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --correct: #16a34a;
  --wrong: #dc2626;
  --option-hover: #f0fdf9;
  --option-selected: #ccfbf1;
}

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; }

/* ── 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;
}

/* ── SEZIONI INFO ── */
.sezioni-info {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px;
}
.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; }
@media (max-width: 500px) { .mode-cards { grid-template-columns: 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;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary-green {
  background: #166534; color: #fff; border: none; border-radius: 10px;
  padding: 10px 18px; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background .2s; margin-top: 8px;
}
.btn-secondary-green:hover { background: #14532d; }
.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;
}

/* ── CATEGORY SELECT ── */
.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;
}

.stat-chip {
  background: #f0fdf9; border: 1px solid #99f6e4;
  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; color: #334; 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; }
}

.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 ── */
.sezione-bar {
  display: flex; background: #fff; border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.sezione-tab {
  flex: 1; min-width: 80px; padding: 10px 8px; text-align: center;
  font-size: 11px; font-weight: 600; color: var(--muted); cursor: pointer;
  border-bottom: 3px solid transparent; white-space: nowrap;
}
.sezione-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.sezione-tab.done { color: var(--correct); }

/* ── NUM ROW ── */
.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 ── */
.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: 17px; font-weight: 600; line-height: 1.5; flex: 1; }
.q-num { background: var(--primary-light); color: var(--primary-dark); font-weight: 700; font-size: 13px; border-radius: 8px; padding: 4px 10px; white-space: nowrap; }

/* ── QUESTION IMAGE ── */
.q-image {
  display: block; max-width: 100%; max-height: 300px;
  margin: 12px auto 16px; border-radius: 8px;
  border: 1px solid var(--border);
}

/* ── OPTIONS ── */
.options-list { display: flex; flex-direction: column; gap: 10px; }
.option-btn {
  display: flex; align-items: flex-start; gap: 12px;
  background: #fff; border: 2px solid var(--border); border-radius: 12px;
  padding: 14px 16px; cursor: pointer; text-align: left;
  font-size: 15px; line-height: 1.4; transition: all .15s;
  color: var(--text);
}
.option-btn:hover:not(:disabled) { border-color: var(--primary); background: var(--option-hover); }
.option-btn .opt-letter {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; flex-shrink: 0; color: var(--muted);
  transition: all .15s;
}
.option-btn:hover:not(:disabled) .opt-letter { border-color: var(--primary); color: var(--primary); }
.option-btn.selected { border-color: var(--primary); background: var(--option-selected); }
.option-btn.selected .opt-letter { background: var(--primary); border-color: var(--primary); color: #fff; }
.option-btn.correct-ans { border-color: var(--correct); background: #dcfce7; }
.option-btn.correct-ans .opt-letter { background: var(--correct); border-color: var(--correct); color: #fff; }
.option-btn.wrong-ans { border-color: var(--wrong); background: #fee2e2; }
.option-btn.wrong-ans .opt-letter { background: var(--wrong); border-color: var(--wrong); color: #fff; }
.option-btn:disabled { cursor: default; }

/* ── FEEDBACK ── */
.answer-feedback {
  margin-top: 16px; padding: 14px 16px; border-radius: 12px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  font-size: 14px; font-weight: 600;
}
.answer-feedback.ok { background: #dcfce7; color: var(--correct); }
.answer-feedback.no { background: #fee2e2; color: var(--wrong); }
.btn-avanti {
  margin-left: auto; background: var(--primary); color: #fff; border: none;
  border-radius: 8px; padding: 8px 16px; font-size: 13px; font-weight: 600; cursor: pointer;
}

/* ── 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); }
.score-value.negative { color: var(--wrong); }
.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: #f0fdf9; }

/* ── RESULT ── */
.result-container { max-width: 680px; margin: 0 auto; padding: 24px 16px; }
.result-box { background: #fff; border-radius: 12px; padding: 40px 32px; text-align: center; box-shadow: 0 4px 24px rgba(0,0,0,.08); margin-bottom: 24px; }
#result-icon { font-size: 56px; margin-bottom: 12px; }
#result-title { font-size: 24px; font-weight: 800; margin-bottom: 8px; }
#result-msg { color: var(--muted); font-size: 15px; margin-bottom: 20px; }
#result-stats { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-bottom: 16px; }
.stat-pill { background: var(--primary-light); color: var(--primary-dark); border-radius: 10px; padding: 8px 16px; font-size: 14px; font-weight: 700; }
#result-sezioni { margin-bottom: 20px; }
.sezione-result { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.sezione-result:last-child { border-bottom: none; }
.result-errors { background: #fff; border-radius: 16px; padding: 20px; box-shadow: 0 4px 24px rgba(0,0,0,.06); }
.errors-title { font-size: 16px; font-weight: 700; margin-bottom: 16px; color: var(--wrong); }
.error-item { border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 10px; }
.error-q { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.error-ans { font-size: 13px; color: var(--muted); }
.error-ans .wrong-r { color: var(--wrong); }
.error-ans .correct-r { color: var(--correct); }

@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.4} }

/* ── RIEPILOGO ── */
.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; }

/* ── BACK HUB ── */
.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: #99f6e4; }

/* ── 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; }
