/* Révisions — "Cahier Seyès" : encre bleu Waterman, marge rouge, papier crème, surligneur jaune */
:root {
  /* Thème unique : cahier bleu nuit (palette de l'accueil, étendue à toutes les pages) */
  --paper: #161b45;
  --paper-2: #1b2150;
  --card: #1e2558;
  --card-2: #252c63;
  --ink: #f1eee4;
  --ink-soft: #c3c8ec;
  --muted: #9aa0cc;
  --line: rgba(150, 165, 255, .05);
  --line-strong: rgba(150, 165, 255, .11);
  --line-ctrl: rgba(150, 165, 255, .22);
  --margin: #c2566a;
  --danger-solid: #b0445b;
  --margin-soft: rgba(194, 86, 106, .18);
  --accent: #f08a6a;
  --highlight: #d9c46a;
  --highlight-soft: rgba(196, 180, 110, .42);
  --juste: #4cc495;
  --juste-soft: rgba(76, 196, 149, .16);
  --partiel: #e8a73a;
  --partiel-soft: rgba(232, 167, 58, .17);
  --faux: #f07a70;
  --faux-soft: rgba(240, 122, 112, .16);
  --on-status: #161b45;
  --shadow: 0 10px 26px -16px rgba(0, 0, 0, .7);
  --shadow-lift: 0 18px 40px -18px rgba(0, 0, 0, .85);
  --radius: 14px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", "Noto Sans", sans-serif;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, ui-serif, serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --tab-h: 68px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background-color: var(--paper);
  /* Seyès : grands carreaux 8mm, lignes fines tous les 2mm */
  background-image:
    linear-gradient(var(--line-strong) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-strong) 1px, transparent 1px);
  background-size: 32px 32px, 32px 32px;
  background-attachment: fixed;
  overflow-x: hidden;
}
body::before { /* marge rouge */
  content: ""; position: fixed; top: 0; bottom: 0; left: 22px; width: 2px;
  background: var(--margin); opacity: .8; pointer-events: none; z-index: 0;
}
body::after { /* grain papier */
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 100; opacity: .05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
a { color: inherit; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--highlight); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- Shell ---------- */
.shell { position: relative; z-index: 1; min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px 6px 40px; max-width: 760px; width: 100%; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; min-height: 44px; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; box-shadow: var(--shadow); }
.brand-name { font-family: var(--font-display); font-size: 1.3rem; font-weight: 700; letter-spacing: -.01em; }
.brand-sub { display: block; font-size: .72rem; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; line-height: 1; }
.main { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 8px 18px calc(var(--tab-h) + 40px) 40px; }
.footer {
  max-width: 760px; margin: 0 auto; padding: 0 18px calc(var(--tab-h) + 24px) 40px;
  font-size: .78rem; color: var(--muted); display: flex; gap: 8px; align-items: flex-start;
}
.footer svg { flex: none; margin-top: 2px; }
.shell.no-tabs .main, .shell.no-tabs .footer { padding-bottom: 32px; }

/* Settings menu */
.menu { position: relative; }
.menu-btn {
  width: 44px; height: 44px; border-radius: 14px; border: 1px solid rgba(150,165,255,.16);
  background: var(--card-2); color: var(--ink); display: grid; place-items: center; cursor: pointer; box-shadow: var(--shadow);
}
.menu-pop {
  position: absolute; right: 0; top: 52px; min-width: 220px; z-index: 50;
  background: var(--card); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: var(--shadow-lift);
  padding: 6px; transform-origin: top right; animation: pop .18s var(--ease);
}
.menu-pop a, .menu-pop button {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 10px;
  text-decoration: none; border: 0; background: none; cursor: pointer; text-align: left;
}
.menu-pop a:hover, .menu-pop button:hover { background: var(--margin-soft); }
.menu-pop form { margin: 0; }
@keyframes pop { from { opacity: 0; transform: scale(.95) translateY(-4px); } to { opacity: 1; transform: none; } }

/* Tabbar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--paper-2);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid rgba(150,165,255,.1);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; font-size: .74rem; font-weight: 600; color: var(--muted); position: relative; min-height: 44px;
  transition: color .2s;
}
.tab svg { transition: transform .25s var(--ease); }
.tab[aria-current="page"] { color: var(--ink); }
.tab[aria-current="page"]::before {
  content: ""; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; border-radius: 0 0 3px 3px; background: var(--margin);
}
.tab[aria-current="page"] svg { transform: translateY(-1px) scale(1.08); }
.tab-add .tab-plus {
  width: 40px; height: 30px; border-radius: 10px; background: var(--ink); color: var(--paper); display: grid; place-items: center;
}
.tab-add[aria-current="page"]::before { display: none; }

@media (min-width: 960px) {
  :root { --tab-h: 0px; }
  .tabbar {
    top: 0; bottom: 0; right: auto; width: 96px; height: auto; grid-template-columns: 1fr; grid-auto-rows: 76px;
    align-content: center; border-top: 0; border-right: 1px solid rgba(150,165,255,.1);
  }
  .tab[aria-current="page"]::before { top: 18px; bottom: 18px; left: 0; right: auto; width: 3px; height: auto; border-radius: 0 3px 3px 0; }
  .shell { padding-left: 96px; }
  body::before { left: 118px; }
  .topbar, .main, .footer { padding-left: 48px; }
  .main { padding-bottom: 48px; }
  .footer { padding-bottom: 32px; }
}

/* ---------- Typography ---------- */
.eyebrow { font-size: .74rem; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); font-weight: 700; margin: 0 0 6px; }
h1, h2, h3 { font-family: var(--font-display); letter-spacing: -.015em; line-height: 1.15; margin: 0; }
h1 { font-size: clamp(1.9rem, 7vw, 2.6rem); font-weight: 700; }
h2 { font-size: 1.3rem; font-weight: 700; }
h3 { font-size: 1.08rem; }
.lead { color: var(--ink-soft); margin: 8px 0 0; }
.page-head { margin: 10px 0 24px; animation: rise .5s var(--ease) both; }
.underline-mark { background: linear-gradient(transparent 62%, var(--highlight-soft) 62%, var(--highlight-soft) 92%, transparent 92%); padding: 0 2px; }
.section { margin-top: 32px; animation: rise .55s var(--ease) both; }
.section:nth-of-type(2) { animation-delay: .06s; } .section:nth-of-type(3) { animation-delay: .12s; } .section:nth-of-type(4) { animation-delay: .18s; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-head a { font-size: .88rem; font-weight: 600; color: var(--ink-soft); min-height: 44px; display: inline-flex; align-items: center; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 10px 18px;
  border-radius: 12px; border: 1.5px solid transparent; cursor: pointer; font-weight: 650; text-decoration: none;
  transition: transform .15s var(--ease), box-shadow .2s, background .2s, opacity .2s; -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px) scale(.985); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--ink); color: var(--paper); box-shadow: 0 3px 0 color-mix(in srgb, var(--ink) 60%, #000); }
.btn-primary:hover:not([disabled]) { box-shadow: 0 3px 0 color-mix(in srgb, var(--ink) 60%, #000), var(--shadow-lift); }
.btn-red { background: var(--danger-solid); color: #fff8f0; box-shadow: 0 3px 0 color-mix(in srgb, var(--danger-solid) 65%, #000); }
.btn-ghost { background: var(--card); border-color: var(--line-strong); color: var(--ink); }
.btn-ghost:hover { border-color: var(--ink-soft); background: var(--card-2); }
.btn-danger { background: transparent; border-color: color-mix(in srgb, var(--faux) 45%, transparent); color: var(--faux); }
.btn-danger:hover { background: var(--faux-soft); }
.btn-block { width: 100%; }
.btn-sm { min-height: 44px; padding: 8px 14px; font-size: .92rem; }
.btn.is-loading { pointer-events: none; }
.btn.is-loading::after { content: ""; width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
.link-btn { background: none; border: 0; padding: 10px 0; min-height: 44px; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-size: .88rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Cards ---------- */
.card { background: var(--card); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.paper-card { position: relative; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line-strong); padding: 20px 18px 20px 26px; overflow: hidden; }
.paper-card::before { content: ""; position: absolute; left: 12px; top: 0; bottom: 0; width: 1.5px; background: var(--margin); opacity: .5; }

/* Home */
.hero-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.big-action {
  position: relative; display: flex; flex-direction: column; justify-content: space-between; gap: 22px; min-height: 148px; padding: 18px;
  border-radius: 18px; text-decoration: none; overflow: hidden; box-shadow: var(--shadow); transition: transform .2s var(--ease), box-shadow .2s;
}
.big-action:hover { transform: translateY(-2px) rotate(-.3deg); box-shadow: var(--shadow-lift); }
.big-action:active { transform: scale(.98); }
.big-action strong { font-family: var(--font-display); font-size: 1.28rem; line-height: 1.1; }
.big-action small { display: block; font-size: .8rem; opacity: .8; margin-top: 4px; }
.big-action .ba-icon { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; background: rgba(255,255,255,.14); }
.big-action.ink { background: var(--ink); color: var(--paper); }
.big-action.ink::after { content: ""; position: absolute; inset: 0; background-image: linear-gradient(rgba(255,255,255,.07) 1px, transparent 1px); background-size: 100% 8px; pointer-events: none; }
.big-action.red { background: var(--danger-solid); color: #fffaf2; }
.big-action.red::after { content: ""; position: absolute; right: -30px; bottom: -30px; width: 120px; height: 120px; border-radius: 50%; border: 18px solid rgba(255,255,255,.12); }

.resume {
  display: flex; align-items: center; gap: 14px; margin-bottom: 18px; padding: 14px 14px 14px 16px; border-radius: var(--radius);
  background: var(--highlight-soft); border: 1.5px dashed color-mix(in srgb, var(--partiel) 60%, transparent); animation: rise .4s var(--ease) both;
}
.resume p { margin: 0; flex: 1; font-weight: 650; }
.resume small { display: block; font-weight: 400; color: var(--ink-soft); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; margin-top: 18px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line-strong); background: var(--card); }
.stat { padding: 12px 8px; text-align: center; border-right: 1px dashed var(--line-strong); }
.stat:last-child { border-right: 0; }
.stat b { display: block; font-family: var(--font-display); font-size: 1.45rem; line-height: 1.1; }
.stat span { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.row {
  display: flex; align-items: center; gap: 14px; min-height: 64px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--line-strong); text-decoration: none; box-shadow: var(--shadow);
  transition: transform .18s var(--ease), border-color .2s;
}
.row:hover { transform: translateX(3px); border-color: var(--ink-soft); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 650; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { font-size: .82rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.row-chevron { color: var(--muted); flex: none; }
.row-glyph { flex: none; width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; background: var(--margin-soft); color: var(--margin); font-family: var(--font-display); font-weight: 700; }
.score-chip { flex: none; min-width: 64px; text-align: center; font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; padding: 6px 10px; border-radius: 10px; background: var(--juste-soft); color: var(--juste); }
.score-chip.pending { background: var(--partiel-soft); color: var(--partiel); font-family: var(--font); font-size: .78rem; }
.score-chip.err { background: var(--faux-soft); color: var(--faux); font-family: var(--font); font-size: .78rem; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: .72rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; letter-spacing: .02em; white-space: nowrap; }
.badge-hist { background: var(--line-strong); color: var(--ink); }
.badge-ok { background: var(--juste-soft); color: var(--juste); }
.badge-wait { background: var(--partiel-soft); color: var(--partiel); }
.badge-err { background: var(--faux-soft); color: var(--faux); }

/* Empty states */
.empty { text-align: center; padding: 30px 20px; border: 1.5px dashed var(--line-strong); border-radius: var(--radius); background: color-mix(in srgb, var(--card) 70%, transparent); }
.empty svg.empty-art { margin: 0 auto 12px; color: var(--ink-soft); }
.empty h3 { margin-bottom: 6px; }
.empty p { color: var(--muted); margin: 0 auto 16px; max-width: 34ch; font-size: .94rem; }

/* Forms */
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field label, .label { font-weight: 650; font-size: .9rem; }
.input, .select, .textarea {
  width: 100%; min-height: 48px; padding: 11px 14px; border-radius: 12px; border: 1.5px solid var(--line-ctrl); background: var(--paper-2); color: var(--ink);
  transition: border-color .2s, box-shadow .2s;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 4px var(--highlight-soft); }
.input::placeholder, .textarea::placeholder { color: var(--muted); opacity: 1; }
.input:disabled, .select:disabled, .textarea:disabled { opacity: .55; cursor: not-allowed; }
select option, select optgroup { background: var(--paper-2); color: var(--ink); }
.textarea { min-height: 320px; font-family: var(--font-mono); font-size: .88rem; line-height: 1.6; resize: vertical; }
.hint { font-size: .84rem; color: var(--muted); margin: 0; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; gap: 4px; border-radius: 14px; background: var(--card); border: 1px solid var(--line-strong); }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label { min-height: 46px; display: flex; align-items: center; justify-content: center; gap: 8px; border-radius: 10px; font-weight: 650; cursor: pointer; transition: background .2s, color .2s; color: var(--ink-soft); }
.segmented input:checked + label { background: var(--ink); color: var(--paper); }
.segmented input:focus-visible + label { outline: 3px solid var(--highlight); }

.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--faux-soft); color: var(--faux); font-weight: 600; font-size: .92rem; margin-bottom: 16px; animation: shake .4s var(--ease); }
.alert svg { flex: none; margin-top: 2px; }
.notice { padding: 12px 14px; border-radius: 12px; background: var(--highlight-soft); font-size: .92rem; }
@keyframes shake { 0%,100% { transform: none; } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* Login */
.login-wrap { min-height: 82dvh; display: grid; place-items: center; }
.login-card { width: 100%; max-width: 400px; animation: rise .6s var(--ease) both; }
.login-title { font-size: clamp(2.6rem, 12vw, 3.4rem); margin-bottom: 4px; }
.login-title .accent { color: var(--margin); }
.login-formula { font-family: var(--font-display); font-style: italic; color: var(--ink-soft); font-size: 1.05rem; margin: 0 0 26px; transform: rotate(-1.5deg); display: inline-block; }

/* Upload */
.pick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pick { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 108px; border-radius: var(--radius); border: 1.5px dashed var(--ink-soft); background: var(--card); cursor: pointer; font-weight: 650; text-align: center; padding: 12px; transition: transform .15s var(--ease), background .2s; }
.pick:hover { background: var(--paper-2); }
.pick:active { transform: scale(.98); }
.pick input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.pick.is-disabled { opacity: .45; pointer-events: none; }
.thumbs { list-style: none; padding: 0; margin: 16px 0 0; display: grid; gap: 10px; }
.thumb { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line-strong); box-shadow: var(--shadow); animation: rise .3s var(--ease) both; }
.thumb img { width: 64px; height: 84px; object-fit: cover; border-radius: 8px; background: var(--paper-2); }
.thumb-n { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; }
.thumb-info { flex: 1; min-width: 0; font-size: .82rem; color: var(--muted); }
.thumb-actions { display: flex; gap: 4px; }
.icon-btn { width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--paper-2); display: grid; place-items: center; cursor: pointer; transition: background .15s; }
.icon-btn:hover:not([disabled]) { background: var(--margin-soft); }
.icon-btn[disabled] { opacity: .35; cursor: default; }
.icon-btn.danger { color: var(--faux); }
.count-line { display: flex; justify-content: space-between; align-items: baseline; margin-top: 18px; font-size: .9rem; }
.count-line b { font-family: var(--font-display); font-size: 1.15rem; }
.progress { height: 8px; border-radius: 99px; background: var(--line-strong); overflow: hidden; margin-top: 12px; }
.progress > i { display: block; height: 100%; width: 100%; background: var(--margin); transform-origin: left; transform: scaleX(0); transition: transform .2s; }
.sticky-cta { position: sticky; bottom: calc(var(--tab-h) + 12px); margin-top: 22px; z-index: 5; padding: 10px; border-radius: 14px; background: var(--paper); box-shadow: 0 -2px 12px var(--line-strong); }

/* Spinner / waiting */
.waiting { text-align: center; padding: 40px 16px; }
.pencil-loader { width: 84px; height: 84px; margin: 0 auto 18px; position: relative; }
.pencil-loader svg { width: 100%; height: 100%; }
.pencil-loader .trace { stroke-dasharray: 160; stroke-dashoffset: 160; animation: draw 2.2s var(--ease) infinite; }
@keyframes draw { 50% { stroke-dashoffset: 0; } 100% { stroke-dashoffset: -160; } }
.waiting h2 { margin-bottom: 6px; }
.waiting p { color: var(--muted); margin: 0; }
.skeleton { border-radius: 8px; background: linear-gradient(90deg, var(--line) 25%, var(--line-strong) 50%, var(--line) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite linear; height: 14px; margin: 10px 0; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Rich text (Markdown + KaTeX) */
.rich { overflow-wrap: anywhere; }
.rich > :first-child { margin-top: 0; }
.rich > :last-child { margin-bottom: 0; }
.rich h1, .rich h2, .rich h3 { margin: 1.2em 0 .5em; }
.rich h2 { font-size: 1.25rem; color: var(--margin); }
.rich h3 { font-size: 1.08rem; }
.rich p { margin: .6em 0; }
.rich blockquote { margin: 1em 0; padding: 10px 14px; border-left: 3px solid var(--ink); background: var(--paper-2); border-radius: 0 10px 10px 0; }
.rich table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; margin: 1em 0; }
.rich th, .rich td { border: 1px solid var(--line-strong); padding: 6px 10px; }
.rich code { font-family: var(--font-mono); font-size: .88em; background: var(--paper-2); padding: 1px 5px; border-radius: 5px; }
.rich pre { overflow-x: auto; background: var(--paper-2); padding: 12px; border-radius: 10px; }
.rich pre code { background: none; padding: 0; }
.rich .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.rich ul, .rich ol { padding-left: 1.3em; }
mark.incertain { background: var(--highlight-soft); color: inherit; padding: 0 3px; border-radius: 3px; box-shadow: inset 0 -2px 0 var(--highlight); }

/* Lesson */
.photo-strip { display: flex; gap: 10px; overflow-x: auto; padding: 4px 2px 10px; scroll-snap-type: x mandatory; }
.photo-strip a { flex: none; scroll-snap-align: start; }
.photo-strip img { height: 132px; width: auto; border-radius: 10px; border: 1px solid var(--line-strong); box-shadow: var(--shadow); background: var(--paper-2); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; padding: 0; margin: 0; }
.chips li { font-size: .82rem; padding: 4px 10px; border-radius: 999px; background: var(--card); border: 1px solid var(--line-strong); }
.review-head { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.meta-grid { display: grid; gap: 14px; }
@media (min-width: 640px) { .meta-grid { grid-template-columns: 1fr 1fr; } }

.search { position: relative; margin-bottom: 18px; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search .input { padding-left: 42px; }
.chapter-group { margin-bottom: 26px; }
.chapter-title { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.chapter-title h2 { font-size: 1.12rem; }
.chapter-title span { font-size: .8rem; color: var(--muted); }

/* Tests */
.period-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.period {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; gap: 18px;
  min-height: 132px; padding: 16px; border-radius: 16px; border: 1.5px solid var(--line-strong); background: var(--card); text-align: left;
  cursor: pointer; box-shadow: var(--shadow); transition: transform .18s var(--ease), border-color .2s, box-shadow .2s;
}
.period:hover:not([disabled]) { transform: translateY(-2px); border-color: var(--ink); box-shadow: var(--shadow-lift); }
.period[disabled] { cursor: not-allowed; opacity: .62; box-shadow: none; background: transparent; border-style: dashed; }
.period strong { font-family: var(--font-display); font-size: 1.12rem; line-height: 1.15; }
.period .p-count { font-size: .82rem; font-weight: 700; color: var(--margin); }
.period[disabled] .p-count { color: var(--muted); }
.period .p-desc { font-size: .76rem; color: var(--muted); }
.period .p-num { position: absolute; top: 10px; right: 14px; font-family: var(--font-display); font-size: 2.1rem; font-weight: 700; color: var(--line-strong); line-height: 1; }
.period.is-loading { pointer-events: none; }
.period.is-loading .p-count::after { content: " · préparation…"; }
.prep-note { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 12px; background: var(--card); border: 1px solid var(--line-strong); margin-bottom: 18px; font-size: .92rem; }

.test-banner { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: var(--radius); background: var(--ink); color: var(--paper); margin-bottom: 20px; font-weight: 650; }
.q-card { margin-bottom: 14px; animation: rise .45s var(--ease) both; }
.q-card:nth-child(2) { animation-delay: .05s; } .q-card:nth-child(3) { animation-delay: .1s; } .q-card:nth-child(4) { animation-delay: .15s; } .q-card:nth-child(5) { animation-delay: .2s; }
.q-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.q-num { font-family: var(--font-display); font-weight: 700; color: var(--margin); font-size: 1.05rem; }
.reveal-zone { margin-top: 16px; padding-top: 16px; border-top: 1.5px dashed var(--line-strong); }
.solution { animation: unfold .45s var(--ease) both; transform-origin: top; }
@keyframes unfold { from { opacity: 0; transform: translateY(-6px) scaleY(.97); } to { opacity: 1; transform: none; } }
.answer-box { margin: 14px 0; padding: 12px 14px; border-radius: 12px; background: var(--highlight-soft); border: 1.5px solid var(--highlight); }
.answer-box .label { display: block; font-size: .74rem; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-soft); margin-bottom: 4px; }
.source-line { font-size: .84rem; color: var(--muted); margin: 10px 0 0; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.rating { margin-top: 16px; }
.rating-q { font-weight: 650; font-size: .92rem; margin: 0 0 8px; }
.rating-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.rate { min-height: 48px; border-radius: 12px; border: 1.5px solid var(--line-strong); background: var(--paper-2); font-weight: 700; cursor: pointer; transition: transform .15s var(--ease), background .2s, color .2s, border-color .2s; }
.rate:active { transform: scale(.96); }
.rate[aria-pressed="true"][data-eval="juste"] { background: var(--juste); border-color: var(--juste); color: var(--on-status); }
.rate[aria-pressed="true"][data-eval="partiel"] { background: var(--partiel); border-color: var(--partiel); color: var(--on-status); }
.rate[aria-pressed="true"][data-eval="faux"] { background: var(--faux); border-color: var(--faux); color: var(--on-status); }
.rate[disabled] { cursor: default; }
.rate[disabled]:not([aria-pressed="true"]) { opacity: .45; }
.thanks { font-size: .86rem; color: var(--juste); font-weight: 650; padding: 10px 0; }

.result-hero { text-align: center; padding: 28px 18px; margin-bottom: 22px; }
.result-score { font-family: var(--font-display); font-weight: 700; font-size: clamp(3rem, 16vw, 4.6rem); line-height: 1; margin: 6px 0 4px; display: inline-block; position: relative; }
.result-score::after { content: ""; position: absolute; left: -8%; right: -8%; bottom: -8px; height: 10px; border: 3px solid var(--margin); border-color: var(--margin) transparent transparent; border-radius: 50%; transform: rotate(-2deg); opacity: .85; }
.result-dots { display: flex; justify-content: center; gap: 8px; margin: 22px 0 6px; }
.result-dots span { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-size: .78rem; font-weight: 700; color: var(--on-status); }
.d-juste { background: var(--juste); } .d-partiel { background: var(--partiel); } .d-faux { background: var(--faux); } .d-none { background: var(--line-strong); color: var(--ink) !important; }

/* Monitor */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kpi { padding: 14px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line-strong); }
.kpi b { display: block; font-family: var(--font-display); font-size: 1.7rem; line-height: 1.1; }
.kpi span { font-size: .76rem; color: var(--muted); }
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--line-strong); background: var(--card); }
table.data { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.data th, table.data td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
table.data td.num { font-family: var(--font-mono); text-align: right; }
details.fail { background: var(--card); border: 1px solid var(--line-strong); border-radius: var(--radius); margin-bottom: 8px; }
details.fail summary { cursor: pointer; padding: 12px 14px; min-height: 44px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
details.fail pre { margin: 0; padding: 12px 14px; font-size: .78rem; overflow-x: auto; border-top: 1px dashed var(--line-strong); white-space: pre-wrap; word-break: break-word; }

/* Toast + dialog */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom)); z-index: 90; display: grid; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { padding: 12px 16px; border-radius: 12px; background: var(--ink); color: var(--paper); box-shadow: var(--shadow-lift); font-weight: 600; font-size: .92rem; animation: toastIn .3s var(--ease) both; pointer-events: auto; }
.toast.error { background: var(--faux); color: var(--on-status); }
.toast.ok { background: var(--juste); color: var(--on-status); }
.toast.out { animation: toastOut .25s ease both; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px); } }
dialog.confirm { border: 1px solid rgba(150,165,255,.16); padding: 0; border-radius: 18px; background: var(--card); color: var(--ink); width: min(92vw, 400px); box-shadow: var(--shadow-lift); }
dialog.confirm[open] { animation: pop .22s var(--ease); }
dialog.confirm::backdrop { background: rgba(10, 13, 34, .6); backdrop-filter: blur(2px); }
.confirm-body { padding: 22px 20px 18px; }
.confirm-body p { margin: 0 0 18px; font-size: 1.05rem; font-weight: 600; font-family: var(--font-display); }
.confirm-body .btn-row > * { flex: 1; }

.fade-swap { animation: rise .35s var(--ease) both; }
.center-error { text-align: center; padding: 50px 10px; }
.center-error .big { font-family: var(--font-display); font-size: 4.5rem; color: var(--margin); line-height: 1; transform: rotate(-4deg); display: inline-block; }

/* ---------- v2 : matières ---------- */
.subj-dot { display: inline-block; flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--subj, var(--ink)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--subj, var(--ink)) 22%, transparent); }
.subj-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.subj-line .link-btn { min-height: 32px; }


.subject-head h1 { text-decoration: underline; text-decoration-color: var(--subj); text-decoration-thickness: 4px; text-underline-offset: 6px; }

.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; margin: -6px 0 18px; }
.fchip { display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--card); color: var(--ink-soft); font-size: .88rem; font-weight: 600; text-decoration: none; }
.fchip[aria-current] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
details.chapter-group > summary { list-style: none; cursor: pointer; min-height: 44px; align-items: center; }
details.chapter-group > summary::-webkit-details-marker { display: none; }
details.chapter-group > summary svg { color: var(--muted); transition: transform .2s var(--ease); }
details.chapter-group:not([open]) > summary svg { transform: rotate(-90deg); }
details.chapter-group > summary h2 { flex: 1; }
.row-snippet { display: block; margin-top: 4px; font-size: .84rem; color: var(--ink-soft); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.misfile { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; padding: 14px; margin-bottom: 16px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line-strong); border-left: 5px solid var(--subj); box-shadow: var(--shadow); animation: rise .4s var(--ease) both; }
.misfile p { margin: 0; flex: 1 1 200px; font-weight: 650; }
.misfile .btn-row { flex: 1 1 100%; }
.flagged { margin-bottom: 16px; padding: 14px; border-radius: var(--radius); background: var(--partiel-soft); border: 1px solid color-mix(in srgb, var(--partiel) 35%, transparent); }
.flagged h2 { display: flex; align-items: center; gap: 8px; font-size: 1rem; margin: 0 0 8px; color: var(--partiel); }
.flagged ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.flagged q { display: block; font-style: italic; color: var(--ink); }
.flagged p { margin: 2px 0 0; font-size: .9rem; color: var(--ink-soft); }

.key-points, .citations { margin-top: 14px; }
.key-points .label, .citations .label { font-weight: 700; font-size: .86rem; margin: 0 0 6px; }
.key-points ul { margin: 0; padding-left: 20px; }
.key-points li { margin: 3px 0; }
.rich-inline > p { display: inline; margin: 0; }
.citation { margin: 0 0 8px; padding: 8px 12px; border-left: 3px solid var(--margin); background: var(--margin-soft); border-radius: 0 10px 10px 0; font-family: var(--font-display); }
.cite-link { display: inline-flex; min-height: 32px; align-items: center; font-family: var(--font); font-size: .8rem; font-weight: 600; color: var(--ink-soft); }
.monitor-filter { margin: -6px 0 18px; max-width: 320px; display: flex; gap: 8px; }
.rich pre { overflow-x: auto; padding: 10px 12px; border-radius: 10px; background: var(--paper-2); border: 1px solid var(--line-strong); font-family: var(--font-mono); font-size: .86rem; tab-size: 4; white-space: pre; }
.rich code { font-family: var(--font-mono); font-size: .9em; }

/* ---------- Accueil : cahier bleu nuit ---------- */
.tab[aria-current="page"]::before { display: none; }
.tab[aria-current="page"] > svg { border-radius: 14px; }
.tab[aria-current="page"] > svg { background: #2f3772; padding: 6px; width: 44px; height: 34px; border-radius: 17px; }
.tab-add .tab-plus { background: none; color: inherit; }
.resume { background: #262d63; border-color: rgba(217,196,106,.5); }
body[data-page="home"] h1 { font-size: clamp(1.7rem, 8vw, 3rem); }

.home-subjects .section-head h2 { font-size: 1.45rem; }
.hs-total { font-size: .88rem; color: var(--muted); }
.hs-total-x, .sc-x, .sc-long { display: none; }
.subject-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.sg-item { position: relative; animation: rise .45s var(--ease) both; }
.subject-card {
  display: flex; flex-direction: column; height: 100%; min-height: 160px; padding: 14px 16px 16px; border-radius: 18px;
  background: var(--card); border: 1px solid rgba(150,165,255,.14); color: var(--ink); text-decoration: none;
  box-shadow: var(--shadow); transition: transform .2s var(--ease), border-color .2s, box-shadow .2s;
}
.subject-card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--subj) 55%, transparent); box-shadow: var(--shadow-lift); }
.subject-card:active { transform: scale(.98); }
.subject-card:focus-visible, .sc-add:focus-visible { outline: 3px solid var(--highlight); outline-offset: 3px; border-radius: 18px; }
.sc-art { width: 56px; height: 56px; border-radius: 14px; display: grid; place-items: center; margin-bottom: 18px;
  background: color-mix(in srgb, var(--subj) 42%, #1e2558); }
.sc-art svg { width: 44px; height: 44px; }
.sc-name { font-weight: 700; font-size: 1.05rem; line-height: 1.2; margin-bottom: 4px; }
.sc-meta { font-size: .88rem; color: var(--ink-soft); opacity: .85; }
.sc-foot { display: none; }
.sc-add { position: absolute; top: 12px; right: 12px; width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center;
  background: rgba(150,165,255,.12); border: 1px solid rgba(150,165,255,.2); color: var(--ink); transition: background .2s, transform .15s var(--ease); }
.sc-add:hover { background: rgba(150,165,255,.24); }
.sc-add:active { transform: scale(.94); }
@media (min-width: 960px) {
  .hs-total-x, .sc-x, .sc-long { display: inline; }
  .sc-name-long .sc-short { display: none; }
  .sc-mscore { display: none; }
  .subject-grid { grid-template-columns: repeat(3, 1fr); gap: 12px; }
  .subject-card { min-height: 148px; padding: 12px 12px 12px; border-radius: 14px; }
  .sc-art { width: 40px; height: 40px; border-radius: 11px; margin-bottom: 14px; }
  .sc-art svg { width: 36px; height: 36px; }
  .sc-name { font-size: 1rem; margin-bottom: 0; }
  .sc-meta { font-size: .8rem; }
  .sc-foot { display: flex; justify-content: space-between; align-items: center; margin-top: auto; padding-top: 10px; border-top: 1px solid rgba(150,165,255,.12); font-size: .76rem; color: var(--ink-soft); min-height: 38px; }
  .sc-score { background: rgba(150,165,255,.16); padding: 2px 8px; border-radius: 8px; font-size: .78rem; color: var(--ink); }
  .sc-add { width: 44px; height: 44px; border-radius: 11px; }
  .tab[aria-current="page"] > svg { width: 34px; }
  body[data-page="home"] .main, body[data-page="home"] .topbar, body[data-page="home"] .footer { max-width: 760px; }
}

/* ---------- Navigation globale : sélecteur de matière ---------- */
.subj-tag { display: inline-flex; align-items: center; gap: 6px; font-weight: 650; color: var(--ink-soft); }
.subj-tag .subj-dot { width: 8px; height: 8px; box-shadow: none; }
.subject-field { margin: 0 0 18px; }
.select.is-missing { border-color: var(--faux); box-shadow: 0 0 0 4px var(--faux-soft); }
.subject-chooser { display: grid; gap: 6px; margin: 0 0 20px; padding: 14px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line-strong); animation: rise .45s var(--ease) both; }
.subject-chooser label { font-weight: 650; font-size: .9rem; }
.chooser-row { display: flex; gap: 10px; align-items: center; }
.chooser-row .select { flex: 1; }
.js-hide { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.js-hide:focus { position: static; width: auto; height: auto; clip: auto; }
.choose-empty { margin-bottom: 8px; }

@media (min-width: 960px) {
  .subject-field .select, .subject-chooser .select {
    appearance: none;
    height: 56px;
    min-height: 56px;
    padding: 14px 44px 14px 16px;
    font-size: 1rem;
    line-height: 1.5;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20' fill='none' stroke='%23c3c8ec' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 8 4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
  }
}
