/* Sémio & Épidémio — iPad-first study guide.
   Tokens: cool clinical paper, deep green ink, two subject colours (sémio = officine green,
   épidémio = indigo), amber for « tombé à l'examen ». */

:root {
  --paper: #f3f6f4;
  --sheet: #ffffff;
  --sunk: #e8eeea;
  --ink: #10221d;
  --ink-2: #3b4d47;
  --muted: #64746f;
  --line: #d3ddd8;
  --line-strong: #b6c4bd;

  --semio: #0d7a63;
  --semio-soft: #dcefe8;
  --epi: #3946a8;
  --epi-soft: #e2e5f7;
  --tombe: #b86e00;
  --tombe-soft: #fbecd2;
  --right: #157a45;
  --right-soft: #daf1e3;
  --wrong: #b93a30;
  --wrong-soft: #f9e0dc;
  --focus: #2b62d9;

  --accent: var(--semio);
  --accent-soft: var(--semio-soft);

  --f-display: "Schibsted Grotesk", "Helvetica Neue", Arial, sans-serif;
  --f-body: "Atkinson Hyperlegible Next", -apple-system, "Segoe UI", sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;

  --r-s: 8px;
  --r-m: 14px;
  --r-l: 20px;
  --shadow: 0 1px 0 rgb(16 34 29 / 0.04), 0 6px 20px -12px rgb(16 34 29 / 0.25);

  --nav-w: 232px;
  --tab-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --measure: 46rem;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f1916;
    --sheet: #16231f;
    --sunk: #1c2c27;
    --ink: #e6efeb;
    --ink-2: #c3d1cb;
    --muted: #8fa29b;
    --line: #2a3b35;
    --line-strong: #3a4e47;
    --semio: #4cc3a5;
    --semio-soft: #173a31;
    --epi: #9aa6ff;
    --epi-soft: #252b52;
    --tombe: #f0b14e;
    --tombe-soft: #3d2d12;
    --right: #5dd394;
    --right-soft: #173828;
    --wrong: #ff8a7d;
    --wrong-soft: #45201c;
    --focus: #8fb2ff;
    --shadow: 0 1px 0 rgb(0 0 0 / 0.2), 0 8px 24px -14px rgb(0 0 0 / 0.6);
    color-scheme: dark;
  }
}

[data-subject="epi"] { --accent: var(--epi); --accent-soft: var(--epi-soft); }
[data-subject="semio"] { --accent: var(--semio); --accent-soft: var(--semio-soft); }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 17.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
svg { width: 1.25em; height: 1.25em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
table { border-collapse: collapse; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--ink); color: var(--paper); padding: 8px 12px; border-radius: var(--r-s); z-index: 99; }
.skip:focus { left: 8px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Shell ---------- */
.shell { min-height: 100dvh; }
.nav {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--sheet) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--line);
}
.brand, .nav-search { display: none; }
.nav-list { list-style: none; margin: 0; padding: 0 4px; height: var(--tab-h); display: grid; grid-template-columns: repeat(6, 1fr); }
.nav-list a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: 100%; text-decoration: none; color: var(--muted); font-size: 11.5px; font-weight: 600; letter-spacing: 0.01em;
}
.nav-list a svg { width: 24px; height: 24px; }
.nav-list a[aria-current="page"] { color: var(--ink); }
.nav-list a[aria-current="page"] svg { color: var(--accent); stroke-width: 2.2; }
.main { padding: 20px 20px calc(var(--tab-h) + var(--safe-b) + 32px); max-width: 1100px; margin: 0 auto; outline: none; }
.loading { color: var(--muted); }

@media (min-width: 1000px) {
  .nav {
    inset: 0 auto 0 0; width: var(--nav-w); height: auto; padding: 22px 14px; display: flex; flex-direction: column; gap: 18px;
    border-top: 0; border-right: 1px solid var(--line); background: var(--sheet);
  }
  .brand { display: flex; align-items: center; gap: 10px; text-decoration: none; padding: 4px 10px 10px; }
  .brand-mark { width: 28px; height: 28px; border-radius: 8px; background:
      linear-gradient(var(--semio), var(--semio)) 0 0 / 50% 50% no-repeat,
      linear-gradient(var(--epi), var(--epi)) 100% 100% / 50% 50% no-repeat,
      var(--sunk); }
  .brand-text { font-family: var(--f-display); font-weight: 800; font-size: 18px; letter-spacing: -0.02em; line-height: 1.1; }
  .amp { color: var(--muted); font-weight: 500; }
  .nav-list { display: flex; flex-direction: column; height: auto; gap: 2px; padding: 0; }
  .nav-list a { flex-direction: row; justify-content: flex-start; gap: 12px; height: 46px; padding: 0 12px; font-size: 16px; border-radius: 10px; color: var(--ink-2); }
  .nav-list a[aria-current="page"] { background: var(--sunk); }
  .nav-search {
    display: flex; align-items: center; gap: 10px; margin-top: auto; height: 46px; padding: 0 12px; border-radius: 10px;
    border: 1px solid var(--line); background: var(--paper); color: var(--muted); font-size: 15px;
  }
  .main { margin-left: var(--nav-w); padding: 36px 44px 64px; max-width: calc(1100px + var(--nav-w)); }
}

/* Search button for compact layouts lives in the page header */
.top-search { display: inline-flex; }
@media (min-width: 1000px) { .icon-btn.top-search { display: none; } }

/* ---------- Type ---------- */
h1, h2, h3, h4 { font-family: var(--f-display); letter-spacing: -0.02em; line-height: 1.15; margin: 0; }
h1 { font-size: clamp(30px, 4.2vw, 44px); font-weight: 800; }
h2 { font-size: 24px; font-weight: 800; }
h3 { font-size: 19px; font-weight: 700; }
.eyebrow { font-family: var(--f-display); font-size: 13px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 0 0 6px; }
.lede { color: var(--ink-2); max-width: 40rem; margin: 10px 0 0; }
.muted { color: var(--muted); }
.mono { font-family: var(--f-mono); font-size: 0.92em; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin: 4px 0 28px; flex-wrap: wrap; }
.page-head .back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 15px; margin-bottom: 10px; min-height: 36px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 40px 0 14px; }
.section-title h2 { font-size: 21px; }

/* ---------- Primitives ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px;
  border-radius: 999px; border: 1px solid transparent; background: var(--ink); color: var(--paper);
  font-weight: 700; font-size: 16px; text-decoration: none; white-space: nowrap; touch-action: manipulation;
}
.btn.accent { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.accent { color: #0b1512; } }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.btn.small { min-height: 40px; padding: 0 14px; font-size: 15px; }
.btn[disabled] { opacity: 0.45; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.icon-btn { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 999px; border: 1px solid var(--line); background: var(--sheet); color: var(--ink-2); }

.card { background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-l); box-shadow: var(--shadow); }
.pad { padding: 22px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 26px; padding: 2px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 700; background: var(--sunk); color: var(--ink-2); white-space: nowrap; line-height: 1.2;
}
.chip.semio { background: var(--semio-soft); color: var(--semio); }
.chip.epi { background: var(--epi-soft); color: var(--epi); }
.chip.tombe { background: var(--tombe-soft); color: var(--tombe); }
.chip.warn { background: var(--wrong-soft); color: var(--wrong); }
.chip.ok { background: var(--right-soft); color: var(--right); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.filter-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 18px; }
.seg { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--sunk); gap: 2px; }
.seg button { min-height: 40px; padding: 0 16px; border: 0; border-radius: 999px; background: transparent; font-weight: 700; font-size: 15px; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--sheet); color: var(--ink); box-shadow: var(--shadow); }

.bar { height: 6px; border-radius: 999px; background: var(--sunk); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: inherit; }

.empty { padding: 28px; text-align: center; color: var(--muted); border: 1.5px dashed var(--line-strong); border-radius: var(--r-l); }

/* ---------- Home ---------- */
.hero { display: grid; gap: 18px; grid-template-columns: 1fr; margin-bottom: 8px; }
.hero h1 span { color: var(--muted); font-weight: 600; }
.quick { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(200px, 42vw), 1fr)); margin-top: 26px; }
.quick a {
  display: flex; flex-direction: column; gap: 6px; padding: 18px; text-decoration: none; min-height: 112px;
  background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-l); box-shadow: var(--shadow);
}
.quick a strong { font-family: var(--f-display); font-size: 30px; font-weight: 800; letter-spacing: -0.03em; line-height: 1; }
.quick a span { color: var(--ink-2); font-weight: 600; }
.quick a small { color: var(--muted); font-size: 14px; margin-top: auto; }

/* Signature: « Ce qui tombe » grid — one row per notion, one column per exam year */
.tombe { background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-l); box-shadow: var(--shadow); overflow: hidden; }
.tombe-head, .tombe-row { display: grid; grid-template-columns: minmax(0, 1fr) repeat(var(--years), 30px) 56px; align-items: center; gap: 0 4px; padding: 0 16px; }
.tombe-head { position: sticky; top: 0; background: var(--sheet); border-bottom: 1px solid var(--line); min-height: 44px; font-family: var(--f-mono); font-size: 12px; color: var(--muted); }
.tombe-head span { text-align: center; }
.tombe-row { min-height: 52px; border-bottom: 1px solid var(--line); text-decoration: none; }
.tombe-row:last-child { border-bottom: 0; }
.tombe-row .name { display: flex; flex-direction: column; min-width: 0; padding: 8px 8px 8px 0; }
.tombe-row .name b { font-weight: 700; line-height: 1.3; }
.tombe-row .name small { color: var(--muted); font-size: 13px; }
.dot { width: 22px; height: 22px; margin: 0 auto; border-radius: 6px; background: var(--sunk); }
.dot.on { background: var(--tombe); box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--tombe) 60%, #000 0%); }
.dot.on.x2 { background: repeating-linear-gradient(135deg, var(--tombe) 0 5px, color-mix(in srgb, var(--tombe) 70%, var(--sheet)) 5px 7px); }
.mastery { font-family: var(--f-mono); font-size: 13px; text-align: right; color: var(--muted); }
.mastery.good { color: var(--right); }
.mastery.bad { color: var(--wrong); }
.tombe-more { display: block; width: 100%; min-height: 48px; border: 0; border-top: 1px solid var(--line); background: var(--paper); font-weight: 700; color: var(--ink-2); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 14px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; margin-right: 6px; background: var(--tombe); }

/* Chapter tiles */
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.tile { display: flex; flex-direction: column; gap: 10px; padding: 18px; text-decoration: none; background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-l); box-shadow: var(--shadow); min-height: 150px; }
.tile .k { font-family: var(--f-mono); font-size: 13px; color: var(--accent); font-weight: 600; }
.tile h3 { font-size: 19px; }
.tile .meta { margin-top: auto; display: flex; flex-direction: column; gap: 8px; font-size: 14px; color: var(--muted); }

/* ---------- Reading view ---------- */
.reader { display: grid; gap: 32px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1200px) { .reader { grid-template-columns: minmax(0, 1fr) 240px; } }
.toc { display: none; }
@media (min-width: 1200px) {
  .toc { display: block; position: sticky; top: 24px; align-self: start; max-height: calc(100dvh - 48px); overflow: auto; font-size: 14.5px; }
  .toc ol { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
  .toc a { display: block; padding: 6px 12px; text-decoration: none; color: var(--muted); margin-left: -2px; border-left: 2px solid transparent; line-height: 1.35; }
  .toc a.read { color: var(--ink-2); }
  .toc a:hover { color: var(--ink); border-left-color: var(--accent); }
}
.objectives { margin: 0 0 28px; padding: 18px 22px; border-radius: var(--r-m); background: var(--accent-soft); }
.objectives h3 { font-size: 15px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); margin-bottom: 6px; }
.objectives ul { margin: 0; padding-left: 20px; }

.sec { margin: 0 0 18px; padding: 24px 26px; background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-l); scroll-margin-top: 20px; }
.sec-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 12px; }
.sec-head h2 { font-size: 22px; }
.sec-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.sec-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.read-toggle { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-strong); background: transparent; font-weight: 700; font-size: 15px; color: var(--ink-2); }
.read-toggle[aria-pressed="true"] { background: var(--right-soft); color: var(--right); border-color: transparent; }

/* Rich content coming from JSON */
.rich { max-width: var(--measure); }
.rich > :first-child { margin-top: 0; }
.rich p { margin: 0 0 12px; }
.rich ul, .rich ol { margin: 0 0 12px; padding-left: 22px; }
.rich li { margin: 3px 0; }
.rich li::marker { color: var(--accent); }
.rich h4 { font-size: 17px; margin: 20px 0 8px; color: var(--ink); }
.rich strong { font-weight: 700; }
.rich .hl { background: linear-gradient(transparent 55%, color-mix(in srgb, var(--accent) 22%, transparent) 55%); padding: 0 2px; }
.rich .formula { font-family: var(--f-mono); font-size: 0.93em; background: var(--sunk); padding: 2px 7px; border-radius: 6px; white-space: nowrap; }
.rich table { width: 100%; margin: 8px 0 16px; font-size: 15.5px; display: block; overflow-x: auto; }
.rich th, .rich td { text-align: left; vertical-align: top; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.rich thead th, .rich tr:first-child th { background: var(--sunk); font-family: var(--f-display); font-weight: 700; font-size: 14.5px; }
.rich td:first-child, .rich th:first-child { padding-left: 4px; }
.rich thead th:first-child { padding-left: 12px; }
.callout { margin: 14px 0; padding: 14px 16px 14px 18px; border-radius: var(--r-m); border-left: 4px solid; }
.callout > :last-child { margin-bottom: 0; }
.callout::before { display: block; font-family: var(--f-display); font-size: 12.5px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 4px; }
.callout.key { background: var(--accent-soft); border-color: var(--accent); }
.callout.key::before { content: "À retenir"; color: var(--accent); }
.callout.tip { background: var(--sunk); border-color: var(--ink-2); }
.callout.tip::before { content: "Astuce"; color: var(--ink-2); }
.callout.trap { background: var(--wrong-soft); border-color: var(--wrong); }
.callout.trap::before { content: "Piège d'examen"; color: var(--wrong); }

/* ---------- Annales list ---------- */
.exam-year { margin: 30px 0 10px; font-family: var(--f-mono); font-size: 14px; color: var(--muted); font-weight: 600; }
.exam-list { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.exam-card { display: flex; flex-direction: column; gap: 12px; padding: 18px; text-decoration: none; background: var(--sheet); border: 1px solid var(--line); border-left: 5px solid var(--accent); border-radius: var(--r-m); box-shadow: var(--shadow); }
.exam-card h3 { font-size: 18px; }
.exam-card .meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; color: var(--muted); font-size: 14px; }

/* ---------- Quiz ---------- */
.quiz { max-width: 50rem; }
.quiz-top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 14px; padding: 12px 0; background: var(--paper); margin-bottom: 8px; }
.quiz-top .bar { flex: 1; }
.quiz-top .count { font-family: var(--f-mono); font-size: 14px; color: var(--muted); white-space: nowrap; }
.timer { font-family: var(--f-mono); font-weight: 600; font-size: 16px; padding: 6px 12px; border-radius: 999px; background: var(--sunk); }
.timer.low { background: var(--wrong-soft); color: var(--wrong); }

.q { padding: 24px; background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-l); box-shadow: var(--shadow); margin-bottom: 16px; }
.q-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; align-items: center; }
.q-stem { font-size: 19px; font-weight: 700; line-height: 1.4; margin: 0 0 16px; }
.q-context { margin-bottom: 16px; }
.q-context details { background: var(--sunk); border-radius: var(--r-m); padding: 0 16px; }
.q-context summary { min-height: 48px; display: flex; align-items: center; font-weight: 700; cursor: pointer; list-style: none; gap: 8px; }
.q-context summary::-webkit-details-marker { display: none; }
.q-context summary::before { content: "▸"; color: var(--muted); transition: transform 0.15s; }
.q-context details[open] summary::before { transform: rotate(90deg); }
.q-context .rich { padding-bottom: 14px; }
.q-context .rich table { background: var(--sheet); border-radius: var(--r-s); }

.opts { display: grid; gap: 10px; }
.opt {
  display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 10px 14px;
  text-align: left; border: 1.5px solid var(--line-strong); border-radius: var(--r-m); background: var(--sheet); touch-action: manipulation; line-height: 1.4;
}
.opt .k { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: var(--sunk); font-family: var(--f-mono); font-weight: 600; }
.opt[aria-pressed="true"] { border-color: var(--ink); background: color-mix(in srgb, var(--ink) 5%, var(--sheet)); }
.opt[aria-pressed="true"] .k { background: var(--ink); color: var(--paper); }
.opt .verdict { font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; }
.opt.is-right { border-color: var(--right); background: var(--right-soft); }
.opt.is-right .k { background: var(--right); color: #fff; }
.opt.is-right .verdict { color: var(--right); }
.opt.is-wrong { border-color: var(--wrong); background: var(--wrong-soft); }
.opt.is-wrong .k { background: var(--wrong); color: #fff; }
.opt.is-wrong .verdict { color: var(--wrong); }
.opt.is-missed { border-style: dashed; border-color: var(--right); }
.opt.is-missed .verdict { color: var(--right); }
.opt:disabled { cursor: default; color: inherit; opacity: 1; }

.answer-box { width: 100%; min-height: 120px; padding: 14px; border: 1.5px solid var(--line-strong); border-radius: var(--r-m); background: var(--paper); resize: vertical; line-height: 1.5; }
.q-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; align-items: center; }
.q-actions .spacer { flex: 1; }

.feedback { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.verdict-line { display: flex; align-items: center; gap: 10px; font-family: var(--f-display); font-weight: 800; font-size: 20px; margin-bottom: 10px; }
.verdict-line.ok { color: var(--right); }
.verdict-line.ko { color: var(--wrong); }
.verdict-line.part { color: var(--tombe); }
.model { padding: 16px 18px; background: var(--accent-soft); border-radius: var(--r-m); margin-bottom: 12px; }
.model h4 { font-family: var(--f-display); font-size: 13px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); margin: 0 0 6px; }
.keypoints { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 6px; }
.keypoints li { display: flex; gap: 10px; align-items: flex-start; }
.keypoints li::before { content: ""; flex: none; width: 18px; height: 18px; margin-top: 3px; border-radius: 5px; border: 2px solid var(--accent); }
.flag { display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--r-m); background: var(--tombe-soft); color: var(--ink); margin: 12px 0; font-size: 15.5px; }
.flag b { color: var(--tombe); }
.refs { font-size: 14.5px; color: var(--muted); margin-top: 10px; }
.refs a { color: var(--accent); font-weight: 600; }
.selfgrade { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.selfgrade button { flex: 1 1 120px; min-height: 48px; border-radius: var(--r-m); border: 1.5px solid var(--line-strong); background: var(--sheet); font-weight: 700; }
.selfgrade button[data-g="0"][aria-pressed="true"] { background: var(--wrong-soft); border-color: var(--wrong); color: var(--wrong); }
.selfgrade button[data-g="1"][aria-pressed="true"] { background: var(--tombe-soft); border-color: var(--tombe); color: var(--tombe); }
.selfgrade button[data-g="2"][aria-pressed="true"] { background: var(--right-soft); border-color: var(--right); color: var(--right); }

.result-hero { text-align: center; padding: 34px 20px; }
.result-hero .score { font-family: var(--f-display); font-size: 76px; font-weight: 800; letter-spacing: -0.04em; line-height: 1; }
.result-hero .score small { font-size: 30px; color: var(--muted); font-weight: 700; }
.review-list { display: grid; gap: 8px; margin-top: 20px; }
.review-item { display: grid; grid-template-columns: 30px 1fr auto; gap: 12px; align-items: center; padding: 12px 14px; border-radius: var(--r-m); background: var(--sheet); border: 1px solid var(--line); text-align: left; width: 100%; }
.review-item .mark { width: 26px; height: 26px; border-radius: 999px; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 14px; }
.mark.ok { background: var(--right); } .mark.ko { background: var(--wrong); } .mark.part { background: var(--tombe); } .mark.na { background: var(--line-strong); }

/* Practice launcher */
.launcher { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.launch { display: flex; flex-direction: column; gap: 8px; padding: 20px; text-align: left; border: 1px solid var(--line); background: var(--sheet); border-radius: var(--r-l); box-shadow: var(--shadow); min-height: 140px; text-decoration: none; }
.launch h3 { font-size: 18px; }
.launch p { margin: 0; color: var(--ink-2); font-size: 15.5px; }
.launch .go { margin-top: auto; font-weight: 700; color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 700; font-size: 14px; color: var(--muted); }
select, input[type="number"], input[type="text"] { min-height: 48px; padding: 0 14px; border: 1.5px solid var(--line-strong); border-radius: var(--r-m); background: var(--sheet); }
.check-list { display: flex; flex-wrap: wrap; gap: 8px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border-radius: 999px; border: 1.5px solid var(--line-strong); background: var(--sheet); font-weight: 600; font-size: 15px; }
.toggle[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* ---------- Flashcards ---------- */
.flash { max-width: 42rem; margin: 0 auto; }
.flashcard { position: relative; min-height: 330px; perspective: 1400px; }
.flashcard .face {
  position: absolute; inset: 0; display: flex; flex-direction: column; padding: 28px; border-radius: var(--r-l);
  background: var(--sheet); border: 1px solid var(--line); box-shadow: var(--shadow); backface-visibility: hidden; -webkit-backface-visibility: hidden;
  transition: transform 0.45s cubic-bezier(.2,.7,.2,1); overflow: auto;
}
.flashcard .front { justify-content: center; text-align: center; font-family: var(--f-display); font-size: 25px; font-weight: 700; letter-spacing: -0.015em; line-height: 1.3; }
.flashcard .back { transform: rotateY(180deg); }
.flashcard .back .eyebrow { text-transform: none; letter-spacing: 0; font-size: 15px; margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.flashcard.flipped .front { transform: rotateY(-180deg); }
.flashcard.flipped .back { transform: rotateY(0); }
.flashcard .face .hint { position: absolute; bottom: 16px; left: 0; right: 0; text-align: center; font-family: var(--f-body); font-size: 14px; font-weight: 400; color: var(--muted); }
.flash-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.flash-actions .btn { min-height: 56px; border-radius: var(--r-m); }
.btn.again { background: var(--wrong-soft); color: var(--wrong); }
.btn.knew { background: var(--right-soft); color: var(--right); }
.boxes { display: flex; gap: 6px; align-items: flex-end; height: 40px; }
.boxes i { flex: 1; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 3px; opacity: 0.85; }
.deck-list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.deck { display: flex; flex-direction: column; gap: 10px; padding: 18px; text-align: left; background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-l); box-shadow: var(--shadow); }
.deck .due { font-family: var(--f-display); font-weight: 800; font-size: 28px; line-height: 1; }

/* ---------- Calculs: interactive 2×2 table ---------- */
.calc { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .calc { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); } }
.scenario { font-size: 17px; }
.t22 { width: 100%; border-collapse: separate; border-spacing: 6px; font-family: var(--f-mono); }
.t22 th { font-family: var(--f-display); font-size: 14px; font-weight: 700; color: var(--muted); padding: 4px; text-align: center; }
.t22 th.row { text-align: right; }
.t22 td { text-align: center; height: 74px; border-radius: 12px; background: var(--sunk); font-size: 24px; font-weight: 600; position: relative; transition: background 0.15s, box-shadow 0.15s; }
.t22 td .cell-k { position: absolute; top: 6px; left: 9px; font-size: 12px; color: var(--muted); font-weight: 600; }
.t22 td.tot { background: transparent; border: 1.5px dashed var(--line-strong); font-size: 18px; color: var(--ink-2); }
.t22 td.num { box-shadow: inset 0 0 0 3px var(--accent); background: var(--accent-soft); }
.t22 td.den { box-shadow: inset 0 0 0 3px var(--tombe); }
.t22 td.num.den { box-shadow: inset 0 0 0 3px var(--accent), inset 0 0 0 6px var(--tombe); }
.measures { display: grid; gap: 10px; }
.measure { display: grid; grid-template-columns: 1fr 130px; gap: 10px; align-items: center; padding: 10px 12px; border-radius: var(--r-m); border: 1.5px solid var(--line); background: var(--sheet); }
.measure.focus { border-color: var(--accent); }
.measure label { font-weight: 700; }
.measure label small { display: block; font-weight: 400; color: var(--muted); font-family: var(--f-mono); font-size: 13px; }
.measure input { width: 100%; font-family: var(--f-mono); text-align: right; }
.measure.ok { border-color: var(--right); background: var(--right-soft); }
.measure.ko { border-color: var(--wrong); background: var(--wrong-soft); }
.measure .sol { grid-column: 1 / -1; font-family: var(--f-mono); font-size: 14.5px; color: var(--ink-2); }
.measure .sol .interp { font-family: var(--f-body); display: block; margin-top: 4px; color: var(--ink); }
.legend-22 { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13.5px; color: var(--muted); }
.legend-22 i { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; margin-right: 6px; }

/* Decision tree */
.tree { display: grid; gap: 12px; }
.tree-step { padding: 20px; border-radius: var(--r-l); background: var(--sheet); border: 1px solid var(--line); }
.tree-step h3 { margin-bottom: 12px; }
.tree-choices { display: grid; gap: 8px; }
.tree-choices button { min-height: 52px; padding: 10px 16px; border-radius: var(--r-m); border: 1.5px solid var(--line-strong); background: var(--sheet); text-align: left; font-weight: 600; }
.tree-choices button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.tree-result { padding: 20px; border-radius: var(--r-l); background: var(--accent-soft); border: 1.5px solid var(--accent); }

/* ---------- Search ---------- */
.search { width: min(720px, 94vw); max-height: 86dvh; padding: 0; border: 1px solid var(--line); border-radius: var(--r-l); background: var(--sheet); color: var(--ink); box-shadow: 0 30px 80px -20px rgb(0 0 0 / 0.4); margin-top: 6vh; }
.search::backdrop { background: rgb(10 20 17 / 0.4); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.search-bar { display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--line); }
.search-bar input { flex: 1; min-height: 48px; border: 0; background: transparent; font-size: 19px; outline: none; }
.search-results { overflow: auto; max-height: calc(86dvh - 80px); padding: 8px; }
.search-results a { display: block; padding: 12px 14px; border-radius: var(--r-m); text-decoration: none; }
.search-results a:hover, .search-results a:focus-visible { background: var(--sunk); }
.search-results .t { font-weight: 700; }
.search-results .s { font-size: 14.5px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.search-results mark { background: var(--tombe-soft); color: inherit; border-radius: 3px; }
.search-group { font-family: var(--f-mono); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); padding: 12px 14px 4px; }

.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 16px); transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 12px 18px; border-radius: 999px; font-weight: 600; z-index: 50; box-shadow: var(--shadow); }
@media (min-width: 1000px) { .toast { bottom: 24px; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
