/* CLEAN CODE, le manuel illustré.
   Direction : fascicule d'imprimerie, papier crème, encre noire,
   un seul vermillon. Fraunces pour la voix, Plex Mono pour le code. */

:root {
  --papier: #f4eee1;
  --papier-2: #ece4d2;
  --encre: #201c16;
  --encre-2: #6d6455;
  --vermillon: #cf3e12;
  --filet: #c9bfa9;
  --ombre: rgba(32, 28, 22, 0.12);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  background: var(--papier);
  color: var(--encre);
  font-family: "Fraunces", Georgia, serif;
  font-weight: 400;
  line-height: 1.62;
  font-size: 19px;
  overflow-x: hidden;
}

/* le grain du papier */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='p'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23p)' opacity='0.045'/%3E%3C/svg%3E");
}

/* le fil de lecture, en haut */
.fil-lecture {
  position: fixed;
  top: 0; left: 0;
  height: 4px;
  width: 0;
  background: var(--vermillon);
  z-index: 60;
}

code {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.82em;
  background: var(--papier-2);
  padding: 0.08em 0.35em;
  border-radius: 3px;
}

/* le repère de lecture, sur la tranche droite */
#repere {
  position: fixed;
  right: 26px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 55;
  display: none;
  flex-direction: column;
  gap: 13px;
  text-align: right;
}
@media (min-width: 1280px) { #repere { display: flex; } }
#repere a {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11.5px;
  color: var(--encre-2);
  opacity: 0.6;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
  transition: opacity 0.25s ease, color 0.25s ease;
}
/* le titre de la section, toujours visible */
#repere a::before {
  content: attr(data-titre);
  font-style: italic;
  font-family: "Fraunces", serif;
  font-size: 13px;
  color: inherit;
  white-space: nowrap;
}
/* le numéro, en colonne bien alignée */
#repere a .num { min-width: 2.2em; text-align: right; }
/* le tiret, hors du texte, dans sa propre case */
#repere a::after {
  content: "";
  width: 22px;
  height: 1.5px;
  background: currentColor;
  transform: scaleX(0.42);
  transform-origin: right;
  transition: transform 0.25s ease;
}
#repere a:hover { opacity: 1; }
#repere a.ici {
  color: var(--vermillon);
  opacity: 1;
  font-weight: 500;
}
#repere a.ici::after { transform: scaleX(1); }
/* au-dessus d'un interlude noir, la ligne s'inverse en ivoire */
#repere a.inverse { color: #b3a992; }
#repere a.inverse.ici { color: #f0b26a; }

/* ═══════ la couverture ═══════ */
.couverture {
  min-height: 92vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 8vh 24px 4vh;
}
.filet-double {
  width: min(560px, 80vw);
  border-top: 2px solid var(--encre);
  border-bottom: 1px solid var(--encre);
  height: 6px;
}
.surtitre {
  margin: 26px 0 8px;
  font-variant: small-caps;
  letter-spacing: 0.22em;
  font-size: 15px;
  color: var(--encre-2);
}
.couverture h1 {
  font-size: clamp(64px, 14vw, 170px);
  font-weight: 900;
  font-variation-settings: "opsz" 144;
  line-height: 0.92;
  letter-spacing: -0.015em;
  margin: 12px 0 18px;
}
.couverture h1 em {
  font-style: italic;
  font-weight: 300;
  color: var(--vermillon);
}
.edition {
  font-variant: small-caps;
  letter-spacing: 0.18em;
  font-size: 14px;
  color: var(--encre-2);
  margin-bottom: 26px;
}
.avertissement {
  max-width: 34em;
  margin-top: 34px;
  font-style: italic;
  font-size: 21px;
  line-height: 1.55;
}
.fleche {
  margin-top: 7vh;
  font-size: 26px;
  color: var(--vermillon);
  animation: descendre 2.2s ease-in-out infinite;
}
@keyframes descendre {
  0%, 100% { transform: translateY(0); opacity: 0.55; }
  50% { transform: translateY(10px); opacity: 1; }
}

/* ═══════ les chapitres ═══════ */
.chapitre {
  position: relative;
  max-width: 700px;
  margin: 0 auto;
  padding: 13vh 24px 6vh;
}
.numero {
  position: absolute;
  top: 6vh;
  right: -0.06em;
  font-size: clamp(130px, 20vw, 260px);
  font-weight: 900;
  font-variation-settings: "opsz" 144;
  line-height: 1;
  color: transparent;
  -webkit-text-stroke: 1.5px var(--filet);
  z-index: -1;
  user-select: none;
}
.folio {
  display: block;
  font-variant: small-caps;
  font-weight: 400;
  letter-spacing: 0.24em;
  font-size: 14px;
  color: var(--vermillon);
  margin-bottom: 10px;
}
/* le nom canonique du principe, tamponné à côté du folio */
.tampon {
  display: inline-block;
  font-family: "IBM Plex Mono", monospace;
  font-variant: normal;
  letter-spacing: 0.04em;
  font-size: 11.5px;
  color: var(--encre-2);
  border: 1px solid var(--filet);
  border-radius: 11px;
  padding: 2px 10px;
  margin-left: 10px;
  transform: rotate(-1.2deg) translateY(-2px);
}
.chapitre h2 {
  font-size: clamp(34px, 5.4vw, 52px);
  font-weight: 600;
  font-variation-settings: "opsz" 144;
  line-height: 1.08;
  margin-bottom: 26px;
  max-width: 13em;
}
.chapitre > p { max-width: 36em; }

/* les notes de marge, dans la marge de gauche : la tranche droite
   appartient au repère de lecture, ils ne se croisent jamais */
.marge {
  position: absolute;
  top: 40%;
  right: calc(100% + 28px);
  width: 200px;
  font-size: 14.5px;
  font-style: italic;
  line-height: 1.5;
  text-align: right;
  color: var(--encre-2);
  border-top: 1px solid var(--filet);
  padding-top: 10px;
}
.asterisque { color: var(--vermillon); font-style: normal; }
@media (max-width: 1180px) {
  .marge {
    position: static;
    width: auto;
    max-width: 30em;
    margin-top: 28px;
    text-align: left;
  }
}

/* ═══════ les machines à manipuler ═══════ */
.machine {
  margin: 44px 0 8px;
  border: 1.5px solid var(--encre);
  background: #faf6ec;
  box-shadow: 6px 6px 0 var(--ombre);
  padding: 26px 26px 20px;
}
.machine figcaption {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px dashed var(--filet);
  font-style: italic;
  font-size: 16.5px;
  color: var(--encre-2);
  min-height: 2.2em;
  transition: color 0.3s ease;
}
.machine figcaption.eclaire { color: var(--vermillon); }

.pupitre {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 22px;
  font-variant: small-caps;
  letter-spacing: 0.14em;
  font-size: 14px;
  color: var(--encre-2);
}

/* le code imprimé */
.code {
  font-family: "IBM Plex Mono", monospace;
  font-size: 15.5px;
  line-height: 1.75;
  background: var(--papier-2);
  border: 1px solid var(--filet);
  padding: 18px 20px;
  overflow-x: auto;
  white-space: pre;
}
.code.petit { font-size: 13.5px; padding: 12px 16px; }
.kw { color: var(--vermillon); }
.fn { font-weight: 500; }
.cm { color: var(--encre-2); font-style: italic; }
.lit { color: #1e56a0; }
.nom {
  font-weight: 500;
  background: #f3d9a8;
  padding: 0 3px;
  border-radius: 2px;
  transition: background 0.4s ease;
}

/* les curseurs, façon règle à calcul */
input[type="range"] {
  appearance: none;
  flex: 1;
  max-width: 300px;
  height: 26px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  background: var(--encre);
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 26px;
  margin-top: -11.5px;
  background: var(--vermillon);
  border: 1.5px solid var(--encre);
  border-radius: 2px;
}
input[type="range"]::-moz-range-track { height: 3px; background: var(--encre); }
input[type="range"]::-moz-range-thumb {
  width: 12px; height: 24px;
  background: var(--vermillon);
  border: 1.5px solid var(--encre);
  border-radius: 2px;
}

/* les boutons, façon caractère de plomb */
.bouton {
  font-family: "IBM Plex Mono", monospace;
  font-size: 14px;
  letter-spacing: 0.06em;
  padding: 10px 22px;
  background: var(--encre);
  color: var(--papier);
  border: none;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--ombre);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.bouton:hover { background: var(--vermillon); }
.bouton:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ombre); }

/* 01 · le cadran de compréhension */
#machine-nommer { display: grid; grid-template-columns: 1fr 210px; gap: 8px 26px; align-items: center; }
#machine-nommer .code { grid-column: 1; }
#machine-nommer .pupitre { grid-column: 1; }
#machine-nommer figcaption { grid-column: 1 / -1; }
.cadran { grid-column: 2; grid-row: 1 / 3; text-align: center; }
.cadran svg { width: 100%; }
/* l'aiguille est animée en JS, comme un vrai galvanomètre qui dépasse et se pose */
.gradu { font-family: "IBM Plex Mono", monospace; font-size: 10px; fill: var(--encre-2); }
.legende-cadran {
  font-variant: small-caps;
  letter-spacing: 0.16em;
  font-size: 12.5px;
  color: var(--encre-2);
}
@media (max-width: 720px) {
  #machine-nommer { display: block; }
  .cadran { max-width: 220px; margin: 14px auto 0; }
  .numero { right: 0; } /* le grand numéro ne déborde jamais du papier */
}

/* 02 · l'atelier de découpe */
.atelier { position: relative; }
.bloc-trio { display: none; }
.bloc-trio .mini { margin-top: 10px; margin-left: 34px; position: relative; }
.bloc-trio .mini::before {
  content: "↳";
  position: absolute;
  left: -24px;
  color: var(--vermillon);
}
#machine-fonctions.decoupe .bloc-monstre { display: none; }
#machine-fonctions.decoupe .bloc-trio { display: block; }
/* le monstre se fait découper : il se plie avant de céder la place */
#machine-fonctions.casse .bloc-monstre {
  animation: cede 0.42s cubic-bezier(0.55, 0, 0.8, 0.4) forwards;
  transform-origin: 50% 0;
}
@keyframes cede {
  30%  { transform: rotate(0.8deg) scaleY(0.98); }
  100% { transform: rotate(-1.6deg) scaleY(0.04) translateY(20px); opacity: 0; }
}
/* et les morceaux retombent un à un, avec le petit rebond du plomb qui se cale */
#machine-fonctions.decoupe .bloc-trio > * {
  animation: retombe 0.55s cubic-bezier(0.34, 1.45, 0.64, 1) backwards;
}
#machine-fonctions.decoupe .bloc-trio > *:nth-child(2) { animation-delay: 0.12s; }
#machine-fonctions.decoupe .bloc-trio > *:nth-child(3) { animation-delay: 0.24s; }
#machine-fonctions.decoupe .bloc-trio > *:nth-child(4) { animation-delay: 0.36s; }
@keyframes retombe {
  from { opacity: 0; transform: translateY(-26px) rotate(-1.4deg); }
  to   { opacity: 1; transform: translateY(0) rotate(0); }
}
.pli { color: var(--encre-2); letter-spacing: 0.3em; }

/* 03 · la bascule et le schéma */
.bascule { display: flex; gap: 0; margin-bottom: 18px; }
.onglet {
  font-family: "IBM Plex Mono", monospace;
  font-size: 13.5px;
  padding: 9px 18px;
  background: transparent;
  border: 1.5px solid var(--encre);
  border-right-width: 0;
  cursor: pointer;
  color: var(--encre);
}
.onglet:last-child { border-right-width: 1.5px; }
.onglet.actif { background: var(--encre); color: var(--papier); }
.duo { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; align-items: center; }
@media (max-width: 720px) { .duo { grid-template-columns: 1fr; } }
.schema { width: 100%; }
.etiquette { font-family: "IBM Plex Mono", monospace; font-size: 9.5px; fill: var(--encre-2); }

/* 04 · le nombre magique */
.magique {
  font-family: inherit;
  font-size: inherit;
  border: none;
  cursor: pointer;
  background: #f3d9a8;
  color: var(--encre);
  padding: 0 4px;
  border-radius: 2px;
  position: relative;
  animation: scintille 1.6s ease-in-out infinite;
}
@keyframes scintille {
  0%, 100% { background: #f3d9a8; }
  50% { background: #ecc26f; }
}
.magique::after {
  content: "?";
  position: absolute;
  top: -14px;
  right: -10px;
  font-size: 13px;
  font-weight: 900;
  color: var(--vermillon);
  font-family: "Fraunces", serif;
}
.magique.revele {
  animation: none;
  background: transparent;
  color: var(--vermillon);
  font-weight: 500;
  cursor: default;
}
.magique.revele::after { content: ""; }

/* 05 · les jumeaux */
.carte-code { min-width: 0; }
.titre-carte {
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
  margin-bottom: 8px;
  color: var(--encre-2);
}
.tampon-copie {
  display: inline-block;
  font-size: 11px;
  border: 1px solid var(--vermillon);
  color: var(--vermillon);
  padding: 1px 7px;
  border-radius: 10px;
  transform: rotate(-2deg);
  margin-left: 8px;
}
.date-fictive {
  font-family: "IBM Plex Mono", monospace;
  font-size: 13.5px;
  color: var(--vermillon);
  min-width: 9em;
}
.derive { background: #f6c9b6; border-radius: 2px; }

/* 06 · la verrière */
.verriere {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  background: var(--encre);
  border: 6px solid var(--encre);
  border-radius: 3px;
}
.carreau {
  aspect-ratio: 1;
  background: linear-gradient(135deg, #dfe8e4 0%, #cfdbd6 55%, #c2d0ca 100%);
  border: none;
  cursor: default;
  position: relative;
  transition: background 0.35s ease;
}
.carreau.fele { cursor: pointer; }
.carreau.fele:hover { background: #e8dcc9; }
.carreau svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.carreau .brisure { stroke: var(--encre); stroke-width: 1.6; fill: none; opacity: 0.85; }
.carreau.repare .brisure { display: none; }
.carreau.repare::after {
  content: "✳";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--vermillon);
  font-size: 20px;
  animation: repare 0.6s ease;
}
@keyframes repare {
  from { transform: scale(2.2) rotate(40deg); opacity: 0; }
  to   { transform: scale(1) rotate(0); opacity: 1; }
}

/* ═══════ les interludes ═══════ */
.interlude {
  background: var(--encre);
  color: var(--papier);
  text-align: center;
  padding: 13vh 24px;
  margin: 12vh 0;
}
.interlude p:first-child {
  font-size: clamp(28px, 4.6vw, 46px);
  font-weight: 300;
  font-variation-settings: "opsz" 144;
  line-height: 1.25;
  max-width: 21em;
  margin: 0 auto;
}
.interlude em { font-style: italic; color: #f0b26a; }
.attribution {
  margin-top: 26px;
  font-variant: small-caps;
  letter-spacing: 0.18em;
  font-size: 14px;
  color: #a89d89;
}

/* les fêlures s'aggravent quand on les ignore */
.carreau .brisure-2, .carreau .brisure-3 { opacity: 0; }
.carreau.stade-2 .brisure-2 { opacity: 0.85; transition: opacity 0.8s ease; }
.carreau.stade-3 .brisure-3 { opacity: 0.85; transition: opacity 0.8s ease; }

/* les formats à emporter, pour les machines */
.formats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin: 34px 0 10px;
}
@media (max-width: 720px) { .formats { grid-template-columns: 1fr; } }
.format {
  display: block;
  border: 1.5px solid var(--encre);
  background: #faf6ec;
  box-shadow: 4px 4px 0 var(--ombre);
  padding: 16px 18px;
  text-decoration: none;
  color: var(--encre);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.format:hover { transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--ombre); }
.format:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ombre); }
.format-nom {
  display: block;
  font-family: "IBM Plex Mono", monospace;
  font-weight: 500;
  font-size: 15px;
  color: var(--vermillon);
  margin-bottom: 6px;
}
.format-nom::before { content: "↓ "; }
.format-pour { font-size: 14px; font-style: italic; color: var(--encre-2); line-height: 1.45; }
.regles {
  max-height: 340px;
  overflow-y: auto;
  white-space: pre-wrap;
  margin-top: 14px;
}

/* le petit bouton du son */
#son {
  position: fixed;
  right: 18px;
  bottom: 16px;
  z-index: 60;
  font-family: "IBM Plex Mono", monospace;
  font-size: 11.5px;
  color: var(--encre-2);
  background: var(--papier);
  border: 1px solid var(--filet);
  border-radius: 12px;
  padding: 4px 12px;
  cursor: pointer;
}
#son[aria-pressed="true"] { color: var(--vermillon); border-color: var(--vermillon); }

/* ═══════ l'annexe lexique ═══════ */
.lexique { margin-top: 34px; }
.lexique > div {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 18px;
  padding: 13px 0;
  border-top: 1px solid var(--filet);
  align-items: baseline;
}
.lexique > div:last-child { border-bottom: 1px solid var(--filet); }
.lexique dt {
  font-family: "IBM Plex Mono", monospace;
  font-weight: 500;
  font-size: 16px;
  color: var(--vermillon);
}
.lexique dd { font-size: 17px; }
.lexique dd em { color: var(--encre-2); font-size: 15px; }
.lexique .sous { border-top: 1px dashed var(--filet); }
.lexique .sous dt { padding-left: 34px; color: var(--encre); }

/* ═══════ le colophon ═══════ */
.colophon {
  text-align: center;
  padding: 14vh 24px 10vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.devise {
  font-size: clamp(26px, 4vw, 40px);
  font-weight: 600;
  font-variation-settings: "opsz" 144;
  line-height: 1.25;
  margin: 40px 0 30px;
}
.devise em { font-style: italic; font-weight: 300; color: var(--vermillon); }
.composition {
  font-variant: small-caps;
  letter-spacing: 0.14em;
  font-size: 14px;
  color: var(--encre-2);
  max-width: 34em;
  line-height: 2;
}
.signature { color: var(--vermillon); text-decoration-color: var(--filet); }
