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

:root {
  --primary: #1e40af;
  --primary-dark: #1e3a8a;
  --primary-light: #dbeafe;
  --bg: #f0f4ff;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --correct: #16a34a;
  --wrong: #dc2626;
  --option-hover: #eff6ff;
  --option-selected: #dbeafe;
}

body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }

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

.ad-top { 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%; 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; } }

.start-box { max-width: 1000px; margin: 0 auto; padding: 24px 20px 40px; text-align: center; }
.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: #bfdbfe; }

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

.badge-concorso {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--primary-light); color: var(--primary-dark);
  font-size: 12px; font-weight: 600; padding: 6px 14px;
  border-radius: 20px; margin-bottom: 14px; letter-spacing: .5px;
}

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

#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--full { cursor: pointer; text-decoration: underline; transition: opacity .2s; }
.stat-chip--full:hover { opacity: .7; }

/* ── 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-btn {
  background: none; border: 1px solid var(--border); color: var(--muted);
  padding: 7px 16px; border-radius: 8px; cursor: pointer;
  font-size: 13px; margin-bottom: 20px; transition: all .2s;
}
.info-toggle-btn:hover { border-color: var(--primary); color: var(--primary); }

.info-panel {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 20px; margin-bottom: 24px; text-align: left;
  box-shadow: 0 2px 12px rgba(0,0,0,.06);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.info-panel h3 { font-size: 15px; font-weight: 700; margin-bottom: 14px; color: var(--primary-dark); }
.info-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.info-table th { background: var(--primary-light); padding: 8px 12px; text-align: left; font-weight: 600; color: var(--primary-dark); font-size: 12px; }
.info-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.info-table tr:last-child td { border-bottom: none; }
@media (max-width: 480px) {
  .info-panel { padding: 14px; }
  .info-table { font-size: 11px; min-width: 460px; }
  .info-table th, .info-table td { padding: 6px 8px; }
}
.score-pos { color: var(--correct); font-weight: 700; }
.score-neg { color: var(--wrong); font-weight: 700; }

.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: 1.5px solid var(--border); border-radius: 16px;
  padding: 20px; display: flex; flex-direction: column; gap: 6px;
  transition: box-shadow .2s, transform .2s;
}
.mode-card:hover { box-shadow: 0 4px 20px rgba(30,64,175,.12); transform: translateY(-2px); }
.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; }

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

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

#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: 13px; font-weight: 600; padding: 8px 16px; letter-spacing: .3px; }

.num-row { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 14px; background: var(--card); border-bottom: 1px solid var(--border); }
.num-btn { width: 30px; height: 30px; border-radius: 6px; border: 1.5px solid var(--border); background: var(--card); font-size: 12px; font-weight: 600; cursor: pointer; color: var(--muted); transition: all .15s; user-select: none; }
.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: 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; }

.options-list { display: flex; flex-direction: column; gap: 10px; }
.option-btn {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--card); 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); user-select: none;
}
.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; }

.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 { background: var(--card); 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: var(--card); 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; transition: all .15s; }
.btn-riepilogo:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }

#screen-riepilogo.active { display: block; max-width: 860px; margin: 0 auto; padding: 16px; }
.riepilogo-header { background: var(--card); 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-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; padding: 10px 14px; border-radius: 10px; margin-bottom: 6px; font-size: 13px; cursor: pointer; }
.riepilogo-row.answered { background: #eff6ff; border: 1px solid #bfdbfe; }
.riepilogo-row.skipped  { background: #f8fafc; border: 1px solid var(--border); }
.riepilogo-num { font-weight: 700; min-width: 32px; }
.riepilogo-q { flex: 1; line-height: 1.4; }
.riepilogo-ans { font-size: 12px; color: var(--primary); font-weight: 600; margin-left: 40px; }
.riepilogo-btns { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; align-items: center; }

.btn { padding: 10px 18px; border-radius: 8px; border: none; font-size: 14px; font-weight: 600; cursor: pointer; transition: all .2s; user-select: none; }
.btn-secondary { background: #f1f5f9; color: var(--text); border: 1.5px solid var(--border); }
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }
.btn-hub { padding: 10px 18px; border-radius: 8px; background: #f1f5f9; color: var(--text); font-size: 14px; font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; border: 1.5px solid var(--border); transition: all .2s; }
.btn-hub:hover { border-color: var(--primary); color: var(--primary); }

#screen-result.active { display: block; max-width: 700px; margin: 0 auto; padding: 32px 16px; }
.result-box { background: var(--card); border-radius: 20px; padding: 32px 24px; text-align: center; box-shadow: 0 4px 24px rgba(0,0,0,.08); margin-bottom: 24px; }
.result-score { font-size: 3.5rem; font-weight: 900; color: var(--primary-dark); }
.result-punteggio { font-size: 1.1rem; font-weight: 700; margin: 8px 0; }
.result-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; margin: 20px 0; }
.r-stat { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px 8px; text-align: center; }
.r-stat-val { font-size: 1.4rem; font-weight: 800; }
.r-stat-lbl { font-size: 11px; color: var(--muted); }
.r-stat.correct .r-stat-val { color: var(--correct); }
.r-stat.wrong   .r-stat-val { color: var(--wrong); }
.r-stat.skip    .r-stat-val { color: #d97706; }
.result-btns { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

#screen-argomento.active { display: block; max-width: 860px; margin: 0 auto; padding: 16px; }
.argomento-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px,1fr)); gap: 14px; }
.arg-card { background: var(--card); border: 1.5px solid var(--border); border-radius: 14px; padding: 20px 16px; cursor: pointer; transition: all .2s; }
.arg-card:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: 0 4px 16px rgba(30,64,175,.12); }
.arg-title { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.arg-count { font-size: 12px; color: var(--muted); }

.loading-box { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 200px; gap: 12px; color: var(--muted); font-size: 15px; }
.spinner { width: 36px; height: 36px; border: 4px solid var(--primary-light); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.4} }

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

.error-item { background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; padding: 14px; margin-bottom: 10px; }
.error-q { font-size: .88rem; color: #334155; margin-bottom: 8px; line-height: 1.4; }
.error-answers { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; }
.error-wrong { color: #ef4444; font-weight: 600; }
.error-correct { color: #10b981; font-weight: 600; }

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