:root {
  --primary: #4338CA;
  --primary-dark: #3730A3;
  --primary-light: #EEF2FF;
  --accent: #F59E0B;
  --accent-light: #FEF3C7;
  --success: #22c55e;
  --success-light: #dcfce7;
  --error: #ef4444;
  --error-light: #fee2e2;
  --warning: #F59E0B;
  --bg: #F5F3FF;
  --card: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 14px;
  --shadow: 0 2px 12px rgba(67, 56, 202, 0.10);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 16px;
  line-height: 1.5;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 40px;
  min-height: 100vh;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 0 16px;
  border-bottom: 2px solid var(--primary);
  margin-bottom: 24px;
}

.header-logo {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.header-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.header-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  background: none;
  border: none;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-subtitle:hover { color: var(--primary-dark); }

.btn-home {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 9px;
  background: var(--primary-light);
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-home:hover { background: var(--accent-light); }
.btn-home:active { transform: scale(0.95); }

/* ── Back button ── */
.btn-back {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--primary-dark);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 0;
  margin-bottom: 16px;
}

.btn-back:hover { opacity: 0.7; }

/* ── Cards ── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

/* ── Home view ── */
.home-greeting {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
}

.home-intro {
  color: var(--text-muted);
  font-size: 15px;
  margin-bottom: 28px;
}

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

.mode-card {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s ease;
}

.mode-card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 16px rgba(67, 56, 202, 0.18);
  transform: translateY(-2px);
}

.mode-icon {
  font-size: 32px;
  margin-bottom: 10px;
}

.mode-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 6px;
}

.mode-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ── Resume card ── */
.resume-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--accent);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.35);
}

.resume-card:hover {
  background: #d97706;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(245, 158, 11, 0.5);
}

.resume-card:active { transform: translateY(0); }

.resume-icon {
  font-size: 20px;
  color: white;
  font-weight: 700;
  width: 32px;
  text-align: center;
  flex-shrink: 0;
}

.resume-title {
  font-size: 14px;
  font-weight: 700;
  color: white;
  margin-bottom: 2px;
}

.resume-desc {
  font-size: 12px;
  color: rgba(255,255,255,0.8);
}

.resume-card .chapter-arrow {
  color: white;
  font-size: 22px;
  margin-left: auto;
}

/* ── Stats strip ── */
.stats-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}

.stat-block {
  background: var(--card);
  border-radius: 10px;
  padding: 14px 10px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Dashboard parent ── */
.dashboard-child-card {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  margin-bottom: 16px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.dashboard-child-card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 16px rgba(67, 56, 202, 0.18);
  transform: translateY(-2px);
}

.dashboard-child-card:active {
  transform: translateY(0);
}

.dashboard-child-name .chapter-arrow {
  margin-left: 6px;
}

.dashboard-child-header {
  margin-bottom: 12px;
}

.dashboard-child-name {
  font-size: 17px;
  font-weight: 700;
}

.dashboard-child-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.dashboard-child-card .stats-strip {
  margin-bottom: 0;
}

.dashboard-section-title {
  font-size: 15px;
  font-weight: 700;
  margin: 24px 0 12px;
}

.detail-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
}

.detail-row-title {
  font-size: 14px;
  font-weight: 600;
}

.detail-row-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.detail-row-badges {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Chapter selector ── */
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.tab {
  flex: 1;
  padding: 10px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  transition: all 0.15s;
}

.tab.active {
  border-color: var(--primary);
  color: var(--primary-dark);
  background: var(--primary-light);
}

.theme-group {
  margin-bottom: 20px;
}

.theme-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding-left: 4px;
}

.chapter-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--card);
  border-radius: 10px;
  border: 1.5px solid var(--border);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.chapter-item:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.chapter-item.has-wrong {
  border-color: var(--warning);
}

.chapter-name {
  font-size: 14px;
  font-weight: 500;
  flex: 1;
  margin-right: 12px;
}

.chapter-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--warning);
  color: white;
  white-space: nowrap;
}

.chapter-offline-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--success-light);
  color: var(--success);
  white-space: nowrap;
  margin-right: 8px;
}

.chapter-arrow {
  color: var(--text-muted);
  font-size: 16px;
  margin-left: 8px;
}

/* ── Upload view ── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: 16px;
}

.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}

.upload-icon { font-size: 40px; margin-bottom: 12px; }
.upload-text { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.upload-hint { font-size: 12px; color: var(--text-muted); }

.upload-file-info {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--success-light);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 16px;
}

.upload-file-icon { font-size: 24px; }
.upload-file-name { font-size: 14px; font-weight: 600; flex: 1; }
.upload-file-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 16px;
}

.field-label {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  display: block;
}

.field-select {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 20px;
  background: white;
  color: var(--text);
}

/* ── Buttons ── */
.btn {
  display: block;
  width: 100%;
  padding: 16px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { background: var(--border); color: var(--text-muted); cursor: default; }

.btn-secondary {
  background: var(--border);
  color: var(--text);
}

.btn-secondary:hover { background: #d1dde8; }

.btn-sm {
  padding: 10px 20px;
  width: auto;
  display: inline-block;
  font-size: 14px;
}

/* ── Loading view ── */
.loading-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
}

.spinner {
  width: 52px;
  height: 52px;
  border: 4px solid var(--primary-light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin-bottom: 24px;
}

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

.loading-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
}

.loading-hint {
  font-size: 14px;
  color: var(--text-muted);
}

/* ── Quiz view ── */
.quiz-header {
  margin-bottom: 20px;
}

.quiz-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
}

.quiz-progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.quiz-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.bloom-tag {
  display: inline-block;
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 20px;
  font-weight: 600;
  margin-bottom: 12px;
}

.bloom-1 { background: #e0f2fe; color: #0369a1; }
.bloom-2 { background: #dcfce7; color: #15803d; }
.bloom-3 { background: #fef9c3; color: #854d0e; }
.bloom-4 { background: #fce7f3; color: #9d174d; }


.question-text {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.5;
  margin-bottom: 22px;
}

.choices-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.choice-btn {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: white;
  cursor: pointer;
  text-align: left;
  font-size: 15px;
  line-height: 1.4;
  transition: all 0.15s;
  width: 100%;
}

.choice-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-light);
}

.choice-btn:disabled { cursor: default; }

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

.choice-btn.wrong {
  border-color: var(--error);
  background: var(--error-light);
}

.choice-letter {
  width: 26px;
  height: 26px;
  min-width: 26px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
}

.choice-btn.correct .choice-letter { background: var(--success); color: white; }
.choice-btn.wrong .choice-letter { background: var(--error); color: white; }

/* ── Open question ── */
.open-textarea {
  width: 100%;
  min-height: 120px;
  padding: 14px;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
  margin-bottom: 14px;
}

.open-textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.self-eval-prompt {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.self-eval-buttons {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.btn-correct {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
  border: 2px solid var(--success);
  background: var(--success-light);
  color: var(--success);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}

.btn-wrong {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
  border: 2px solid var(--error);
  background: var(--error-light);
  color: var(--error);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}

/* ── Feedback block ── */
.feedback {
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 20px;
  display: none;
}

.feedback.show { display: block; }

.feedback.correct {
  background: var(--success-light);
  border: 1.5px solid var(--success);
}

.feedback.wrong {
  background: var(--error-light);
  border: 1.5px solid var(--error);
}

.feedback-header {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.feedback.correct .feedback-header { color: #166534; }
.feedback.wrong .feedback-header { color: #991b1b; }

.feedback-explanation {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
}

.feedback-answer {
  font-size: 14px;
  font-style: italic;
  color: var(--text-muted);
  margin-top: 8px;
}

/* ── Results view ── */
.results-score {
  text-align: center;
  padding: 32px 20px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.results-emoji { font-size: 52px; margin-bottom: 12px; }

.results-fraction {
  font-size: 48px;
  font-weight: 800;
  color: var(--accent);
}

.results-fraction span { color: var(--text-muted); font-size: 28px; }

.results-label {
  font-size: 15px;
  color: var(--text-muted);
  margin-top: 4px;
}

.results-message {
  font-size: 16px;
  font-weight: 600;
  margin-top: 12px;
  color: var(--text);
}

.wrong-recap {
  margin-bottom: 24px;
}

/* ── Login ── */
.login-screen {
  max-width: 360px;
  margin: 12vh auto 0;
  padding: 32px 24px;
  text-align: center;
}

.login-logo {
  font-size: 48px;
  margin-bottom: 12px;
}

.login-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 16px;
}

.login-intro {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 24px;
}

.login-screen .field-label {
  text-align: left;
}

.login-error {
  color: var(--error);
  background: var(--error-light);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  margin: -8px 0 16px;
  text-align: left;
}

.profile-success {
  color: var(--success);
  background: var(--success-light);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  margin: -8px 0 16px;
  text-align: left;
}

.login-hint {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
  margin-top: 16px;
}

.link-logout {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
  padding: 8px;
  text-align: center;
}

.wrong-recap-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}

.wrong-item {
  background: var(--error-light);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 8px;
  font-size: 14px;
  border-left: 3px solid var(--error);
}

.results-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Flashcards ── */
.flashcard {
  perspective: 1200px;
  margin-bottom: 22px;
  cursor: pointer;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 260px;
  transition: transform 0.5s ease;
  transform-style: preserve-3d;
}

.flashcard.flipped .flashcard-inner {
  transform: rotateY(180deg);
}

.flashcard-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 28px 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  backface-visibility: hidden;
}

.flashcard-front {
  background: var(--card);
}

.flashcard-back {
  background: var(--primary-light);
  transform: rotateY(180deg);
}

.flashcard-tag {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
  background: var(--accent-light);
  color: var(--accent);
  margin-bottom: 16px;
}

.flashcard-text {
  font-size: 19px;
  font-weight: 700;
  line-height: 1.5;
}

.flashcard-back .flashcard-text {
  font-size: 16px;
  font-weight: 500;
}

.flashcard-hint {
  margin-top: 18px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Bandeau de mise à jour PWA ── */
.update-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--primary);
  color: white;
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 500;
}

.update-banner-btn {
  flex-shrink: 0;
  background: white;
  color: var(--primary-dark);
  border: none;
  border-radius: 9px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.update-banner-btn:active { transform: scale(0.96); }

/* ── Responsive ── */
@media (max-width: 400px) {
  .mode-grid { grid-template-columns: 1fr; }
  .stats-strip { grid-template-columns: 1fr 1fr; }
  .question-text { font-size: 16px; }
  .flashcard-inner { height: 220px; }
  .flashcard-text { font-size: 17px; }
}
