/* ==========================================================================
   Collège+ — système de design
   ========================================================================== */
:root {
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e6e9f2;
  --bg: #f5f6fb;
  --card: #ffffff;
  --ok: #10b981;
  --ok-soft: #d1fae5;
  --bad: #ef4444;
  --bad-soft: #fee2e2;
  --warn: #f59e0b;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px -12px rgba(15, 23, 42, .12);
  --shadow-lg: 0 24px 48px -20px rgba(15, 23, 42, .25);
  --brand: #4f46e5;
  --brand-2: #2563eb;
  --brand-soft: #eef2ff;
  --maths: linear-gradient(135deg, #6366f1, #8b5cf6);
  --pc: linear-gradient(135deg, #06b6d4, #3b82f6);
}
.app-prof, .theme-prof   { --brand: #4f46e5; --brand-2: #2563eb; --brand-soft: #eef2ff; }
.app-eleve, .theme-eleve { --brand: #7c3aed; --brand-2: #db2777; --brand-soft: #f5f0ff; }
.app-parent, .theme-parent { --brand: #0d9488; --brand-2: #0891b2; --brand-soft: #e6fbf7; }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.2; letter-spacing: -.02em; }
h1 { font-size: 1.75rem; font-weight: 800; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }
p { margin: 0; }
a { color: var(--brand); text-decoration: none; }
img, video { max-width: 100%; display: block; }
.ic { flex: none; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.grad { background: linear-gradient(135deg, var(--brand), var(--brand-2)); }

/* ----- Logo ----- */
.logo { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 800; font-size: 1.15rem; letter-spacing: -.02em; }
.logo-mark {
  width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; font-size: .9rem; font-weight: 800;
  box-shadow: 0 6px 14px -6px var(--brand);
}

/* ----- Coquille d'application ----- */
.shell { display: grid; grid-template-columns: 264px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 24px 16px; background: var(--card);
  border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 18px;
}
.brand { padding: 0 8px; }
.role-pill {
  margin: 0 8px; padding: 6px 12px; border-radius: 99px; background: var(--brand-soft); color: var(--brand);
  font-size: .75rem; font-weight: 700; width: fit-content; letter-spacing: .02em;
}
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 12px;
  color: var(--ink-2); font-weight: 600; font-size: .93rem; transition: background .15s, color .15s;
}
.nav a:hover { background: var(--bg); }
.nav a.active { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; box-shadow: 0 10px 20px -12px var(--brand); }
.nav .nav-logout { margin-top: auto; color: var(--muted); }
.me { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 14px; background: var(--bg); min-width: 0; }
.me-text { min-width: 0; display: flex; flex-direction: column; }
.me-text strong { font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-text small { color: var(--muted); font-size: .76rem; }
.avatar {
  width: 40px; height: 40px; flex: none; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: .85rem;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
}
.avatar.lg { width: 56px; height: 56px; font-size: 1.1rem; }
.main { padding: 32px clamp(16px, 4vw, 44px) 64px; max-width: 1240px; width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head p { color: var(--muted); margin-top: 4px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ----- Boutons ----- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 18px; border-radius: 12px;
  border: 1px solid transparent; font: inherit; font-weight: 700; font-size: .92rem; cursor: pointer; white-space: nowrap;
  transition: transform .12s, box-shadow .15s, background .15s; text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; box-shadow: 0 10px 20px -10px var(--brand); }
.btn-primary:hover { box-shadow: 0 14px 24px -10px var(--brand); transform: translateY(-1px); }
.btn-soft { background: var(--brand-soft); color: var(--brand); }
.btn-ghost { background: var(--card); border-color: var(--line); color: var(--ink-2); }
.btn-ghost:hover { border-color: #cbd2e1; }
.btn-danger { background: var(--card); border-color: var(--line); color: var(--bad); }
.btn-danger:hover { background: var(--bad-soft); border-color: transparent; }
.btn-sm { padding: 7px 12px; font-size: .82rem; border-radius: 10px; }
.btn-icon { padding: 8px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .6; cursor: progress; }
.btn-white { background: #fff; color: var(--brand); }

/* ----- Cartes & grilles ----- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.grid { display: grid; gap: 18px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
.g3 { grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.split { display: grid; gap: 18px; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); align-items: start; }
.stack { display: flex; flex-direction: column; gap: 18px; }
.grid > *, .split > *, .stack > * { min-width: 0; }
.row { display: flex; align-items: center; gap: 12px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.section-title { margin: 32px 0 14px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }

.stat { display: flex; align-items: center; gap: 14px; }
.stat-ic { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); font-size: 1.3rem; flex: none; }
.stat b { display: block; font-size: 1.5rem; font-weight: 800; line-height: 1.1; letter-spacing: -.02em; }
.stat span { color: var(--muted); font-size: .82rem; font-weight: 500; }

/* ----- Héro ----- */
.hero {
  position: relative; overflow: hidden; border-radius: 24px; padding: 30px; color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); box-shadow: 0 24px 40px -24px var(--brand);
}
.hero::before, .hero::after { content: ""; position: absolute; border-radius: 50%; background: rgba(255, 255, 255, .12); }
.hero::before { width: 260px; height: 260px; right: -70px; top: -110px; }
.hero::after { width: 160px; height: 160px; right: 120px; bottom: -90px; }
.hero > * { position: relative; z-index: 1; }
.hero h1 { font-size: clamp(1.4rem, 3vw, 1.9rem); }
.hero p { opacity: .9; margin-top: 6px; max-width: 56ch; }
.hero-stats { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 22px; }
.hero-stat { background: rgba(255, 255, 255, .16); backdrop-filter: blur(6px); border: 1px solid rgba(255, 255, 255, .22); border-radius: 16px; padding: 12px 16px; min-width: 120px; }
.hero-stat b { display: block; font-size: 1.35rem; font-weight: 800; line-height: 1.2; }
.hero-stat span { font-size: .78rem; opacity: .9; }
.xp-wrap { margin-top: 20px; max-width: 460px; }
.xp-wrap .row { font-size: .82rem; font-weight: 600; margin-bottom: 6px; }
.xp-wrap .progress { background: rgba(255, 255, 255, .25); height: 10px; }
.xp-wrap .progress span { background: #fff; }

/* ----- Progression, puces ----- */
.progress { height: 8px; border-radius: 99px; background: #e9ecf5; overflow: hidden; }
.progress span { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--brand), var(--brand-2)); transition: width .5s ease; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; font-size: .74rem; font-weight: 700; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.chip-glass { background: rgba(255, 255, 255, .22); color: #fff; backdrop-filter: blur(4px); }
.chip-ok { background: var(--ok-soft); color: #047857; }
.chip-off { background: #f1f5f9; color: var(--muted); }
.chip-warn { background: #fef3c7; color: #92400e; }

/* ----- Cartes de cours ----- */
.course-card { display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; color: inherit; box-shadow: var(--shadow); transition: transform .18s, box-shadow .18s; }
.course-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.course-cover { height: 104px; padding: 14px; display: flex; justify-content: space-between; align-items: flex-start; background: var(--maths); position: relative; overflow: hidden; }
.course-cover::after { content: ""; position: absolute; width: 150px; height: 150px; border-radius: 50%; background: rgba(255, 255, 255, .14); right: -40px; bottom: -80px; }
.subj-pc .course-cover { background: var(--pc); }
.course-emoji { font-size: 2.2rem; filter: drop-shadow(0 6px 8px rgba(0, 0, 0, .2)); }
.course-body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.course-subject { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: #6366f1; }
.subj-pc .course-subject { color: #0891b2; }
.course-body p { color: var(--muted); font-size: .86rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.course-foot { margin-top: auto; padding-top: 12px; display: flex; flex-direction: column; gap: 8px; font-size: .78rem; color: var(--muted); font-weight: 600; }
.course-meta { display: flex; gap: 12px; flex-wrap: wrap; }

/* ----- Formulaires ----- */
label { display: block; font-weight: 600; font-size: .86rem; margin-bottom: 6px; color: var(--ink-2); }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid #d7dcea; background: #fff; font: inherit; color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 16%, transparent); }
textarea { min-height: 120px; resize: vertical; }
.field { margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.hint { font-size: .78rem; color: var(--muted); margin-top: 5px; }
input[type=file] { width: 100%; padding: 12px; border: 1.5px dashed #c9d0e3; border-radius: 12px; background: #fafbff; font: inherit; font-size: .85rem; color: var(--muted); }
input[type=file]::file-selector-button { margin-right: 12px; padding: 7px 12px; border: 0; border-radius: 9px; background: var(--brand-soft); color: var(--brand); font: inherit; font-weight: 700; cursor: pointer; }

.flash { padding: 13px 16px; border-radius: 12px; margin-bottom: 20px; font-weight: 600; font-size: .9rem; background: var(--ok-soft); color: #065f46; }
.flash-err { background: var(--bad-soft); color: #991b1b; }

/* ----- Tableaux & listes ----- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 13px 12px; border-bottom: 1px solid #f0f2f8; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 14px; padding: 13px 0; border-bottom: 1px solid #f0f2f8; }
.item:last-child { border-bottom: 0; padding-bottom: 0; }
.item:first-child { padding-top: 0; }
.item-ic { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; flex: none; background: var(--brand-soft); color: var(--brand); font-size: 1.2rem; }
.item-main { flex: 1; min-width: 0; }
.item-main strong { display: block; font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-main small { color: var(--muted); font-size: .8rem; }
.item-actions { display: flex; gap: 6px; flex: none; }
.empty { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty .big { font-size: 2.4rem; display: block; margin-bottom: 8px; }
.score-pill { font-weight: 800; font-size: .85rem; padding: 4px 10px; border-radius: 99px; background: var(--ok-soft); color: #047857; white-space: nowrap; }
.score-pill.mid { background: #fef3c7; color: #92400e; }
.score-pill.low { background: var(--bad-soft); color: #b91c1c; }

/* ----- Onglets ----- */
.tabs { display: flex; gap: 6px; padding: 5px; background: #e9ecf5; border-radius: 14px; width: fit-content; max-width: 100%; overflow-x: auto; scrollbar-width: none; margin-bottom: 20px; }
.tabs a, .tabs button { padding: 9px 16px; border-radius: 10px; border: 0; background: none; font: inherit; font-weight: 700; font-size: .88rem; color: var(--ink-2); cursor: pointer; white-space: nowrap; }
.tabs .active { background: #fff; color: var(--brand); box-shadow: 0 2px 6px rgba(15, 23, 42, .08); }
.tab-panel[hidden] { display: none; }

/* ----- Fenêtre modale ----- */
dialog { border: 0; border-radius: 22px; padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: var(--shadow-lg); color: var(--ink); }
dialog::backdrop { background: rgba(15, 23, 42, .5); backdrop-filter: blur(3px); }
.dialog-body { padding: 26px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ----- Ressources ----- */
.media-grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); }
.media { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.media video { width: 100%; aspect-ratio: 16 / 9; background: #0f172a; }
.media img { width: 100%; max-height: 420px; object-fit: contain; background: #f1f5f9; }
.media-cap { padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; gap: 10px; font-weight: 600; font-size: .9rem; }

/* ----- Activités (cartes de jeu) ----- */
.game-card { position: relative; display: flex; flex-direction: column; gap: 8px; padding: 20px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); color: inherit; transition: transform .18s, box-shadow .18s; }
a.game-card:hover { transform: translateY(-4px) rotate(-.4deg); box-shadow: var(--shadow-lg); }
.game-emoji { width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center; font-size: 1.7rem; background: var(--brand-soft); }
.game-card p { color: var(--muted); font-size: .84rem; }
.game-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: .8rem; font-weight: 700; color: var(--brand); }
.stars { color: #f59e0b; letter-spacing: 2px; }
.stars i { color: #d7dcea; font-style: normal; }

/* ----- Générateur IA ----- */
.ai-box { border-radius: var(--radius); padding: 22px; background: linear-gradient(135deg, #312e81, #6d28d9 60%, #be185d); color: #fff; box-shadow: 0 24px 40px -24px #6d28d9; }
.ai-box h2 { display: flex; align-items: center; gap: 8px; }
.ai-box p { opacity: .85; font-size: .88rem; margin: 6px 0 16px; }
.ai-box label { color: rgba(255, 255, 255, .85); }
.ai-box select { border-color: transparent; }
.type-picker { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 14px; }
.type-picker label { margin: 0; cursor: pointer; }
.type-picker input { position: absolute; opacity: 0; }
.type-picker span { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 12px; background: rgba(255, 255, 255, .12); border: 1.5px solid transparent; font-size: .84rem; font-weight: 700; color: #fff; transition: background .15s; }
.type-picker input:checked + span { background: #fff; color: #4c1d95; }
.type-picker input:focus-visible + span { border-color: #fff; }
.ai-status { margin-top: 12px; font-size: .86rem; font-weight: 600; min-height: 1.3em; }
.spinner { width: 16px; height: 16px; border: 2.5px solid rgba(255, 255, 255, .4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
.btn-white .spinner { border-color: rgba(76, 29, 149, .25); border-top-color: #4c1d95; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ----- Badges, classement ----- */
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.badge { text-align: center; padding: 14px 8px; border-radius: 16px; background: var(--brand-soft); }
.badge .b-emoji { font-size: 1.8rem; display: block; }
.badge strong { display: block; font-size: .78rem; margin-top: 4px; }
.badge small { font-size: .68rem; color: var(--muted); line-height: 1.3; display: block; }
.badge.locked { background: #f1f5f9; }
.badge.locked .b-emoji { filter: grayscale(1); opacity: .4; }
.badge.locked strong { color: var(--muted); }
.rank { width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; font-size: .85rem; background: #f1f5f9; color: var(--ink-2); flex: none; }
.rank-1 { background: #fef3c7; color: #b45309; }
.rank-2 { background: #e2e8f0; color: #475569; }
.rank-3 { background: #ffedd5; color: #c2410c; }
.item.is-me { background: var(--brand-soft); margin: 0 -12px; padding-left: 12px; padding-right: 12px; border-radius: 12px; border-bottom-color: transparent; }
.code-box { font-family: ui-monospace, Consolas, monospace; font-size: 1.5rem; font-weight: 800; letter-spacing: .25em; padding: 12px 18px; border-radius: 14px; background: var(--brand-soft); color: var(--brand); text-align: center; border: 1.5px dashed color-mix(in srgb, var(--brand) 40%, transparent); }
.bar-row { display: grid; grid-template-columns: 130px 1fr 44px; gap: 12px; align-items: center; font-size: .86rem; font-weight: 600; margin-bottom: 12px; }
.bar-row:last-child { margin-bottom: 0; }

/* ==========================================================================
   Lecteur de jeux
   ========================================================================== */
.player { max-width: 760px; margin: 0 auto; }
.player-top { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.player-top .progress { flex: 1; height: 12px; }
.player-count { font-weight: 800; font-size: .9rem; color: var(--muted); white-space: nowrap; }
.stage { background: var(--card); border: 1px solid var(--line); border-radius: 26px; padding: clamp(20px, 4vw, 38px); box-shadow: var(--shadow-lg); }
.stage-enter { animation: pop .35s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.98); } }
.q-kicker { font-size: .76rem; font-weight: 800; text-transform: uppercase; letter-spacing: .1em; color: var(--brand); margin-bottom: 10px; }
.q-text { font-size: clamp(1.15rem, 2.6vw, 1.5rem); font-weight: 800; letter-spacing: -.02em; margin-bottom: 24px; line-height: 1.35; }
.opts { display: grid; gap: 12px; }
.opts.two { grid-template-columns: 1fr 1fr; }
.opt {
  display: flex; align-items: center; gap: 14px; text-align: left; width: 100%; padding: 15px 18px; border-radius: 16px;
  border: 2px solid var(--line); background: #fff; font: inherit; font-weight: 600; font-size: 1rem; color: var(--ink); cursor: pointer;
  transition: transform .12s, border-color .15s, background .15s;
}
.opt:hover:not([disabled]) { border-color: var(--brand); transform: translateY(-2px); }
.opt[disabled] { cursor: default; }
.opt-key { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); font-weight: 800; font-size: .85rem; flex: none; }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.right .opt-key { background: var(--ok); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); animation: shake .35s; }
.opt.wrong .opt-key { background: var(--bad); color: #fff; }
.opt.big { justify-content: center; font-size: 1.15rem; font-weight: 800; padding: 22px; }
@keyframes shake { 25% { transform: translateX(-6px); } 50% { transform: translateX(6px); } 75% { transform: translateX(-3px); } }
.feedback { margin-top: 18px; padding: 14px 16px; border-radius: 14px; font-size: .93rem; background: var(--ok-soft); color: #065f46; }
.feedback.ko { background: var(--bad-soft); color: #991b1b; }
.feedback strong { display: block; margin-bottom: 2px; }
.next-row { display: flex; justify-content: flex-end; margin-top: 18px; }
.timer { height: 8px; border-radius: 99px; background: #e9ecf5; overflow: hidden; margin-bottom: 22px; }
.timer span { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #f59e0b, #ef4444); transform-origin: left; }
.combo { display: inline-flex; align-items: center; gap: 6px; font-weight: 800; color: #ea580c; font-size: .9rem; min-height: 1.4em; }

.blank { display: inline-block; min-width: 90px; padding: 0 12px; border-bottom: 3px dashed var(--brand); color: var(--brand); text-align: center; }
.blank.right { border-bottom-style: solid; border-color: var(--ok); color: #047857; }
.blank.wrong { border-bottom-style: solid; border-color: var(--bad); color: #b91c1c; }
.chips-row { display: flex; flex-wrap: wrap; gap: 10px; }
.chips-row .opt { width: auto; padding: 12px 20px; }

.mem-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.mem-card { aspect-ratio: 1 / 1; perspective: 800px; border: 0; background: none; padding: 0; cursor: pointer; font: inherit; }
.mem-inner { position: relative; width: 100%; height: 100%; transition: transform .45s cubic-bezier(.3, .8, .3, 1.1); transform-style: preserve-3d; }
.mem-card.open .mem-inner, .mem-card.done .mem-inner { transform: rotateY(180deg); }
.mem-face { position: absolute; inset: 0; border-radius: 16px; display: grid; place-items: center; backface-visibility: hidden; padding: 8px; text-align: center; }
.mem-back { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; font-size: 1.6rem; font-weight: 800; box-shadow: 0 10px 18px -10px var(--brand); }
.mem-front { background: #fff; border: 2px solid var(--line); transform: rotateY(180deg); font-weight: 700; font-size: clamp(.7rem, 1.9vw, .95rem); line-height: 1.25; overflow-wrap: anywhere; color: var(--ink); }
.mem-card.done .mem-front { border-color: var(--ok); background: var(--ok-soft); }
.mem-info { display: flex; justify-content: space-between; font-weight: 700; color: var(--muted); font-size: .88rem; margin-bottom: 16px; }

.result { text-align: center; }
.result-emoji { font-size: 4rem; line-height: 1; animation: pop .5s cubic-bezier(.2, .9, .3, 1.4); }
.result h2 { font-size: 1.7rem; font-weight: 800; margin: 12px 0 4px; }
.result .stars { font-size: 2.2rem; margin: 10px 0; }
.result-score { font-size: 3rem; font-weight: 800; letter-spacing: -.03em; background: linear-gradient(135deg, var(--brand), var(--brand-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.xp-gain { display: inline-flex; align-items: center; gap: 8px; margin: 14px 0 22px; padding: 9px 18px; border-radius: 99px; background: #fef3c7; color: #92400e; font-weight: 800; }
.result-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; }

/* ==========================================================================
   Pages publiques (accueil, connexion)
   ========================================================================== */
.public { background: radial-gradient(1000px 500px at 85% -10%, #ede9fe 0, transparent 60%), radial-gradient(800px 500px at -10% 20%, #dbeafe 0, transparent 60%), var(--bg); min-height: 100vh; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 22px clamp(16px, 5vw, 56px); }
.landing { max-width: 1140px; margin: 0 auto; padding: 32px clamp(16px, 5vw, 40px) 72px; }
.landing-hero { text-align: center; max-width: 780px; margin: 24px auto 48px; }
.landing-hero .chip { margin-bottom: 18px; font-size: .8rem; padding: 6px 14px; }
.landing-hero h1 { font-size: clamp(2.1rem, 5.4vw, 3.5rem); font-weight: 800; letter-spacing: -.035em; line-height: 1.08; }
.landing-hero h1 em { font-style: normal; background: linear-gradient(135deg, #4f46e5, #db2777); -webkit-background-clip: text; background-clip: text; color: transparent; }
.landing-hero p { color: var(--ink-2); font-size: 1.1rem; margin-top: 18px; }
.apps { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 22px; }
.app-card { position: relative; overflow: hidden; display: flex; flex-direction: column; gap: 12px; padding: 28px; border-radius: 26px; color: #fff; background: linear-gradient(145deg, var(--brand), var(--brand-2)); box-shadow: 0 30px 50px -28px var(--brand); transition: transform .2s; min-height: 300px; }
.app-card:hover { transform: translateY(-6px); }
.app-card::after { content: ""; position: absolute; width: 220px; height: 220px; border-radius: 50%; background: rgba(255, 255, 255, .12); right: -70px; top: -80px; }
.app-card > * { position: relative; z-index: 1; }
.app-emoji { width: 62px; height: 62px; border-radius: 20px; background: rgba(255, 255, 255, .2); display: grid; place-items: center; font-size: 2rem; }
.app-card h2 { font-size: 1.4rem; font-weight: 800; }
.app-card p { opacity: .92; font-size: .95rem; }
.app-card ul { margin: 0; padding: 0; list-style: none; font-size: .88rem; display: flex; flex-direction: column; gap: 6px; opacity: .95; }
.app-card li::before { content: "✓  "; font-weight: 800; }
.app-card .btn { margin-top: auto; align-self: flex-start; }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 18px; margin-top: 56px; }
.feature { padding: 22px; border-radius: 20px; background: rgba(255, 255, 255, .8); border: 1px solid var(--line); }
.feature span { font-size: 1.7rem; }
.feature h3 { margin: 10px 0 4px; }
.feature p { color: var(--muted); font-size: .88rem; }

.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); }
.auth-side { position: relative; overflow: hidden; padding: 48px; color: #fff; display: flex; flex-direction: column; justify-content: space-between; background: linear-gradient(150deg, var(--brand), var(--brand-2)); }
.auth-side::before { content: ""; position: absolute; width: 420px; height: 420px; border-radius: 50%; background: rgba(255, 255, 255, .1); right: -140px; bottom: -140px; }
.auth-side .logo { color: #fff; }
.auth-side .logo-mark { background: rgba(255, 255, 255, .22); box-shadow: none; }
.auth-side h1 { font-size: clamp(1.8rem, 3.4vw, 2.6rem); max-width: 14ch; position: relative; }
.auth-side p { opacity: .9; margin-top: 14px; max-width: 40ch; position: relative; }
.auth-main { display: grid; place-items: center; padding: 32px 20px; background: #fff; }
.auth-form { width: min(420px, 100%); }
.auth-form h2 { font-size: 1.6rem; font-weight: 800; margin-bottom: 6px; }
.auth-form > p { color: var(--muted); margin-bottom: 24px; }
.role-switch { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 5px; background: #eef0f6; border-radius: 14px; margin-bottom: 24px; }
.role-switch a { text-align: center; padding: 9px 6px; border-radius: 10px; font-weight: 700; font-size: .86rem; color: var(--ink-2); }
.role-switch a.active { background: #fff; color: var(--brand); box-shadow: 0 2px 6px rgba(15, 23, 42, .08); }
.auth-alt { text-align: center; margin-top: 20px; font-size: .9rem; color: var(--muted); }
.auth-alt a { font-weight: 700; }

/* ==========================================================================
   Mobile
   ========================================================================== */
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; z-index: 30; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); box-shadow: 0 -8px 24px -16px rgba(15, 23, 42, .3); }
  .sidebar .brand, .sidebar .role-pill, .sidebar .me { display: none; }
  .nav { flex-direction: row; justify-content: space-around; gap: 2px; }
  .nav a { flex: 1; flex-direction: column; gap: 3px; padding: 7px 4px; font-size: .66rem; text-align: center; min-width: 0; }
  .nav a span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .nav .nav-logout { margin-top: 0; }
  .main { padding: 20px 16px 104px; }
  .split { grid-template-columns: minmax(0, 1fr); }
  h1 { font-size: 1.45rem; }
  .auth { grid-template-columns: 1fr; }
  .auth-side { padding: 28px 24px; gap: 24px; }
  .auth-side h1 { max-width: none; }
  .hero { padding: 22px; }
  .mem-grid { gap: 8px; }
  .bar-row { grid-template-columns: 96px 1fr 40px; }
}
@media (max-width: 520px) {
  .mem-grid { grid-template-columns: repeat(3, 1fr); }
  .opts.two { grid-template-columns: 1fr; }
  .type-picker { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ==========================================================================
   Formules LaTeX (KaTeX)
   ========================================================================== */
.katex { font-size: 1.1em; }
.katex-display { margin: .7em 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.prose { white-space: pre-line; line-height: 1.75; overflow-wrap: anywhere; }
.math-tools { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.math-tools button { padding: 5px 10px; border-radius: 9px; border: 1px solid var(--line); background: #fff; font: inherit; font-size: .82rem; font-weight: 700; color: var(--ink-2); cursor: pointer; transition: border-color .15s, color .15s; }
.math-tools button:hover { border-color: var(--brand); color: var(--brand); }
.math-preview { position: relative; margin-top: 10px; padding: 22px 16px 14px; border-radius: 12px; background: var(--brand-soft); border: 1px dashed color-mix(in srgb, var(--brand) 35%, transparent); font-size: .93rem; }
.math-preview[hidden] { display: none; }
.math-preview-tag { position: absolute; top: 6px; left: 12px; font-size: .66rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--brand); }
.hint code, .card code { background: #eef0f6; padding: 1px 6px; border-radius: 6px; font-size: .92em; }
.mem-front .katex { font-size: 1em; }
.prose .katex-display { margin: .2em 0 -.4em; }
