/* ============================================================
   Cap Permis - Design system (style Ornikar : clean, arrondi)
   ============================================================ */
:root {
  --violet: #6D28D9;
  --violet-600: #7C3AED;
  --violet-500: #8B5CF6;
  --violet-soft: #EDE7FF;
  --violet-softer: #F6F3FF;
  --bg: #F7F5FC;
  --white: #FFFFFF;
  --ink: #1B1335;
  --ink-soft: #564B73;
  --muted: #8A82A0;
  --line: #ECE7F6;
  --green: #16A34A; --green-soft: #E7F8EE;
  --red: #E11D48; --red-soft: #FCE9EE;
  --amber: #D97706; --amber-soft: #FEF3E2;

  --card-radius: 26px;
  --shadow: 0 18px 40px -18px rgba(109, 40, 217, .30);
  --shadow-sm: 0 8px 20px -12px rgba(109, 40, 217, .28);
  --sidebar-w: 264px;
  --ease: cubic-bezier(.22, .8, .2, 1);

  --sat: env(safe-area-inset-top);
  --sab: env(safe-area-inset-bottom);
  --sal: env(safe-area-inset-left);
  --sar: env(safe-area-inset-right);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100dvh;
}
img, svg { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }
a { color: inherit; }
ul { list-style: none; }

:focus-visible {
  outline: 3px solid var(--violet-500);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------- Layout ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 40;
  height: calc(60px + var(--sat));
  padding: var(--sat) calc(16px + var(--sar)) 0 calc(16px + var(--sal));
  display: none; align-items: center; gap: 12px;
  background: rgba(247, 245, 252, .88);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.burger {
  display: grid; place-items: center;
  width: 42px; height: 42px; border-radius: 12px;
  background: var(--white); border: 1px solid var(--line); color: var(--ink);
}
.topbar-logo { flex: 1; display: flex; align-items: center; }
.topbar-spacer { width: 42px; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 60;
  width: var(--sidebar-w);
  padding: calc(24px + var(--sat)) 16px calc(20px + var(--sab));
  background: var(--white);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 6px;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 6px 8px 22px; }
.brand-badge {
  width: 42px; height: 42px; border-radius: 13px; flex: none;
  background: linear-gradient(135deg, #7C3AED, #6D28D9 55%, #5B21B6);
  display: grid; place-items: center; box-shadow: var(--shadow-sm);
}
.brand-name { font-weight: 800; font-size: 1.18rem; letter-spacing: -.02em; }
.brand-name b { color: var(--violet); }

.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 14px;
  color: var(--ink-soft); font-weight: 600; font-size: .96rem;
  transition: background-color .2s var(--ease), color .2s var(--ease), transform .2s var(--ease);
}
.nav-link svg { width: 21px; height: 21px; flex: none; }
.nav-link:hover { background: var(--violet-softer); color: var(--ink); }
.nav-link[aria-current="page"] { background: var(--violet-soft); color: var(--violet); }
.nav-link[aria-current="page"] svg { color: var(--violet); }
.nav-foot { margin-top: auto; padding: 14px 10px 0; color: var(--muted); font-size: .78rem; }

.content {
  margin-left: var(--sidebar-w);
  padding: 34px clamp(18px, 4vw, 48px) 64px;
  padding-left: calc(clamp(18px, 4vw, 48px) + var(--sal));
  padding-right: calc(clamp(18px, 4vw, 48px) + var(--sar));
  max-width: 1120px;
  min-height: 100dvh;
}
.content:focus { outline: none; }

/* Mobile */
@media (max-width: 880px) {
  .topbar { display: flex; }
  .content { margin-left: 0; padding-top: calc(76px + var(--sat)); }
  .sidebar {
    transform: translateX(-104%);
    transition: transform .34s var(--ease);
    box-shadow: 0 30px 60px -20px rgba(27, 19, 53, .35);
    width: min(86vw, 320px);
  }
  body.drawer-open .sidebar { transform: translateX(0); }
  .scrim {
    position: fixed; inset: 0; z-index: 55; border: 0;
    background: rgba(27, 19, 53, .42);
    opacity: 0; transition: opacity .3s var(--ease);
  }
  body.drawer-open .scrim { opacity: 1; }
}

/* ---------- Composants ---------- */
.card {
  background: var(--white); border: 1px solid var(--line);
  border-radius: var(--card-radius); box-shadow: var(--shadow);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  padding: 13px 22px; border-radius: 14px;
  font-weight: 700; font-size: .96rem; letter-spacing: -.01em;
  transition: transform .16s var(--ease), background-color .2s var(--ease), box-shadow .2s var(--ease), border-color .2s var(--ease);
  text-align: center;
}
.btn svg { width: 19px; height: 19px; }
.btn:active { transform: translateY(1px) scale(.985); }
.btn-primary { background: var(--violet); color: #fff; box-shadow: 0 12px 26px -12px rgba(109, 40, 217, .7); }
.btn-primary:hover { background: var(--violet-600); }
.btn-ghost { background: var(--white); color: var(--ink); border: 1.5px solid var(--line); }
.btn-ghost:hover { border-color: var(--violet-500); color: var(--violet); }
.btn-soft { background: var(--violet-soft); color: var(--violet); }
.btn-soft:hover { background: var(--violet-softer); }
.btn-lg { padding: 16px 26px; font-size: 1.02rem; border-radius: 16px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-block { width: 100%; }

.eyebrow { text-transform: uppercase; letter-spacing: .14em; font-size: .72rem; font-weight: 700; color: var(--violet); }
.h1 { font-size: clamp(1.7rem, 4.4vw, 2.5rem); font-weight: 800; letter-spacing: -.03em; line-height: 1.08; }
.h2 { font-size: clamp(1.35rem, 3vw, 1.8rem); font-weight: 800; letter-spacing: -.02em; }
.lead { color: var(--ink-soft); font-size: 1.05rem; }
.section-title { font-size: 1.32rem; font-weight: 800; letter-spacing: -.02em; }

.chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 13px; border-radius: 999px;
  background: var(--violet-soft); color: var(--violet);
  font-weight: 700; font-size: .82rem;
}

/* ---------- Hero ---------- */
.hero {
  position: relative; overflow: hidden;
  border-radius: 32px; padding: clamp(26px, 5vw, 46px);
  background: linear-gradient(135deg, #7C3AED, #6D28D9 52%, #5B21B6);
  color: #fff; box-shadow: 0 30px 60px -24px rgba(91, 33, 182, .6);
}
.hero h1 { font-size: clamp(1.8rem, 5vw, 2.7rem); font-weight: 800; letter-spacing: -.03em; line-height: 1.06; max-width: 16ch; }
.hero p { margin-top: 12px; max-width: 46ch; color: rgba(255, 255, 255, .9); font-size: 1.06rem; }
.hero-cta { margin-top: 22px; display: flex; flex-wrap: wrap; gap: 12px; position: relative; z-index: 2; }
.hero .btn-primary { background: #fff; color: var(--violet); box-shadow: 0 12px 28px -12px rgba(0, 0, 0, .35); }
.hero .btn-primary:hover { background: #fff; }
.hero .btn-ghost { background: rgba(255, 255, 255, .12); color: #fff; border-color: rgba(255, 255, 255, .4); }
.hero-deco { position: absolute; inset: 0; z-index: 0; pointer-events: none; opacity: .9; }

/* ---------- Stats / ring ---------- */
.grid-stats { display: grid; gap: 14px; grid-template-columns: repeat(4, 1fr); }
.stat { padding: 18px; border-radius: 20px; background: var(--white); border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
.stat-ico { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--violet-soft); color: var(--violet); margin-bottom: 12px; }
.stat-num { font-size: 1.7rem; font-weight: 800; letter-spacing: -.02em; }
.stat-lbl { color: var(--muted); font-size: .82rem; font-weight: 600; }

.ring-wrap { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.ring { --p: 0; width: 132px; height: 132px; flex: none; }
.ring circle { fill: none; stroke-width: 13; stroke-linecap: round; }
.ring .track { stroke: var(--violet-soft); }
.ring .bar { stroke: var(--violet); transform: rotate(-90deg); transform-origin: 50% 50%; transition: stroke-dashoffset 1s var(--ease); }
.ring-label { text-align: center; }
.ring-pct { font-size: 1.55rem; font-weight: 800; }

/* ---------- Thèmes (cours) ---------- */
.grid-themes { display: grid; gap: 16px; grid-template-columns: repeat(3, 1fr); }
.theme-card {
  position: relative; text-align: left; width: 100%;
  padding: 22px; border-radius: var(--card-radius);
  background: var(--white); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
  transition: transform .22s var(--ease), box-shadow .22s var(--ease), border-color .22s var(--ease);
  display: flex; flex-direction: column; gap: 12px;
}
.theme-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.theme-ico { width: 50px; height: 50px; border-radius: 15px; display: grid; place-items: center; background: color-mix(in srgb, var(--accent) 14%, #fff); color: var(--accent); }
.theme-ico svg { width: 27px; height: 27px; }
.theme-title { font-weight: 800; font-size: 1.08rem; letter-spacing: -.01em; }
.theme-desc { color: var(--ink-soft); font-size: .9rem; flex: 1; }
.theme-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 4px; }
.theme-count { color: var(--muted); font-size: .8rem; font-weight: 600; }
.bar-mini { height: 8px; border-radius: 99px; background: var(--violet-soft); overflow: hidden; flex: 1; max-width: 120px; }
.bar-mini > i { display: block; height: 100%; border-radius: 99px; background: var(--accent); transform-origin: left; transition: transform .6s var(--ease); }

/* ---------- Leçon ---------- */
.lesson { max-width: 760px; }
.lesson h2 { font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; margin: 30px 0 12px; }
.lesson h3 { font-size: 1.16rem; font-weight: 700; margin: 22px 0 8px; color: var(--ink); }
.lesson p { margin: 10px 0; color: var(--ink-soft); }
.lesson strong { color: var(--ink); font-weight: 700; }
.lesson ul.bul { margin: 10px 0; display: flex; flex-direction: column; gap: 8px; }
.lesson ul.bul > li { position: relative; padding-left: 26px; color: var(--ink-soft); }
.lesson ul.bul > li::before { content: ""; position: absolute; left: 6px; top: .62em; width: 8px; height: 8px; border-radius: 3px; background: var(--accent); }
.callout { margin: 16px 0; padding: 15px 17px; border-radius: 18px; display: flex; gap: 12px; }
.callout svg { width: 22px; height: 22px; flex: none; margin-top: 1px; }
.callout p { margin: 0; color: inherit; }
.callout b { display: block; margin-bottom: 2px; }
.callout.tip { background: var(--green-soft); color: #14532d; }
.callout.imp { background: var(--amber-soft); color: #7c3a06; }
.callout.note { background: var(--violet-softer); color: #4c2a86; }
.fig { margin: 18px 0; padding: 18px; border-radius: 20px; background: var(--violet-softer); border: 1px solid var(--line); }
.fig figcaption { margin-top: 10px; text-align: center; color: var(--ink-soft); font-size: .86rem; font-weight: 600; }

/* ---------- QCM ---------- */
.quiz { max-width: 720px; }
.q-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.q-progress { height: 9px; border-radius: 99px; background: var(--violet-soft); overflow: hidden; flex: 1; }
.q-progress > i { display: block; height: 100%; background: var(--accent, var(--violet)); transition: transform .4s var(--ease); transform-origin: left; }
.q-count { font-weight: 700; color: var(--muted); font-size: .86rem; white-space: nowrap; }
.q-card { padding: clamp(18px, 3vw, 26px); }
.q-text { font-size: 1.18rem; font-weight: 700; letter-spacing: -.01em; line-height: 1.4; }
.q-hint { margin-top: 6px; color: var(--muted); font-size: .82rem; font-weight: 600; }
.opts { margin-top: 18px; display: flex; flex-direction: column; gap: 11px; }
.opt {
  display: flex; align-items: center; gap: 13px; text-align: left; width: 100%;
  padding: 15px 16px; border-radius: 16px;
  background: var(--white); border: 1.5px solid var(--line); color: var(--ink);
  font-weight: 600; transition: border-color .18s var(--ease), background-color .18s var(--ease), transform .12s var(--ease);
}
.opt:active { transform: scale(.99); }
.opt .box { width: 24px; height: 24px; border-radius: 8px; border: 2px solid var(--line); flex: none; display: grid; place-items: center; transition: .18s var(--ease); }
.opt .box svg { width: 15px; height: 15px; opacity: 0; transform: scale(.6); transition: .18s var(--ease); }
.opt[aria-pressed="true"] { border-color: var(--violet); background: var(--violet-softer); }
.opt[aria-pressed="true"] .box { background: var(--violet); border-color: var(--violet); color: #fff; }
.opt[aria-pressed="true"] .box svg { opacity: 1; transform: scale(1); }
.opt.correct { border-color: var(--green); background: var(--green-soft); }
.opt.correct .box { background: var(--green); border-color: var(--green); color: #fff; }
.opt.correct .box svg { opacity: 1; transform: scale(1); }
.opt.wrong { border-color: var(--red); background: var(--red-soft); }
.opt.wrong .box { background: var(--red); border-color: var(--red); color: #fff; }
.opt.wrong .box svg { opacity: 1; transform: scale(1); }
.opt.locked { pointer-events: none; }
.opt.dim { opacity: .6; }
.explain { margin-top: 16px; padding: 15px 17px; border-radius: 16px; background: var(--violet-softer); border: 1px solid var(--line); }
.explain b { color: var(--violet); }
.explain.ok { background: var(--green-soft); border-color: transparent; }
.explain.ok b { color: var(--green); }
.explain.ko { background: var(--red-soft); border-color: transparent; }
.explain.ko b { color: var(--red); }
.q-actions { margin-top: 18px; display: flex; gap: 12px; flex-wrap: wrap; }

/* ---------- Timer examen ---------- */
.exam-bar { height: 10px; border-radius: 99px; background: var(--violet-soft); overflow: hidden; }
.exam-bar > i { display: block; height: 100%; background: var(--violet); transform-origin: left; }
.exam-bar.danger > i { background: var(--red); }
.exam-timer { font-weight: 800; font-variant-numeric: tabular-nums; }
.exam-timer.danger { color: var(--red); }
.exam-lives { display: flex; gap: 5px; }
.exam-lives svg { width: 22px; height: 22px; color: var(--red); }
.exam-lives .lost { color: var(--line); }

/* ---------- Résultat ---------- */
.result-hero { text-align: center; padding: clamp(26px, 5vw, 44px); border-radius: 30px; color: #fff; }
.result-hero.pass { background: linear-gradient(135deg, #22C55E, #16A34A); }
.result-hero.fail { background: linear-gradient(135deg, #FB7185, #E11D48); }
.result-big { font-size: clamp(2.2rem, 7vw, 3.2rem); font-weight: 800; letter-spacing: -.03em; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 22px; }
.result-stat { background: var(--white); border: 1px solid var(--line); border-radius: 18px; padding: 16px; text-align: center; }
.result-stat .n { font-size: 1.5rem; font-weight: 800; }
.result-stat .l { color: var(--muted); font-size: .8rem; font-weight: 600; }

.review-item { padding: 16px; border-radius: 18px; border: 1px solid var(--line); background: var(--white); }
.review-item .qi { display: flex; gap: 10px; align-items: baseline; }
.review-badge { width: 22px; height: 22px; border-radius: 7px; flex: none; display: grid; place-items: center; }
.review-badge.ok { background: var(--green-soft); color: var(--green); }
.review-badge.ko { background: var(--red-soft); color: var(--red); }

/* ---------- Divers ---------- */
.stack { display: flex; flex-direction: column; }
.gap-s > * + * { margin-top: 12px; }
.gap-m > * + * { margin-top: 20px; }
.gap-l > * + * { margin-top: 30px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.between { justify-content: space-between; }
.muted { color: var(--muted); }
.center { text-align: center; }
.back-link { display: inline-flex; align-items: center; gap: 7px; color: var(--ink-soft); font-weight: 700; font-size: .9rem; margin-bottom: 14px; }
.back-link:hover { color: var(--violet); }
.back-link svg { width: 18px; height: 18px; }

.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty svg { width: 54px; height: 54px; margin: 0 auto 14px; color: var(--violet-500); opacity: .7; }

/* ---------- Animations cascade ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
.reveal { opacity: 0; animation: rise .5s var(--ease) forwards; }
.reveal:nth-child(1) { animation-delay: .03s; }
.reveal:nth-child(2) { animation-delay: .08s; }
.reveal:nth-child(3) { animation-delay: .13s; }
.reveal:nth-child(4) { animation-delay: .18s; }
.reveal:nth-child(5) { animation-delay: .23s; }
.reveal:nth-child(6) { animation-delay: .28s; }
.reveal:nth-child(7) { animation-delay: .33s; }
.reveal:nth-child(8) { animation-delay: .38s; }
.view-enter { animation: rise .42s var(--ease) both; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Responsive grids ---------- */
@media (max-width: 1000px) { .grid-themes { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 720px) {
  .grid-stats { grid-template-columns: repeat(2, 1fr); }
  .grid-themes { grid-template-columns: 1fr; }
  .result-stats { grid-template-columns: repeat(3, 1fr); }
}
