  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface2: #1e2530;
    --border: #2a3340;
    --accent: #58a6ff;
    --accent2: #3fb950;
    --accent3: #f78166;
    --accent4: #d2a8ff;
    --warn: #e3b341;
    --text: #e6edf3;
    --text2: #8b949e;
    --text3: #6e7681;
    --correct: #238636;
    --correct-bg: #0d2818;
    --correct-border: #2ea043;
    --wrong: #b91c1c;
    --wrong-bg: #2d0e0e;
    --wrong-border: #f85149;
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  }

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

  body {
    font-family: 'DM Sans', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
  }

  /* ── BACKGROUND ── */
  .bg-mesh {
    position: fixed; inset: 0; z-index: 0; pointer-events: none;
    background:
      radial-gradient(ellipse 80% 60% at 20% 10%, rgba(88,166,255,.07) 0%, transparent 60%),
      radial-gradient(ellipse 60% 50% at 80% 80%, rgba(212,168,255,.06) 0%, transparent 55%),
      radial-gradient(ellipse 40% 40% at 50% 50%, rgba(63,185,80,.04) 0%, transparent 60%);
  }

  /* ── LAYOUT ── */
  #app { position: relative; z-index: 1; }

  /* ════════════════════════════════
     HOME PAGE
  ════════════════════════════════ */
  #home {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    gap: 60px;
  }

  .hero {
    text-align: center;
    max-width: 700px;
  }

  .badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--accent);
    background: rgba(88,166,255,.1);
    border: 1px solid rgba(88,166,255,.25);
    padding: 5px 14px;
    border-radius: 99px;
    margin-bottom: 24px;
  }

  .hero h1 {
    font-family: 'DM Serif Display', serif;
    font-size: clamp(2.8rem, 7vw, 5.2rem);
    line-height: 1.1;
    letter-spacing: -.02em;
    margin-bottom: 20px;
    background: linear-gradient(135deg, #e6edf3 30%, #7ea8d5 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
  }

  .hero h1 em {
    font-style: italic;
    background: linear-gradient(135deg, var(--accent4) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
  }

  .hero p {
    font-size: 1.15rem;
    color: var(--text2);
    line-height: 1.7;
    max-width: 520px;
    margin: 0 auto;
  }

  /* ── STAT BAR ── */
  .stats-row {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 36px;
  }

  .stat-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 99px;
    padding: 8px 18px;
    font-size: 14px;
    font-weight: 500;
  }

  .stat-pill .dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent);
    flex-shrink: 0;
  }

  .stat-pill:nth-child(2) .dot { background: var(--accent4); box-shadow: 0 0 8px var(--accent4); }
  .stat-pill:nth-child(3) .dot { background: var(--accent2); box-shadow: 0 0 8px var(--accent2); }

  /* ── SECTION CARDS ── */
  .sections-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 24px;
    max-width: 900px;
    width: 100%;
  }

  .section-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 32px;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
    animation: fadeUp 0.5s ease both;
  }

  .section-card:nth-child(2) { animation-delay: .1s; }

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

  .section-card::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 18px;
    background: linear-gradient(135deg, rgba(88,166,255,.05) 0%, transparent 60%);
    opacity: 0;
    transition: var(--transition);
  }

  .section-card:hover {
    border-color: rgba(88,166,255,.4);
    transform: translateY(-4px);
    box-shadow: 0 16px 40px rgba(0,0,0,.4);
  }

  .section-card:hover::before { opacity: 1; }
  .section-card:nth-child(2):hover { border-color: rgba(212,168,255,.4); }
  .section-card:nth-child(2)::before { background: linear-gradient(135deg, rgba(212,168,255,.05) 0%, transparent 60%); }

  .card-icon {
    width: 52px; height: 52px;
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px;
    margin-bottom: 20px;
    background: rgba(88,166,255,.12);
    border: 1px solid rgba(88,166,255,.2);
  }

  .section-card:nth-child(2) .card-icon {
    background: rgba(212,168,255,.12);
    border-color: rgba(212,168,255,.2);
  }

  .card-chapter { font-size: 12px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--accent); margin-bottom: 8px; }
  .section-card:nth-child(2) .card-chapter { color: var(--accent4); }

  .card-title {
    font-family: 'DM Serif Display', serif;
    font-size: 1.5rem;
    margin-bottom: 10px;
    line-height: 1.3;
  }

  .card-desc {
    font-size: 14px;
    color: var(--text2);
    line-height: 1.6;
    margin-bottom: 24px;
  }

  .topics-list {
    display: flex; flex-wrap: wrap; gap: 6px;
    margin-bottom: 28px;
  }

  .topic-tag {
    font-size: 12px;
    color: var(--text2);
    background: var(--surface2);
    border: 1px solid var(--border);
    padding: 3px 10px;
    border-radius: 6px;
  }

  .card-footer {
    display: flex; align-items: center; justify-content: space-between;
  }

  .q-count {
    font-size: 13px; color: var(--text3);
  }

  .btn-start {
    display: inline-flex; align-items: center; gap: 8px;
    background: var(--accent);
    color: #0d1117;
    border: none; border-radius: 10px;
    padding: 10px 20px;
    font-family: 'DM Sans', sans-serif;
    font-size: 14px; font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
  }

  .btn-start:hover { background: #79b8ff; transform: translateX(2px); }
  .section-card:nth-child(2) .btn-start { background: var(--accent4); }
  .section-card:nth-child(2) .btn-start:hover { background: #e2ccff; }

  .btn-start .arrow { transition: transform .2s; }
  .btn-start:hover .arrow { transform: translateX(4px); }

  /* ════════════════════════════════
     QUIZ PAGE
  ════════════════════════════════ */
  #quiz { display: none; min-height: 100vh; }

  /* ── TOP BAR ── */
  .quiz-topbar {
    position: sticky; top: 0; z-index: 100;
    background: rgba(13,17,23,.9);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex; align-items: center; gap: 16px;
  }

  .btn-back {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text2);
    border-radius: 8px;
    padding: 7px 12px;
    font-size: 13px; font-weight: 500;
    cursor: pointer;
    display: flex; align-items: center; gap: 6px;
    font-family: 'DM Sans', sans-serif;
    transition: var(--transition);
    flex-shrink: 0;
  }
  .btn-back:hover { color: var(--text); border-color: var(--accent); }

  .quiz-title-bar {
    font-size: 14px; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    color: var(--text2);
  }

  .progress-wrap {
    flex: 1;
    display: flex; flex-direction: column; gap: 4px;
  }

  .progress-info {
    display: flex; justify-content: space-between;
    font-size: 12px; color: var(--text3);
  }

  .progress-bar-track {
    height: 4px;
    background: var(--border);
    border-radius: 99px;
    overflow: hidden;
  }

  .progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent4));
    border-radius: 99px;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .score-badge {
    flex-shrink: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 14px;
    font-size: 13px; font-weight: 600;
    white-space: nowrap;
  }

  .score-badge .s-right { color: var(--accent2); }
  .score-badge .s-wrong { color: var(--accent3); }

  /* ── MODE TOGGLE ── */
  .mode-row {
    display: flex; gap: 8px; align-items: center;
    padding: 12px 24px 0;
    max-width: 780px; margin: 0 auto;
  }

  .mode-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text2);
    border-radius: 8px;
    padding: 6px 14px;
    font-size: 13px; font-weight: 500;
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    transition: var(--transition);
    display: flex; align-items: center; gap: 6px;
  }
  .mode-btn.active { background: rgba(88,166,255,.15); border-color: var(--accent); color: var(--accent); }
  .mode-btn:hover:not(.active) { border-color: var(--text3); color: var(--text); }

  /* ── QUESTION CARD ── */
  .quiz-body {
    max-width: 780px;
    margin: 0 auto;
    padding: 28px 20px 80px;
  }

  .question-meta {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 20px;
  }

  .q-type-badge {
    font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
    padding: 3px 10px; border-radius: 6px;
  }
  .q-type-badge.choix_multiple { background: rgba(88,166,255,.15); color: var(--accent); }
  .q-type-badge.vrai_faux      { background: rgba(227,179,65,.15);  color: var(--warn); }
  .q-type-badge.piege          { background: rgba(248,81,73,.15);   color: var(--accent3); }
  .q-type-badge.definition     { background: rgba(212,168,255,.15); color: var(--accent4); }
  .q-type-badge.cas_pratique   { background: rgba(63,185,80,.15);   color: var(--accent2); }

  .q-number {
    font-size: 13px; color: var(--text3);
    margin-left: auto;
  }

  .question-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 32px;
    margin-bottom: 24px;
    animation: slideIn .35s ease both;
  }

  @keyframes slideIn {
    from { opacity: 0; transform: translateY(16px) scale(.98); }
    to   { opacity: 1; transform: none; }
  }

  .question-text {
    font-family: 'DM Serif Display', serif;
    font-size: 1.35rem;
    line-height: 1.5;
    color: var(--text);
  }

  .question-hint {
    margin-top: 10px;
    font-size: 13px; color: var(--text3);
    font-style: italic;
  }

  /* ── OPTIONS ── */
  .options-list {
    display: flex; flex-direction: column; gap: 12px;
    margin-top: 28px;
  }

  .free-text-wrap {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: 28px;
  }

  .free-text-input {
    width: 100%;
    min-height: 120px;
    padding: 18px 20px;
    border-radius: var(--radius);
    border: 2px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    font-family: 'DM Sans', sans-serif;
    font-size: 16px;
    line-height: 1.5;
    resize: vertical;
    transition: var(--transition);
  }

  .free-text-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(232, 160, 191, 0.15);
  }

  .free-text-input:disabled {
    opacity: 0.75;
    cursor: not-allowed;
  }

  .btn-validate-text {
    align-self: flex-start;
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: var(--radius);
    padding: 14px 24px;
    font-family: 'DM Sans', sans-serif;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
  }

  .btn-validate-text:hover:not(:disabled) {
    transform: translateY(-1px);
    filter: brightness(1.05);
  }

  .btn-validate-text:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  .q-type-badge.texte_libre {
    background: rgba(232, 160, 191, 0.15);
    color: #e8a0bf;
    border-color: rgba(232, 160, 191, 0.35);
  }

  .option-btn {
    background: var(--surface2);
    border: 2px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    padding: 16px 20px;
    text-align: left;
    font-family: 'DM Sans', sans-serif;
    font-size: 15px; font-weight: 400;
    cursor: pointer;
    transition: var(--transition);
    display: flex; align-items: flex-start; gap: 14px;
    line-height: 1.5;
    position: relative;
    overflow: hidden;
  }

  .option-btn::before {
    content: '';
    position: absolute; inset: 0;
    background: var(--accent);
    opacity: 0;
    transition: opacity .2s;
  }

  .option-letter {
    flex-shrink: 0;
    width: 28px; height: 28px;
    border-radius: 8px;
    background: var(--border);
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700;
    font-family: 'DM Serif Display', serif;
    color: var(--text2);
    transition: var(--transition);
  }

  .option-btn:hover:not(:disabled) {
    border-color: var(--accent);
    transform: translateX(4px);
  }
  .option-btn:hover:not(:disabled) .option-letter { background: var(--accent); color: var(--bg); }

  .option-btn.correct {
    border-color: var(--correct-border);
    background: var(--correct-bg);
    color: #56d364;
  }
  .option-btn.correct .option-letter { background: var(--correct-border); color: #fff; }

  .option-btn.wrong {
    border-color: var(--wrong-border);
    background: var(--wrong-bg);
    color: #ff7b72;
  }
  .option-btn.wrong .option-letter { background: var(--wrong-border); color: #fff; }

  .option-btn.selected-wrong {
    border-color: var(--wrong-border);
    background: var(--wrong-bg);
    color: #ff7b72;
    animation: shake .4s ease;
  }

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

  .option-btn:disabled { cursor: default; transform: none !important; }

  /* ── EXPLANATION ── */
  .explanation-card {
    border-radius: 16px;
    padding: 24px;
    margin-top: 20px;
    animation: expandIn .35s ease both;
    border: 1px solid;
  }

  @keyframes expandIn {
    from { opacity: 0; transform: scaleY(.95); transform-origin: top; }
    to   { opacity: 1; transform: none; }
  }

  .explanation-card.correct-card {
    background: var(--correct-bg);
    border-color: var(--correct-border);
  }

  .explanation-card.wrong-card {
    background: var(--wrong-bg);
    border-color: var(--wrong-border);
  }

  .expl-header {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 14px;
  }

  .expl-icon {
    width: 32px; height: 32px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
  }
  .correct-card .expl-icon { background: rgba(46,160,67,.2); }
  .wrong-card .expl-icon   { background: rgba(248,81,73,.2); }

  .expl-verdict {
    font-weight: 700; font-size: 16px;
  }
  .correct-card .expl-verdict { color: #56d364; }
  .wrong-card .expl-verdict   { color: #ff7b72; }

  .expl-section {
    margin-top: 14px;
  }

  .expl-label {
    font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
    color: var(--text3); margin-bottom: 6px;
  }

  .expl-text {
    font-size: 14px; color: var(--text2); line-height: 1.65;
  }

  .expl-course {
    margin-top: 14px;
    background: rgba(255,255,255,.04);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
  }

  .expl-course .expl-label { margin-bottom: 6px; }

  .wrong-options {
    margin-top: 14px;
  }

  .wrong-item {
    display: flex; gap: 8px; align-items: flex-start;
    padding: 8px 0;
    border-top: 1px solid rgba(255,255,255,.05);
    font-size: 13px; color: var(--text2);
  }
  .wrong-item:first-child { border-top: none; }

  .wrong-label {
    flex-shrink: 0;
    font-weight: 700; color: var(--accent3); font-size: 12px;
    margin-top: 2px;
  }

  /* ── NEXT BTN ── */
  .nav-row {
    display: flex; justify-content: flex-end;
    margin-top: 24px;
  }

  .btn-next {
    background: var(--accent);
    border: none;
    color: #0d1117;
    border-radius: 12px;
    padding: 13px 28px;
    font-family: 'DM Sans', sans-serif;
    font-size: 15px; font-weight: 700;
    cursor: pointer;
    display: flex; align-items: center; gap: 8px;
    transition: var(--transition);
    letter-spacing: -.01em;
  }
  .btn-next:hover { background: #79b8ff; transform: translateX(3px); }
  .btn-next:disabled { opacity: .35; cursor: default; transform: none; }

  /* ════════════════════════════════
     RESULTS PAGE
  ════════════════════════════════ */
  #results { display: none; }

  .results-wrapper {
    min-height: 100vh;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 60px 20px;
    gap: 32px;
  }

  .results-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 48px;
    max-width: 560px; width: 100%;
    text-align: center;
    animation: popIn .5s cubic-bezier(0.34,1.56,0.64,1) both;
  }

  @keyframes popIn {
    from { opacity: 0; transform: scale(.9) translateY(20px); }
    to   { opacity: 1; transform: none; }
  }

  .results-emoji { font-size: 64px; margin-bottom: 16px; display: block; }

  .results-title {
    font-family: 'DM Serif Display', serif;
    font-size: 2.4rem;
    margin-bottom: 8px;
  }

  .results-subtitle {
    color: var(--text2); font-size: 15px; margin-bottom: 36px;
  }

  .score-circle {
    width: 140px; height: 140px;
    border-radius: 50%;
    border: 4px solid var(--border);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    margin: 0 auto 32px;
    position: relative;
    background: var(--surface2);
  }

  .score-number {
    font-family: 'DM Serif Display', serif;
    font-size: 2.8rem;
    line-height: 1;
    background: linear-gradient(135deg, var(--accent), var(--accent4));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
  }

  .score-denom { font-size: 14px; color: var(--text3); }

  .results-stats {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 32px;
  }

  .r-stat {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
  }

  .r-stat-val {
    font-family: 'DM Serif Display', serif;
    font-size: 1.8rem;
    display: block;
  }
  .r-stat:nth-child(1) .r-stat-val { color: var(--accent2); }
  .r-stat:nth-child(2) .r-stat-val { color: var(--accent3); }

  .r-stat-label { font-size: 13px; color: var(--text3); }

  .results-actions {
    display: flex; gap: 12px; flex-wrap: wrap;
    justify-content: center;
  }

  .btn-action {
    border-radius: 12px;
    padding: 12px 24px;
    font-family: 'DM Sans', sans-serif;
    font-size: 14px; font-weight: 600;
    cursor: pointer; border: none;
    transition: var(--transition);
    display: flex; align-items: center; gap: 8px;
  }

  .btn-action.primary { background: var(--accent); color: var(--bg); }
  .btn-action.primary:hover { background: #79b8ff; }
  .btn-action.secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
  .btn-action.secondary:hover { border-color: var(--accent); color: var(--accent); }

  /* ── REVIEW MODE ── */
  .review-wrapper {
    max-width: 780px; margin: 0 auto;
    padding: 20px 20px 80px;
    display: flex; flex-direction: column; gap: 20px;
  }

  .review-header {
    padding: 20px 24px 0;
    max-width: 780px; margin: 0 auto;
    display: flex; align-items: center; justify-content: space-between;
  }

  .review-title {
    font-family: 'DM Serif Display', serif;
    font-size: 1.5rem;
  }

  .filter-group { display: flex; gap: 6px; }

  .filter-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text3);
    border-radius: 8px;
    padding: 5px 12px;
    font-size: 12px; font-weight: 600;
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    transition: var(--transition);
  }
  .filter-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(88,166,255,.1); }
  .filter-btn.f-correct.active { border-color: var(--correct-border); color: var(--accent2); background: rgba(63,185,80,.1); }
  .filter-btn.f-wrong.active { border-color: var(--wrong-border); color: var(--accent3); background: rgba(248,81,73,.1); }

  .review-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    border-left-width: 4px;
  }
  .review-item.was-correct { border-left-color: var(--correct-border); }
  .review-item.was-wrong   { border-left-color: var(--wrong-border); }

  .review-q { font-size: 15px; font-weight: 500; margin-bottom: 10px; }
  .review-answer {
    display: flex; gap: 8px; align-items: flex-start;
    font-size: 14px; color: var(--text2);
  }
  .review-marker { font-size: 16px; flex-shrink: 0; }
  .review-your { font-size: 13px; color: var(--text3); margin-top: 4px; }

  /* Scrollbar */
  ::-webkit-scrollbar { width: 6px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

  /* Responsive */
  @media (max-width: 600px) {
    .quiz-topbar { padding: 10px 14px; gap: 10px; }
    .quiz-title-bar { display: none; }
    .question-card { padding: 20px; }
    .btn-next { padding: 11px 20px; font-size: 14px; }
    .results-card { padding: 32px 24px; }
    .sections-grid { grid-template-columns: 1fr; }
  }
