/* ============================================
   BASE & RESET
   ============================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,0.10);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.14);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 50%, #0ea5e9 100%);
  min-height: 100vh;
  color: var(--gray-900);
  line-height: 1.5;
}

/* ============================================
   LAYOUT
   ============================================ */
.page-wrapper {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 16px 40px;
}

.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 600px;
  padding: 28px 24px;
}

/* ============================================
   TYPOGRAPHY
   ============================================ */
h1 { font-size: clamp(1.5rem, 5vw, 2.2rem); font-weight: 800; }
h2 { font-size: clamp(1.2rem, 4vw, 1.6rem); font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 600; }

.text-primary  { color: var(--primary); }
.text-success  { color: var(--success); }
.text-danger   { color: var(--danger); }
.text-muted    { color: var(--gray-500); }
.text-center   { text-align: center; }

/* ============================================
   BUTTONS
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  text-decoration: none;
  width: 100%;
  letter-spacing: 0.01em;
  -webkit-user-select: none;
  user-select: none;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(37,99,235,0.25);
}
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 16px rgba(37,99,235,0.35); }

.btn-success {
  background: var(--success);
  color: #fff;
  box-shadow: 0 2px 8px rgba(22,163,74,0.25);
}
.btn-success:hover { background: #15803d; }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
}
.btn-outline:hover { background: var(--primary-light); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: #b91c1c; }

.btn-sm {
  padding: 8px 16px;
  font-size: 0.875rem;
  width: auto;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ============================================
   INDEX PAGE
   ============================================ */
.hero-logo {
  width: 90px;
  height: 90px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  font-size: 2.5rem;
  box-shadow: 0 4px 20px rgba(37,99,235,0.3);
}

.hero-title {
  text-align: center;
  margin-bottom: 8px;
}

.hero-subtitle {
  text-align: center;
  color: var(--gray-500);
  margin-bottom: 28px;
  font-size: 0.95rem;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 28px;
}

.info-card {
  background: var(--gray-50);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
  border: 1px solid var(--gray-200);
}

.info-card .info-icon {
  font-size: 1.5rem;
  margin-bottom: 4px;
}

.info-card .info-label {
  font-size: 0.75rem;
  color: var(--gray-500);
  margin-bottom: 2px;
}

.info-card .info-value {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--gray-900);
}

.warning-box {
  background: var(--warning-light);
  border: 1px solid #fcd34d;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 24px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.warning-box .warning-icon { font-size: 1.3rem; flex-shrink: 0; }
.warning-box p { font-size: 0.875rem; color: var(--warning); font-weight: 500; }
.warning-box strong { color: #92400e; }

.btn-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ============================================
   QUIZ PAGE
   ============================================ */
.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}

.quiz-counter {
  font-size: 0.875rem;
  color: var(--gray-500);
  white-space: nowrap;
}

.quiz-counter span {
  font-weight: 700;
  color: var(--primary);
  font-size: 1rem;
}

/* Score live */
.score-live {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--success);
  white-space: nowrap;
}

/* Progress bar */
.progress-bar-wrap {
  background: var(--gray-200);
  border-radius: 99px;
  height: 8px;
  margin-bottom: 20px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #0ea5e9);
  border-radius: 99px;
  transition: width 0.4s ease;
}

/* Timers */
.timers-row {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.timer-block {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--gray-50);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  border: 1px solid var(--gray-200);
}

.timer-label {
  font-size: 0.7rem;
  color: var(--gray-500);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.timer-value {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--gray-900);
  font-variant-numeric: tabular-nums;
  transition: color var(--transition);
}

.timer-value.urgent { color: var(--danger); animation: pulse 0.5s infinite alternate; }

@keyframes pulse {
  from { opacity: 1; }
  to   { opacity: 0.5; }
}

/* Question per-timer bar */
.question-timer-bar {
  height: 5px;
  background: var(--gray-200);
  border-radius: 99px;
  margin-bottom: 20px;
  overflow: hidden;
}

.question-timer-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 1s linear, background 1s linear;
}

/* Question card */
.question-text {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--gray-900);
  margin-bottom: 20px;
  line-height: 1.6;
}

/* Answers */
.answers-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}

.answer-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--gray-50);
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  width: 100%;
  font-size: 0.95rem;
  color: var(--gray-900);
  font-weight: 500;
  -webkit-user-select: none;
  user-select: none;
  position: relative;
  overflow: hidden;
}

.answer-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--primary);
  opacity: 0;
  transition: opacity var(--transition);
}

.answer-letter {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
  transition: all var(--transition);
  z-index: 1;
  position: relative;
}

.answer-text {
  z-index: 1;
  position: relative;
  line-height: 1.4;
}

.answer-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-light);
  transform: translateX(4px);
}

.answer-btn:hover:not(:disabled) .answer-letter {
  background: var(--primary);
  color: #fff;
}

.answer-btn:active:not(:disabled) { transform: scale(0.98); }

.answer-btn.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.answer-btn.selected .answer-letter {
  background: var(--primary);
  color: #fff;
}

.answer-btn.correct {
  border-color: var(--success);
  background: var(--success-light);
  animation: correctPop 0.3s ease;
}

.answer-btn.correct .answer-letter {
  background: var(--success);
  color: #fff;
}

.answer-btn.wrong {
  border-color: var(--danger);
  background: var(--danger-light);
  animation: wrongShake 0.4s ease;
}

.answer-btn.wrong .answer-letter {
  background: var(--danger);
  color: #fff;
}

.answer-btn.reveal-correct {
  border-color: var(--success);
  background: var(--success-light);
}

.answer-btn.reveal-correct .answer-letter {
  background: var(--success);
  color: #fff;
}

.answer-btn:disabled { cursor: not-allowed; }
.answer-btn:disabled:not(.correct):not(.wrong):not(.reveal-correct) { opacity: 0.6; }

@keyframes correctPop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.03); }
  100% { transform: scale(1); }
}

@keyframes wrongShake {
  0%, 100% { transform: translateX(0); }
  25%       { transform: translateX(-6px); }
  75%       { transform: translateX(6px); }
}

/* Feedback */
.feedback-box {
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: fadeIn 0.25s ease;
}

.feedback-box.correct { background: var(--success-light); color: var(--success); border: 1px solid #86efac; }
.feedback-box.wrong   { background: var(--danger-light);  color: var(--danger);  border: 1px solid #fca5a5; }
.feedback-box.timeout { background: var(--warning-light); color: var(--warning); border: 1px solid #fcd34d; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Next button */
.next-btn-wrap {
  margin-top: 8px;
}

/* ============================================
   RESULTS PAGE
   ============================================ */
.result-emoji {
  font-size: 4rem;
  text-align: center;
  margin-bottom: 8px;
}

.result-score-circle {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 16px auto 20px;
  border: 5px solid currentColor;
}

.result-score-circle.excellent { color: var(--success); background: var(--success-light); }
.result-score-circle.good      { color: var(--primary); background: var(--primary-light); }
.result-score-circle.fail      { color: var(--danger);  background: var(--danger-light); }

.result-score-circle .score-num {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
}

.result-score-circle .score-total {
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0.7;
}

.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--gray-50);
  border-radius: var(--radius-sm);
  padding: 12px 8px;
  text-align: center;
  border: 1px solid var(--gray-200);
}

.stat-card .stat-value {
  font-size: 1.4rem;
  font-weight: 800;
  margin-bottom: 2px;
}

.stat-card .stat-label {
  font-size: 0.72rem;
  color: var(--gray-500);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stat-card.s-correct .stat-value { color: var(--success); }
.stat-card.s-wrong   .stat-value { color: var(--danger); }
.stat-card.s-time    .stat-value { color: var(--primary); }

.message-box {
  background: var(--gray-50);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 24px;
  text-align: center;
  border: 1px solid var(--gray-200);
  font-size: 0.95rem;
  font-style: italic;
  color: var(--gray-700);
}

/* Recap list */
.recap-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 12px 0;
  border-top: 1px solid var(--gray-200);
  margin-bottom: 8px;
}

.recap-toggle h3 { font-size: 0.95rem; color: var(--gray-700); }
.recap-toggle .chevron { transition: transform var(--transition); }
.recap-toggle.open .chevron { transform: rotate(180deg); }

.recap-list { display: none; margin-bottom: 20px; }
.recap-list.open { display: block; }

.recap-item {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 8px;
  font-size: 0.875rem;
  border: 1px solid var(--gray-200);
  background: var(--gray-50);
}

.recap-item.r-correct { border-color: #86efac; background: var(--success-light); }
.recap-item.r-wrong   { border-color: #fca5a5; background: var(--danger-light); }
.recap-item.r-timeout { border-color: #fcd34d; background: var(--warning-light); }

.recap-q { font-weight: 600; margin-bottom: 4px; color: var(--gray-900); }
.recap-your { font-size: 0.8rem; color: var(--gray-500); margin-bottom: 2px; }
.recap-correct-ans { font-size: 0.8rem; color: var(--success); font-weight: 600; }

/* ============================================
   HISTORY PAGE
   ============================================ */
.page-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.page-title-row a {
  color: var(--gray-500);
  text-decoration: none;
  font-size: 1.3rem;
  line-height: 1;
  transition: color var(--transition);
}

.page-title-row a:hover { color: var(--primary); }

.history-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--gray-500);
}

.history-empty .empty-icon { font-size: 3rem; margin-bottom: 12px; }

.history-stats-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}

.history-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--gray-200);
  margin-bottom: 20px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead tr {
  background: var(--gray-100);
}

th {
  padding: 12px 14px;
  text-align: left;
  font-weight: 700;
  color: var(--gray-500);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

td {
  padding: 12px 14px;
  border-top: 1px solid var(--gray-100);
  vertical-align: middle;
}

tr:hover td { background: var(--gray-50); }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 0.78rem;
  font-weight: 700;
}

.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger  { background: var(--danger-light);  color: var(--danger); }
.badge-primary { background: var(--primary-light); color: var(--primary); }

.clear-history-wrap {
  text-align: right;
  margin-bottom: 8px;
}

/* ============================================
   MODAL (confirmation anti-triche)
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden { display: none; }

.modal-box {
  background: #fff;
  border-radius: var(--radius);
  padding: 28px 24px;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease;
}

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

.modal-icon { font-size: 2.5rem; text-align: center; margin-bottom: 12px; }
.modal-title { font-size: 1.2rem; font-weight: 700; text-align: center; margin-bottom: 8px; }
.modal-text { font-size: 0.9rem; color: var(--gray-500); text-align: center; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; }

/* ============================================
   NAVIGATION BAR
   ============================================ */
.nav-bar {
  width: 100%;
  max-width: 600px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0 8px;
  margin-bottom: 8px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
}

.nav-brand .nav-icon { font-size: 1.3rem; }

.nav-links {
  display: flex;
  gap: 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all var(--transition);
  background: rgba(255,255,255,0.1);
}

.nav-link:hover, .nav-link.active {
  background: rgba(255,255,255,0.2);
  color: #fff;
}

/* ============================================
   UTILITIES
   ============================================ */
.mb-4  { margin-bottom: 4px; }
.mb-8  { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.mb-24 { margin-bottom: 24px; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }

.divider {
  height: 1px;
  background: var(--gray-200);
  margin: 20px 0;
}

/* ============================================
   PRÉNOM MODAL & BANNIÈRE
   ============================================ */

/* Input prénom dans le modal */
.prenom-input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 1.05rem;
  font-family: inherit;
  color: var(--gray-900);
  margin-bottom: 16px;
  outline: none;
  transition: border-color var(--transition);
}

.prenom-input:focus {
  border-color: var(--primary);
}

.prenom-input.input-error {
  border-color: var(--danger);
  animation: wrongShake 0.4s ease;
}

/* Bandeau prénom sur la page d'accueil */
.prenom-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--primary-light);
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 20px;
  gap: 10px;
}

.prenom-banner.hidden { display: none; }

.prenom-banner-text {
  font-size: 0.95rem;
  color: var(--primary-dark);
  font-weight: 500;
}

.prenom-change-btn {
  background: none;
  border: 1px solid var(--primary);
  color: var(--primary);
  border-radius: 99px;
  padding: 4px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.prenom-change-btn:hover {
  background: var(--primary);
  color: #fff;
}

/* Indicateur de sauvegarde (results.html) */
.save-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 16px;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  color: var(--gray-500);
  animation: fadeIn 0.3s ease;
}

.save-indicator.save-ok {
  background: var(--success-light);
  border-color: #86efac;
  color: var(--success);
}

.save-indicator.save-warn {
  background: var(--warning-light);
  border-color: #fcd34d;
  color: var(--warning);
}

/* Onglets personnes (history.html) */
.person-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.person-tabs.hidden { display: none; }

.person-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 99px;
  border: 2px solid var(--gray-200);
  background: var(--gray-50);
  color: var(--gray-700);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}

.person-tab:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.person-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.tab-count {
  background: rgba(255,255,255,0.25);
  border-radius: 99px;
  padding: 1px 7px;
  font-size: 0.75rem;
  font-weight: 700;
}

.person-tab:not(.active) .tab-count {
  background: var(--gray-200);
  color: var(--gray-500);
}

/* Spinner chargement (history.html) */
.loading-state {
  text-align: center;
  padding: 32px 20px;
}

.loading-state.hidden { display: none; }

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================
   RESPONSIVE FINE-TUNING
   ============================================ */
@media (max-width: 380px) {
  .card { padding: 20px 16px; }
  .info-grid { grid-template-columns: 1fr 1fr; }
  .result-stats { grid-template-columns: 1fr 1fr 1fr; }
  th, td { padding: 10px 10px; }
  .timers-row { gap: 6px; }
}

@media (min-width: 480px) {
  .btn { font-size: 1.05rem; }
  .question-text { font-size: 1.1rem; }
}
