/* Layout : application à onglets — bandeau d'orientation en direct en haut, examen défilant,
   barre d'onglets fixe en bas ; à partir de 960 px, examen et résultat côte à côte, onglets en tête. */
:root {
  --bg: #ECEFF3;
  --surface: #FFFFFF;
  --sunk: #E2E7ED;
  --ink: #0F1B2B;
  --muted: #586678;
  --line: #D2D9E1;
  --accent: #1B45BF;
  --accent-ink: #FFFFFF;
  --accent-soft: #E1E8F9;
  --danger: #B3271A;
  --danger-soft: #FBE5E1;
  --warn: #8F5300;
  --warn-soft: #FAEDD4;
  --note-soft: #E6EBF1;
  --fam-dep: #2C62B0;
  --fam-exc: #BD4C19;
  --fam-cv: #7B3C9E;
  --fam-chim: #187C64;
  --fam-met: #87670A;
  --fam-none: #6A7584;
  --f-display: "Barlow Semi Condensed", "Arial Narrow", "Roboto Condensed", system-ui, sans-serif;
  --f-body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --r: 10px;
  --tabbar-h: 62px;
  --beta-bg: #F2B33D;
  --beta-ink: #241600;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0C1218; --surface: #141C26; --sunk: #1D2734; --ink: #E3E9F0; --muted: #94A2B3; --line: #273343;
    --accent: #84A6FF; --accent-ink: #0A1430; --accent-soft: #1A2747;
    --danger: #FF8B7B; --danger-soft: #3A1915; --warn: #F0B455; --warn-soft: #33250E; --note-soft: #19212C;
    --fam-dep: #74A0EA; --fam-exc: #EE8C5C; --fam-cv: #BC8EDB; --fam-chim: #52C3A3; --fam-met: #D8B14C; --fam-none: #8E99A8;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0C1218; --surface: #141C26; --sunk: #1D2734; --ink: #E3E9F0; --muted: #94A2B3; --line: #273343;
  --accent: #84A6FF; --accent-ink: #0A1430; --accent-soft: #1A2747;
  --danger: #FF8B7B; --danger-soft: #3A1915; --warn: #F0B455; --warn-soft: #33250E; --note-soft: #19212C;
  --fam-dep: #74A0EA; --fam-exc: #EE8C5C; --fam-cv: #BC8EDB; --fam-chim: #52C3A3; --fam-met: #D8B14C; --fam-none: #8E99A8;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body::before {
  content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px);
  z-index: 30; background: var(--surface);
}
h1, h2, h3, h4 { font-family: var(--f-display); text-wrap: balance; margin: 0; line-height: 1.15; }
p { margin: 0; }
ul { margin: 0; padding-left: 1.1em; }
button, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }

/* ---------- En-tête */
.top {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.top-in {
  max-width: 1200px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 8px;
  display: flex; align-items: center; gap: 12px; min-height: 56px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; flex: none; }
.brand svg { width: 34px; height: 34px; flex: none; }
.brand-txt { display: none; }
.brand-txt strong { display: block; font-family: var(--f-display); font-size: 21px; font-weight: 700; letter-spacing: .01em; line-height: 1; }
.brand-txt small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }

.strip {
  flex: 1; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline;
  column-gap: 10px; row-gap: 5px; text-align: left;
  background: var(--sunk); border: 0; border-radius: 9px; padding: 7px 12px 8px;
}
.strip-k { grid-column: 1 / -1; font-family: var(--f-display); font-size: 11px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); display: flex; justify-content: space-between; }
.strip-name { font-family: var(--f-display); font-weight: 700; font-size: 17px; line-height: 1.1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.strip-name.is-empty { font-weight: 500; color: var(--muted); font-size: 15px; }
.strip-pct { font-family: var(--f-mono); font-weight: 600; font-size: 16px; font-variant-numeric: tabular-nums; }
.strip-bar { grid-column: 1 / -1; height: 4px; border-radius: 4px; background: color-mix(in srgb, var(--ink) 10%, transparent); overflow: hidden; }
.strip-bar i { display: block; height: 100%; width: 0; background: var(--fam, var(--accent)); border-radius: 4px; transition: width .35s ease; }

/* ---------- Bandeau bêta : toujours visible, dans l'en-tête collant */
.beta {
  background: var(--beta-bg); color: var(--beta-ink);
  background-image: repeating-linear-gradient(-45deg, transparent 0 14px, rgb(0 0 0 / .06) 14px 28px);
}
.beta-in {
  max-width: 1200px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 5px;
  display: flex; flex-wrap: wrap; justify-content: center; align-items: baseline; gap: 2px 10px;
  font-size: 13.5px; font-weight: 700; line-height: 1.3; text-align: center;
}
.beta-in b { font-family: var(--f-display); font-size: 13px; letter-spacing: .1em; text-transform: uppercase; }
.disc b { color: var(--warn); }

/* ---------- Onglets : barre fixe en bas sur mobile */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: max(8px, env(safe-area-inset-left, 0px));
  padding-right: max(8px, env(safe-area-inset-right, 0px));
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  height: var(--tabbar-h); border: 0; background: none; color: var(--muted);
  font-family: var(--f-display); font-size: 13px; font-weight: 600; letter-spacing: .02em; position: relative;
}
.tab svg { width: 22px; height: 22px; }
.tab[aria-current="page"] { color: var(--accent); }
.tab[aria-current="page"]::before { content: ""; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
.tab .badge { position: absolute; top: 8px; left: calc(50% + 8px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font: 600 11px/18px var(--f-mono); }

/* ---------- Vues */
.views {
  max-width: 1200px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 14px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom, 0px));
}
.view { display: none; min-width: 0; }
.app[data-tab="examen"] #v-examen,
.app[data-tab="resultat"] #v-resultat,
.app[data-tab="fiches"] #v-fiches,
.app[data-tab="methode"] #v-methode { display: block; }

/* ---------- Examen */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-bottom: 12px; }
.count { color: var(--muted); font-size: 14px; }
.count b { color: var(--ink); font-family: var(--f-mono); font-weight: 600; }
.tools { display: flex; gap: 8px; flex: 1 1 320px; justify-content: flex-end; min-width: 0; }
.tools .select { flex: 1; min-width: 0; max-width: 340px; }
.select, .btn {
  height: 38px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  padding: 0 12px; font-size: 14px; color: var(--ink);
}
.select { max-width: 100%; padding-right: 28px; }
.btn { font-family: var(--f-display); font-weight: 600; font-size: 15px; }
.btn.armed { background: var(--danger); border-color: var(--danger); color: #fff; }
.demo-banner { margin-bottom: 12px; padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--ink); font-size: 14px; }
.demo-banner b { color: var(--warn); font-family: var(--f-display); letter-spacing: .04em; text-transform: uppercase; font-size: 12px; margin-right: 6px; }

.form { display: grid; gap: 12px; }
.group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 2px 14px 4px; min-width: 0; }
.group-h { display: flex; align-items: baseline; gap: 8px; padding: 12px 0 4px; font-size: 13px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.group-h span { font-family: var(--f-body); font-size: 12px; letter-spacing: 0; text-transform: none; font-weight: 400; }
.group-h .gcount { margin-left: auto; font-family: var(--f-mono); letter-spacing: 0; font-weight: 500; }
.rows > .field + .field { border-top: 1px solid var(--line); }
.field { padding: 10px 0; scroll-margin-top: 120px; }
.field.flash { animation: flash 1.2s ease; }
@keyframes flash { 0%, 40% { background: var(--accent-soft); } 100% { background: transparent; } }
.f-label { font-weight: 700; font-size: 15px; }
.f-label small { display: block; font-weight: 400; color: var(--muted); font-size: 13px; }

.cat .f-label { margin-bottom: 7px; }
.seg { display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: 3px; background: var(--sunk); padding: 3px; border-radius: 9px; }
.seg-b {
  border: 0; background: transparent; border-radius: 7px; padding: 7px 4px 6px; min-height: 46px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  font-family: var(--f-display); font-weight: 600; font-size: 15px; line-height: 1.1; color: var(--ink);
  transition: background .12s ease, color .12s ease;
}
.seg-b small { font-family: var(--f-mono); font-weight: 400; font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.seg-b[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); box-shadow: 0 1px 2px rgb(0 0 0 / .18); }
.seg-b[aria-pressed="true"] small { color: inherit; opacity: .85; }

.bin { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px; }
.yn { display: flex; gap: 4px; }
.yn-b {
  min-width: 58px; height: 38px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  font-family: var(--f-display); font-weight: 600; font-size: 15px; color: var(--muted);
}
.yn-b.yes[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.yn-b.no[aria-pressed="true"] { background: var(--sunk); border-color: var(--ink); color: var(--ink); }
.subfield { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.subfield > span { font-size: 13px; color: var(--muted); }
.subfield .seg { flex: 1; min-width: 220px; }
.subfield .seg-b { min-height: 34px; font-size: 14px; }

.ctx { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 0 12px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 18px; padding: 7px 12px;
  font-size: 14px; line-height: 1.25; text-align: left; color: var(--ink); max-width: 100%;
}
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); font-weight: 700; }
.chip[aria-pressed="true"]::before { content: "✓ "; color: var(--accent); }

/* ---------- Résultat */
.res { display: grid; gap: 12px; }
.res-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.res-head h2 { font-size: 22px; }
.res-head span { color: var(--muted); font-size: 13px; }
.alert { border-radius: var(--r); padding: 10px 12px; font-size: 14px; display: grid; gap: 2px; }
.alert h3 { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; }
.alert.danger { background: var(--danger-soft); }
.alert.danger h3 { color: var(--danger); }
.alert.warn { background: var(--warn-soft); }
.alert.warn h3 { color: var(--warn); }
.alert.note { background: var(--note-soft); }
.alert.note h3 { color: var(--muted); }
.alert .sub { color: var(--muted); font-size: 13px; }

.topcard { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); overflow: hidden; }
.topcard-h { padding: 12px 14px 12px; background: var(--surface); background: color-mix(in srgb, var(--fam) 11%, var(--surface)); display: grid; gap: 6px; }
.topcard-k { display: flex; justify-content: space-between; gap: 8px; font-family: var(--f-display); font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.topcard-k .lvl { color: var(--fam); }
.topcard-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.topcard-row h2 { font-size: 28px; font-weight: 700; min-width: 0; }
.pct { font-family: var(--f-mono); font-variant-numeric: tabular-nums; font-weight: 600; font-size: 34px; line-height: 1; white-space: nowrap; }
.pct small { font-size: 18px; margin-left: 2px; }
.bar { height: 6px; border-radius: 6px; background: color-mix(in srgb, var(--ink) 10%, transparent); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--fam); border-radius: 6px; transition: width .35s ease; }
.topcard-b { padding: 12px 14px 14px; display: grid; gap: 12px; }
.why { display: grid; grid-template-columns: 1fr; gap: 10px; }
.why h4, .act h4 { font-size: 12px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); margin-bottom: 5px; }
.tags { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 5px; }
.tags li { font-size: 13px; padding: 3px 9px; border-radius: 6px; background: var(--sunk); }
.tags.pro li::before { content: "+ "; font-family: var(--f-mono); color: var(--fam); font-weight: 600; }
.tags.con li { background: transparent; border: 1px dashed var(--line); color: var(--muted); }
.tags.con li::before { content: "− "; font-family: var(--f-mono); }
.act ul { display: grid; gap: 4px; font-size: 14px; }
.linkbtn { justify-self: start; border: 0; background: none; padding: 4px 0; color: var(--accent); font-family: var(--f-display); font-weight: 700; font-size: 15px; }

.others h3 { font-size: 13px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.rank { list-style: none; padding: 0; margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.rank li + li { border-top: 1px solid var(--line); }
.rank button {
  width: 100%; border: 0; background: none; text-align: left; padding: 9px 14px;
  display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; column-gap: 9px; row-gap: 5px; align-items: center;
}
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--fam); }
.rank .nm { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .pc { font-family: var(--f-mono); font-variant-numeric: tabular-nums; font-size: 14px; color: var(--muted); }
.rank .bar { grid-column: 2 / -1; height: 4px; }
.more { margin-top: 6px; }
.more summary { cursor: pointer; color: var(--accent); font-family: var(--f-display); font-weight: 700; font-size: 15px; padding: 6px 0; }

.next { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; display: grid; gap: 8px; }
.next h3 { font-size: 13px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.next p { font-size: 13px; color: var(--muted); }
.next-list { display: flex; flex-wrap: wrap; gap: 6px; }
.next-list button { border: 1px solid var(--accent); background: var(--accent-soft); color: var(--ink); border-radius: 8px; padding: 7px 12px; font-family: var(--f-display); font-weight: 600; font-size: 15px; }

.empty { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 14px; display: grid; gap: 10px; }
.empty h2 { font-size: 22px; }
.empty p { color: var(--muted); }

.contact { display: grid; gap: 8px; padding: 12px 14px; border-radius: var(--r); background: var(--note-soft); font-size: 14px; }
.contact-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.contact-row strong { font-family: var(--f-display); font-size: 15px; }
.num { font-family: var(--f-mono); font-weight: 600; font-size: 16px; user-select: all; -webkit-user-select: all; }
.copy { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 3px 9px; font-size: 13px; }
.disc { font-size: 12.5px; color: var(--muted); }

/* ---------- Fiches et méthode */
.doc { display: grid; gap: 14px; max-width: 760px; }
.doc > h2 { font-size: 26px; }
.lede { color: var(--muted); max-width: 64ch; }
.box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: grid; gap: 8px; }
.box h3 { font-size: 18px; }
.box ol, .box ul { padding-left: 1.2em; display: grid; gap: 4px; font-size: 14px; }
.box p { font-size: 14px; }
.fiche { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); scroll-margin-top: 110px; }
.fiche summary { list-style: none; cursor: pointer; padding: 12px 14px; display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; gap: 10px; align-items: center; }
.fiche summary::-webkit-details-marker { display: none; }
.fiche summary h3 { font-size: 19px; }
.fiche summary .fam { font-size: 12px; color: var(--muted); font-family: var(--f-display); letter-spacing: .06em; text-transform: uppercase; }
.fiche summary .chev { width: 18px; height: 18px; color: var(--muted); transition: transform .15s ease; }
.fiche[open] summary .chev { transform: rotate(180deg); }
.fiche-b { padding: 0 14px 14px; display: grid; gap: 12px; font-size: 14px; }
.fiche-b h4 { font-size: 12px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.fiche-b ul { display: grid; gap: 3px; }
.mnemo { padding: 8px 10px; border-radius: 8px; background: var(--sunk); font-style: italic; }
.prose { display: grid; gap: 10px; font-size: 15px; max-width: 66ch; }
.prose h3 { font-size: 19px; margin-top: 6px; }
.prose ul, .prose ol { display: grid; gap: 4px; }
.refs { font-size: 13.5px; display: grid; gap: 6px; padding-left: 1.3em; }
.formula { font-family: var(--f-mono); font-size: 13px; background: var(--sunk); padding: 10px 12px; border-radius: 8px; overflow-x: auto; white-space: pre; }
.meta { color: var(--muted); font-size: 13px; }

/* ---------- Écran large */
@media (min-width: 640px) {
  .brand-txt { display: block; }
  .why { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 960px) {
  :root { --tabbar-h: 0px; }
  .top-in { gap: 28px; }
  .strip { display: none; }
  .tabs {
    position: static; display: flex; gap: 4px; border: 0; padding: 0; background: none; margin-left: auto;
  }
  .tab { flex-direction: row; height: 40px; padding: 0 14px; border-radius: 8px; font-size: 15px; gap: 7px; }
  .tab svg { width: 18px; height: 18px; }
  .tab[aria-current="page"] { background: var(--accent-soft); }
  .tab[aria-current="page"]::before { display: none; }
  .tab .badge { position: static; }
  .tab-resultat { display: none; }
  .views { padding-block: 20px 40px; }
  .app[data-tab="examen"] .views, .app[data-tab="resultat"] .views {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 430px); gap: 24px; align-items: start;
  }
  .app[data-tab="examen"] #v-resultat, .app[data-tab="resultat"] #v-examen { display: block; }
  #v-resultat { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 106px); max-height: calc(100vh - 124px); overflow-y: auto; padding-bottom: 8px; }
  .form { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .form .group.wide { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
