/* Pige-moi ça — charte « Clair moderne » */
:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --soft: #f1f5f9;
  --ink: #0f172a;
  --ink-2: #475569;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-2: #cbd5e1;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-ink: #4338ca;
  --on-accent: #ffffff;
  --good: #059669;
  --good-bg: #ecfdf5;
  --bad: #e11d48;
  --bad-bg: #fff1f2;
  --remember: #fffbeb;
  --remember-ink: #92400e;

  --monde: #e11d48;    --monde-bg: #fff1f2;
  --eco: #059669;      --eco-bg: #ecfdf5;
  --tech: #d97706;     --tech-bg: #fffbeb;
  --sciences: #0284c7; --sciences-bg: #f0f9ff;
  --culture: #7c3aed;  --culture-bg: #f5f3ff;

  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .04);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .08), 0 2px 6px rgba(15, 23, 42, .04);
  --radius: 14px;
  --radius-sm: 10px;
  --title: 'Inter Tight', 'Inter', system-ui, sans-serif;
  --sans: 'Inter', system-ui, -apple-system, sans-serif;
  --chat-w: 400px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f19;
    --card: #111827;
    --soft: #1a2232;
    --ink: #f1f5f9;
    --ink-2: #cbd5e1;
    --muted: #94a3b8;
    --line: #1f2937;
    --line-2: #334155;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-soft: rgba(99, 102, 241, .16);
    --accent-ink: #a5b4fc;
    --good: #34d399;
    --good-bg: rgba(16, 185, 129, .14);
    --bad: #fb7185;
    --bad-bg: rgba(244, 63, 94, .14);
    --remember: rgba(245, 158, 11, .12);
    --remember-ink: #fcd34d;

    --monde: #fb7185;    --monde-bg: rgba(244, 63, 94, .14);
    --eco: #34d399;      --eco-bg: rgba(16, 185, 129, .14);
    --tech: #fbbf24;     --tech-bg: rgba(245, 158, 11, .14);
    --sciences: #38bdf8; --sciences-bg: rgba(14, 165, 233, .14);
    --culture: #a78bfa;  --culture-bg: rgba(139, 92, 246, .16);

    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
code { font-size: .88em; background: var(--soft); padding: 2px 6px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------- En-tête ---------- */
.masthead {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--card) 85%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.masthead-inner {
  max-width: 1400px; margin: 0 auto;
  display: flex; align-items: center; gap: 20px;
  padding: 12px 24px;
}
.brand h1 {
  margin: 0; font-family: var(--title); font-weight: 700;
  font-size: 19px; letter-spacing: -.02em; line-height: 1;
  display: flex; align-items: center; gap: 9px;
}
.logo {
  display: grid; place-items: center; width: 28px; height: 28px;
  border-radius: 8px; background: var(--accent); color: var(--on-accent);
  font-size: 15px; font-weight: 700;
}
.dateline { margin: 3px 0 0 37px; font-size: 12px; color: var(--muted); }
.dateline::first-letter { text-transform: uppercase; }
.tabs {
  display: flex; gap: 2px; margin-left: auto;
  background: var(--soft); padding: 4px; border-radius: 999px;
}
.tab {
  background: none; border: 0; padding: 6px 14px; border-radius: 999px;
  color: var(--ink-2); font-weight: 500; font-size: 14px; transition: background .15s, color .15s;
}
.tab:hover { color: var(--ink); }
.tab.active { background: var(--card); color: var(--accent-ink); box-shadow: var(--shadow); }
.chat-toggle {
  display: flex; align-items: center; gap: 8px;
  background: var(--accent); color: var(--on-accent); border: 0;
  padding: 8px 16px; border-radius: 999px; font-weight: 500; font-size: 14px;
  transition: background .15s;
}
.chat-toggle:hover { background: var(--accent-hover); }
body.chat-open .chat-toggle { background: var(--accent-soft); color: var(--accent-ink); }

/* ---------- Mise en page ---------- */
.layout { max-width: 1400px; margin: 0 auto; display: flex; align-items: flex-start; }
main { flex: 1; min-width: 0; padding: 32px 24px 96px; }
.view { max-width: 920px; margin: 0 auto; }
#view-today, #view-search { max-width: 1180px; container-type: inline-size; }
#view-today { max-width: 1360px; }

.view-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 16px; flex-wrap: wrap; margin-bottom: 24px;
}
.view-head h2 {
  margin: 0; font-family: var(--title); font-weight: 700;
  font-size: 32px; line-height: 1.15; letter-spacing: -.025em;
}
.view-head h2::first-letter { text-transform: uppercase; }
.kicker { margin: 0 0 6px; font-size: 13px; font-weight: 500; color: var(--accent-ink); }
.view-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 8px 16px; border-radius: var(--radius-sm); font-weight: 500; font-size: 14px;
  box-shadow: var(--shadow); transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--line-2); background: var(--soft); }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.btn.primary:hover { background: var(--accent-hover); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.small { padding: 5px 12px; font-size: 13px; border-radius: 8px; }
.icon-btn {
  display: grid; place-items: center; width: 34px; height: 34px;
  border: 0; background: none; border-radius: 10px; color: var(--muted);
}
.icon-btn:hover { background: var(--soft); color: var(--ink); }
.link-btn { border: 0; background: none; padding: 0; color: var(--accent-ink); font-size: 13px; font-weight: 500; }
.link-btn:hover { text-decoration: underline; }

.banner {
  max-width: 920px; margin: 0 auto 24px;
  background: var(--remember); color: var(--remember-ink); border-radius: var(--radius);
  padding: 14px 18px; font-size: 14px;
}

/* ---------- Catégories et infos ---------- */
.category { margin-bottom: 48px; scroll-margin-top: 96px; }
.category-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 14px;
}
.category-head h3 { margin: 0; font-size: inherit; }
.cat-badge {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--cb); color: var(--c);
  font-family: var(--title); font-weight: 700; font-size: 17px; letter-spacing: -.01em;
  padding: 6px 14px; border-radius: 999px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex-shrink: 0; }
.category-head .meta { display: flex; align-items: center; gap: 12px; }

.items { display: grid; gap: 14px; }
.item {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px; box-shadow: var(--shadow); scroll-margin-top: 96px;
  transition: border-color .15s, box-shadow .15s;
}
.item:hover { border-color: var(--line-2); box-shadow: var(--shadow-lg); }
.item h4 {
  margin: 0 0 8px; font-family: var(--title); font-size: 18px; line-height: 1.35;
  font-weight: 700; letter-spacing: -.01em;
}
.item p { margin: 0 0 10px; color: var(--ink-2); }
.item .why { color: var(--ink); }
.item .why strong { display: block; font-size: 12.5px; font-weight: 600; color: var(--c); margin-bottom: 2px; }
.item details { margin: 6px 0 10px; }
.item summary {
  cursor: pointer; font-size: 13.5px; font-weight: 500; color: var(--accent-ink);
  list-style: none; display: inline-flex; align-items: center; gap: 6px;
}
.item summary::-webkit-details-marker { display: none; }
.item summary::before { content: '+'; font-weight: 600; width: 12px; }
.item details[open] summary::before { content: '–'; }
.item details p { margin-top: 8px; padding-left: 18px; }
.remember {
  background: var(--remember); color: var(--remember-ink); border-radius: var(--radius-sm);
  padding: 10px 14px; font-size: 14px; margin: 12px 0;
}
.remember strong { margin-right: 6px; }
.item-foot {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line);
}
.sources { display: flex; gap: 6px; flex-wrap: wrap; font-size: 12px; }
.sources a {
  color: var(--muted); text-decoration: none; background: var(--soft);
  padding: 3px 10px; border-radius: 999px; max-width: 240px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sources a:hover { color: var(--accent-ink); background: var(--accent-soft); }
.item-actions { display: flex; gap: 6px; }
.item-actions .btn:first-child { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; box-shadow: none; }
.item-actions .btn:first-child:hover { background: var(--accent); color: var(--on-accent); }

.loading {
  display: flex; align-items: center; gap: 12px;
  padding: 22px; background: var(--card); border: 1px dashed var(--line-2);
  border-radius: var(--radius); color: var(--muted); font-size: 14px;
}
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-box {
  padding: 14px 18px; background: var(--bad-bg); border-radius: var(--radius); color: var(--bad);
  display: flex; justify-content: space-between; gap: 12px; align-items: center; font-size: 14px;
}

/* ---------- Recherche ---------- */
.search-form {
  display: flex; gap: 8px; margin-bottom: 14px; padding: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
}
.search-form:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.search-form input {
  flex: 1; min-width: 0; padding: 10px 12px; font: inherit; font-size: 16px;
  border: 0; background: none; color: var(--ink); outline: none;
}
.search-form .btn { box-shadow: none; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 28px; }
.chip {
  border: 1px solid var(--line); background: var(--card); padding: 6px 13px; border-radius: 999px;
  font-size: 13px; color: var(--ink-2); transition: all .15s;
}
.chip:hover { border-color: transparent; background: var(--accent-soft); color: var(--accent-ink); }

.dossier {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 32px 36px; box-shadow: var(--shadow);
}
.dossier h2 { font-family: var(--title); font-size: 30px; font-weight: 700; letter-spacing: -.025em; margin: 0 0 14px; line-height: 1.2; }
.dossier .chapeau { font-size: 17px; color: var(--ink); background: var(--soft); border-radius: var(--radius-sm); padding: 14px 18px; margin: 0 0 24px; }
.dossier h3 { font-family: var(--title); font-size: 20px; font-weight: 700; letter-spacing: -.01em; margin: 30px 0 8px; scroll-margin-top: 96px; }
.dossier .prose p { margin: 0 0 10px; color: var(--ink-2); }
.dossier .prose ul { margin: 0 0 10px; padding-left: 20px; color: var(--ink-2); }
.dossier .box { background: var(--remember); color: var(--remember-ink); border-radius: var(--radius); padding: 16px 20px; margin-top: 28px; scroll-margin-top: 96px; }
.dossier .box h3 { margin-top: 0; font-size: 17px; color: inherit; }
.dossier .box ul { margin: 0; padding-left: 20px; }
.dossier .dossier-actions, .dossier-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 28px; }
.dossier .sources { margin-top: 8px; }
#sec-sources { scroll-margin-top: 96px; }

/* ---------- Historique ---------- */
.history-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.history-col {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.history-col h3 { font-family: var(--title); font-size: 16px; font-weight: 700; margin: 0 0 10px; }
.history-list { list-style: none; margin: 0; padding: 0; }
.history-list button {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 9px 10px; border-radius: var(--radius-sm); font-size: 14px;
}
.history-list button:hover { background: var(--soft); }
.history-list button:first-letter { text-transform: uppercase; }
.history-list .sub { display: block; font-size: 12px; color: var(--muted); }
.history-list .score { display: flex; justify-content: space-between; align-items: center; padding: 9px 10px; font-size: 14px; }
.history-list .score strong { background: var(--accent-soft); color: var(--accent-ink); padding: 2px 10px; border-radius: 999px; font-size: 13px; }
.empty-note { color: var(--muted); font-size: 14px; padding: 9px 10px; }

/* ---------- Sommaire ---------- */
.toc-content { min-width: 0; }
.toc {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  margin-bottom: 20px; font-size: 13.5px; box-shadow: var(--shadow);
}
.toc > summary {
  list-style: none; cursor: pointer; padding: 12px 16px;
  font-size: 13px; font-weight: 600; color: var(--ink);
  display: flex; justify-content: space-between; align-items: center;
}
.toc > summary::-webkit-details-marker { display: none; }
.toc > summary::after { content: '▾'; font-size: 12px; color: var(--muted); transition: transform .2s; }
.toc[open] > summary::after { transform: rotate(180deg); }
.toc-list, .toc-list ol { list-style: none; margin: 0; padding: 0; }
.toc-list { padding: 0 8px 10px; max-height: 60vh; overflow-y: auto; }
.toc-group + .toc-group { margin-top: 4px; }
.toc-link {
  display: block; padding: 5px 10px; border-radius: 8px; text-decoration: none;
  color: var(--muted); line-height: 1.4; transition: background .12s, color .12s;
}
.toc-link:hover { background: var(--soft); color: var(--ink); }
.toc-top { font-weight: 600; color: var(--ink); display: flex; align-items: center; gap: 8px; }
.toc-note {
  margin-left: auto; min-width: 22px; text-align: center; font-size: 11.5px; font-weight: 600;
  color: var(--muted); background: var(--soft); border-radius: 999px; padding: 1px 7px;
}
.toc-group ol { display: none; }
.toc-group.expanded ol { display: block; animation: tocIn .2s ease; }
.toc-group.expanded .toc-note { visibility: hidden; }
@keyframes tocIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.toc-group ol .toc-link { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.toc-group ol { margin: 2px 0 6px 14px; padding-left: 8px; border-left: 1px solid var(--line); }
.toc-group ol .toc-link { font-size: 13px; }
.toc-link.active { color: var(--c, var(--accent-ink)); background: var(--cb, var(--accent-soft)); font-weight: 500; }
.toc-foot { border-top: 1px solid var(--line); padding: 10px 16px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }

@media (max-width: 900px) {
  .toc { position: sticky; top: calc(var(--mast-h, 110px) + 8px); z-index: 10; box-shadow: var(--shadow-lg); }
}

@container (min-width: 760px) {
  .with-toc { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 32px; align-items: start; }
  .toc {
    position: sticky; top: calc(var(--mast-h, 64px) + 24px); margin: 0;
    background: transparent; border: 0; box-shadow: none;
  }
  .toc > summary { pointer-events: none; padding: 4px 10px 10px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
  .toc > summary::after { display: none; }
  .toc-list {
    padding: 0 4px 0 0;
    max-height: calc(100vh - var(--mast-h, 64px) - 150px);
    overflow-y: auto; overscroll-behavior: contain;
    scrollbar-width: thin; scrollbar-color: var(--line-2) transparent;
  }
  .toc-foot { padding: 12px 10px; }
}

/* Colonne de droite : sous-menu de la rubrique en cours (grand écran uniquement) */
.toc-sub { display: none; }
.toc-sub-kicker { margin: 4px 0 8px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.toc-sub-title {
  display: inline-flex; align-items: center; gap: 8px; margin: 0 0 12px;
  background: var(--cb, var(--accent-soft)); color: var(--c, var(--accent-ink));
  font-family: var(--title); font-weight: 700; font-size: 14px; padding: 5px 12px; border-radius: 999px;
}
.toc-sub-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.toc-sub-list .toc-link { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; font-size: 13px; }
.toc-sub-list .num {
  flex-shrink: 0; width: 20px; height: 20px; border-radius: 6px; display: grid; place-items: center;
  background: var(--soft); color: var(--muted); font-size: 11px; font-weight: 600; margin-top: 1px;
}
.toc-sub-list .toc-link.active .num { background: var(--c, var(--accent)); color: #fff; }
.toc-sub-empty { font-size: 13px; color: var(--muted); }

@container (min-width: 940px) {
  .with-toc.has-sub { grid-template-columns: 200px minmax(0, 1fr) 230px; gap: 24px; }
  .has-sub .toc-sub {
    display: block; position: sticky; top: calc(var(--mast-h, 64px) + 24px);
    max-height: calc(100vh - var(--mast-h, 64px) - 48px); overflow-y: auto;
    scrollbar-width: thin; scrollbar-color: var(--line-2) transparent;
  }
  .has-sub .toc-group.expanded ol { display: none; }
  .has-sub .toc-group.expanded .toc-note { visibility: visible; }
  .has-sub .toc-group .toc-top { padding: 8px 10px; }
  .has-sub .toc-group.expanded .toc-top { background: var(--cb); color: var(--c); }
}

/* ---------- Réduire / déplier ---------- */
.view-actions { align-items: center; }
.seg {
  display: inline-flex; align-items: center; gap: 2px; padding: 3px;
  background: var(--soft); border-radius: 12px;
}
.seg button {
  border: 0; background: none; padding: 6px 12px; border-radius: 9px;
  font-size: 13px; font-weight: 500; color: var(--ink-2);
}
.seg button:hover { color: var(--ink); }
.seg button.active { background: var(--card); color: var(--accent-ink); box-shadow: var(--shadow); }
.seg-label { font-size: 12px; color: var(--muted); min-width: 42px; text-align: center; font-variant-numeric: tabular-nums; }

.item-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  width: 100%; border: 0; background: none; padding: 0; text-align: left; color: inherit;
}
.item-head h4 { margin-bottom: 6px; }
.chev { flex-shrink: 0; color: var(--muted); transition: transform .2s; margin-top: 2px; }
.item.open .item-head .chev { transform: rotate(180deg); }
.item-head:hover .chev { color: var(--accent-ink); }
.item .resume { margin-bottom: 0; }
.item:not(.open) { padding: 16px 20px; cursor: pointer; }
.item:not(.open) .resume {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  font-size: 14px;
}
.item:not(.open) .item-more { display: none; }
.item.open .resume { margin-bottom: 10px; }
.items { gap: 10px; }

.cat-fold { border: 0; background: none; padding: 0; }
.cat-fold .chev { color: currentColor; opacity: .7; margin: 0 -4px 0 2px; }
.category.folded .cat-fold .chev { transform: rotate(-90deg); }
.category.folded .items, .category.folded .loading, .category.folded .error-box { display: none; }
.category.folded { margin-bottom: 20px; }

/* ---------- Chat ---------- */
.chat {
  position: sticky; top: var(--mast-h, 64px);
  width: var(--chat-w); height: calc(100vh - var(--mast-h, 64px));
  border-left: 1px solid var(--line); background: var(--card);
  display: none; flex-direction: column;
}
body.chat-open .chat { display: flex; }
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.chat-head strong { font-family: var(--title); font-size: 16px; display: block; }
.chat-head-actions { display: flex; gap: 2px; }
.chat-context {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  margin: 10px 12px 0; padding: 8px 12px; font-size: 12.5px;
  background: var(--accent-soft); color: var(--accent-ink); border-radius: var(--radius-sm);
}
.chat-context span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.chat-empty { color: var(--ink-2); font-size: 14px; margin: auto 0; text-align: center; padding: 0 12px; }
.msg { max-width: 100%; font-size: 14.5px; }
.msg.user {
  align-self: flex-end; background: var(--accent); color: var(--on-accent);
  padding: 9px 14px; border-radius: 16px 16px 4px 16px; max-width: 88%; white-space: pre-wrap;
}
.msg.assistant { color: var(--ink); }
.msg.assistant .md p { margin: 0 0 8px; }
.msg.assistant .md ul, .msg.assistant .md ol { margin: 0 0 8px; padding-left: 20px; }
.msg.assistant .md h4 { font-family: var(--title); margin: 12px 0 4px; font-size: 15px; }
.msg.assistant .md a { color: var(--accent-ink); }
.msg .status { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.msg .status .spinner { width: 12px; height: 12px; }
.msg .sources { margin-top: 8px; }
.msg.error { color: var(--bad); font-size: 13.5px; }
.chat-form {
  display: flex; gap: 8px; margin: 12px; padding: 6px; align-items: flex-end;
  border: 1px solid var(--line); border-radius: 14px; background: var(--bg);
}
.chat-form:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.chat-form textarea {
  flex: 1; resize: none; max-height: 140px; padding: 8px 10px; font: inherit; font-size: 14.5px;
  border: 0; background: none; color: var(--ink); outline: none;
}
.chat-form .btn { box-shadow: none; }

/* ---------- Quiz ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50; background: rgba(15, 23, 42, .5);
  backdrop-filter: blur(4px); display: grid; place-items: center; padding: 16px;
}
.modal-card {
  background: var(--card); width: min(620px, 100%); max-height: calc(100vh - 32px); overflow-y: auto;
  border-radius: 20px; padding: 26px 28px; box-shadow: var(--shadow-lg);
}
.modal-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.modal-head h3 { margin: 0; font-family: var(--title); font-size: 19px; font-weight: 700; }
.quiz-progress { height: 6px; background: var(--soft); border-radius: 999px; margin-bottom: 18px; overflow: hidden; }
.quiz-progress div { height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s; }
.quiz-q { font-family: var(--title); font-weight: 700; font-size: 19px; line-height: 1.4; margin: 6px 0 18px; }
.quiz-options { display: grid; gap: 8px; }
.quiz-opt {
  text-align: left; border: 1px solid var(--line); background: var(--card);
  padding: 12px 16px; border-radius: 12px; font-size: 15px; transition: all .12s;
}
.quiz-opt:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.quiz-opt.correct { border-color: var(--good); background: var(--good-bg); color: var(--good); font-weight: 500; }
.quiz-opt.wrong { border-color: var(--bad); background: var(--bad-bg); color: var(--bad); }
.quiz-opt:disabled { cursor: default; }
.quiz-expl { margin-top: 14px; padding: 12px 16px; background: var(--soft); border-radius: 12px; font-size: 14px; }
.quiz-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; }
.quiz-score { text-align: center; padding: 10px 0; }
.quiz-score .big { font-family: var(--title); font-weight: 700; font-size: 56px; line-height: 1; margin: 8px 0; color: var(--accent); }
.quiz-score .dossier-actions { justify-content: center; }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .masthead-inner { flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .tabs { order: 3; width: 100%; margin: 0; justify-content: space-between; }
  .tab { flex: 1; }
  .chat-toggle { margin-left: auto; }
  main { padding: 22px 16px 96px; }
  .view-head h2 { font-size: 26px; }
  .item { padding: 18px; }
  .item-actions { width: 100%; }
  .item-actions .btn { flex: 1; justify-content: center; }
  .chat { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 40; border: 0; }
  .dossier { padding: 22px 18px; }
}

.cat-badge { white-space: nowrap; }
@media (max-width: 520px) {
  .category-head .meta .muted { display: none; }
  .cat-badge { font-size: 16px; }
}

/* ---------- Rôles ---------- */
body[data-role="reader"] .needs-premium,
body:not([data-role="admin"]) .needs-admin,
body:not([data-role="reader"]) .reader-only,
body[data-role="reader"] .chat { display: none !important; }
body:not([data-role]) .needs-premium, body:not([data-role]) .needs-admin { display: none !important; }

.account { display: flex; align-items: center; gap: 4px; }
.role-chip {
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  font-size: 12.5px; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-ink);
}
.role-chip.admin { background: var(--remember); color: var(--remember-ink); }
.small-chip { font-size: 11px; padding: 1px 8px; margin-left: 4px; vertical-align: 1px; }
.reader-hint { margin: 8px 0 0; font-size: 13.5px; color: var(--muted); }

/* Connexion */
.login-card { width: min(420px, 100%); display: grid; gap: 12px; }
.login-card .modal-head { margin-bottom: 0; }
.login-card p { margin: 0; }
.login-card input, .panel input, .panel select {
  width: 100%; padding: 11px 14px; font: inherit; font-size: 15px; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.login-card input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .06em; text-transform: uppercase; }
.login-card input:focus, .panel input:focus, .panel select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.form-error { color: var(--bad); font-size: 13.5px; }

/* Admin */
#view-admin { max-width: 1000px; }
.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); display: grid; gap: 12px;
}
.panel h3 { margin: 0; font-family: var(--title); font-size: 17px; font-weight: 700; }
.panel p { margin: 0; }
.panel label { display: grid; gap: 6px; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.new-code { background: var(--good-bg); border-radius: var(--radius-sm); padding: 12px 14px; display: grid; gap: 8px; }
.code-box { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.code-box code { font-size: 17px; font-weight: 600; letter-spacing: .06em; background: var(--card); padding: 6px 10px; }
.code-list { list-style: none; margin: 0; padding: 0; }
.code-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.code-list .sub { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-bg); border-color: transparent; }

@media (max-width: 900px) {
  .role-chip { max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
}
