:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #efede6;
  --fg: #1d2330;
  --muted: #5d6677;
  --line: #dcd8cc;
  --accent: #1f5fbf;
  --accent-soft: #e3ecfa;
  --ok: #1b7a45;
  --ok-soft: #e1f3e8;
  --bad: #b3261e;
  --bad-soft: #fbe6e4;
  --code-bg: #1e2430;
  --code-fg: #e6e9ef;
  --warn-soft: #fdf3d6;
  --radius: 10px;
  --mono: ui-monospace, 'Cascadia Code', Consolas, 'Courier New', monospace;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171d;
    --surface: #1c2029;
    --surface-2: #232834;
    --fg: #e7e9ee;
    --muted: #a0a8b8;
    --line: #333a48;
    --accent: #7fb0ff;
    --accent-soft: #1f2d45;
    --ok: #6fd39a;
    --ok-soft: #173326;
    --bad: #ff8a80;
    --bad-soft: #3a1c1a;
    --code-bg: #0f1218;
    --code-fg: #e6e9ef;
    --warn-soft: #3a3214;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
}
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.6;
}
a {
  color: var(--accent);
}
code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--surface-2);
  padding: 0.1em 0.35em;
  border-radius: 5px;
}
h1,
h2,
h3 {
  line-height: 1.25;
  text-wrap: balance;
}
h1 {
  font-size: 1.9rem;
  margin: 0 0 0.4rem;
}
h2 {
  font-size: 1.3rem;
  margin: 2.2rem 0 0.7rem;
}
h3 {
  font-size: 1.05rem;
  margin: 1.4rem 0 0.4rem;
}
p {
  margin: 0 0 0.9rem;
}

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: 700;
  text-decoration: none;
  color: var(--fg);
}
.brand span {
  color: var(--muted);
  font-weight: 400;
}
.menu-btn {
  display: none;
}

.layout {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  max-width: 1280px;
  margin: 0 auto;
}
.nav {
  position: sticky;
  top: 49px;
  align-self: start;
  height: calc(100vh - 49px);
  overflow-y: auto;
  padding: 1rem 0.8rem 2rem;
  border-right: 1px solid var(--line);
  font-size: 0.93rem;
}
.nav h4 {
  margin: 1.1rem 0.5rem 0.3rem;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.nav a {
  display: block;
  padding: 0.32rem 0.6rem;
  border-radius: 7px;
  color: var(--fg);
  text-decoration: none;
}
.nav a:hover {
  background: var(--surface-2);
}
.nav a.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.nav a code {
  background: none;
  padding: 0;
}
.nav .done::after {
  content: ' ✓';
  color: var(--ok);
}

.main {
  padding: 1.6rem clamp(1rem, 4vw, 3rem) 4rem;
  min-width: 0;
  outline: none;
}
.lead {
  font-size: 1.1rem;
  color: var(--muted);
  max-width: 70ch;
}
.prose {
  max-width: 75ch;
}
.file {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 0.8rem;
}
a.card {
  display: block;
  text-decoration: none;
  color: var(--fg);
}
a.card:hover {
  border-color: var(--accent);
}
.card h3 {
  margin: 0 0 0.3rem;
}
.card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.93rem;
}

.image {
  background: var(--warn-soft);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  max-width: 75ch;
}
.image b {
  display: block;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Le trajet d'une détection */
.flow {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: stretch;
  margin: 1rem 0;
}
.flow .step {
  flex: 1 1 150px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.7rem 0.8rem;
  font-size: 0.9rem;
}
.flow .step b {
  display: block;
}
.flow .step.focus {
  border: 2px solid var(--accent);
  background: var(--accent-soft);
}
.flow .step.dim {
  opacity: 0.6;
}
.flow .step small {
  color: var(--muted);
}

.tree {
  font-family: var(--mono);
  font-size: 0.86rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  overflow-x: auto;
}
.tree div {
  white-space: nowrap;
}
.tree .focus {
  color: var(--accent);
  font-weight: 700;
}
.tree .dim {
  color: var(--muted);
}
.tree span.note {
  font-family: var(--sans);
  color: var(--muted);
  font-weight: 400;
}

/* Le code ligne par ligne */
.steps {
  display: grid;
  gap: 0.8rem;
  margin-top: 0.8rem;
}
.step-row {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.step-row pre {
  margin: 0;
  padding: 0.8rem 1rem;
  background: var(--code-bg);
  color: var(--code-fg);
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.55;
  overflow-x: auto;
}
.step-row .explain {
  padding: 0.8rem 1rem;
  font-size: 0.97rem;
}
.step-row .num {
  display: inline-block;
  margin-bottom: 0.45rem;
  padding: 0.05rem 0.6rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
}
.step-row .explain p {
  margin: 0 0 0.55rem;
}
.step-row .explain p:last-child {
  margin-bottom: 0;
}
ul.avant {
  margin: 0;
  padding-left: 1.1rem;
}
ul.avant li {
  margin-bottom: 0.5rem;
}
.io {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.8rem;
}
.io ul {
  margin: 0;
  padding-left: 1.1rem;
}
.jury {
  border-left: 4px solid var(--accent);
}
.pager {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 2.5rem;
  flex-wrap: wrap;
}

a.mot {
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  color: inherit;
  cursor: help;
}
dl.glossaire dt {
  font-weight: 700;
  margin-top: 1.1rem;
  scroll-margin-top: 70px;
}
dl.glossaire dd {
  margin: 0.2rem 0 0;
  max-width: 75ch;
}
dl.glossaire dt.target {
  color: var(--accent);
}

/* Quiz */
.btn {
  font: inherit;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.btn:hover {
  border-color: var(--accent);
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
  font-weight: 600;
}
.btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.quiz {
  max-width: 760px;
}
.progress {
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
  margin: 0.6rem 0 1.2rem;
}
.progress div {
  height: 100%;
  background: var(--accent);
}
.question {
  font-size: 1.12rem;
  font-weight: 600;
  margin-bottom: 1rem;
}
.choices {
  display: grid;
  gap: 0.55rem;
}
.choice {
  text-align: left;
  width: 100%;
}
.choice.good {
  background: var(--ok-soft);
  border-color: var(--ok);
}
.choice.wrong {
  background: var(--bad-soft);
  border-color: var(--bad);
}
.order-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.order-item span {
  flex: 1;
}
.order-item .btn {
  padding: 0.15rem 0.55rem;
}
.order-item.good {
  background: var(--ok-soft);
  border-color: var(--ok);
}
.order-item.wrong {
  background: var(--bad-soft);
  border-color: var(--bad);
}
.feedback {
  margin-top: 1rem;
  padding: 0.9rem 1.1rem;
  border-radius: var(--radius);
}
.feedback.good {
  background: var(--ok-soft);
}
.feedback.wrong {
  background: var(--bad-soft);
}
.feedback b.verdict {
  display: block;
  margin-bottom: 0.3rem;
}
.quiz-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}
.score {
  font-size: 2.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.badge {
  display: inline-block;
  font-size: 0.78rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .menu-btn {
    display: inline-block;
    font: inherit;
    padding: 0.3rem 0.8rem;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--fg);
  }
  .nav {
    display: none;
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .nav.open {
    display: block;
  }
  .step-row {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Où j'en suis */
.summary {
  margin: 1.2rem 0;
  max-width: 760px;
}
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem 2rem;
}
.summary b {
  display: block;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.summary .big {
  font-size: 1.7rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.summary .progress {
  margin: 0.3rem 0 0;
}
.summary .next {
  margin: 1rem 0 0;
}
.summary .next b {
  display: inline;
  font-size: inherit;
  letter-spacing: 0;
  text-transform: none;
  color: inherit;
}
.cards.wide {
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.card .progress {
  margin: 0.3rem 0 0.7rem;
}
.badge.ok {
  background: var(--ok-soft);
  color: var(--ok);
}
.badge.mid {
  background: var(--accent-soft);
  color: var(--accent);
}
.badge.bad {
  background: var(--bad-soft);
  color: var(--bad);
}
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  max-width: 900px;
}
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.93rem;
}
th,
td {
  text-align: left;
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
tr:last-child td {
  border-bottom: none;
}
th {
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}
td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
ol.worst {
  margin: 0;
  padding-left: 1.2rem;
}
ol.worst li {
  margin-bottom: 0.6rem;
}
