/* ==========================================================================
   La loi de Benford : feuille de style commune
   --------------------------------------------------------------------------
   Identité « registre comptable » : papier légèrement vert, filets de registre,
   encre verte pour ce qui est observé, encre rouge pour ce que prédit la loi.
   Thème sombre : le même registre, de nuit.
   Aucune ressource externe : uniquement des polices installées sur l’appareil.
   ========================================================================== */

:root {
  color-scheme: light;

  --fond: #f7f9f6;
  --surface: #edf2eb;
  --texte: #17251f;
  --texte-doux: #4f5e57;
  --filet: #c5d3c6;
  --filet-leger: #dde6dc;
  --observe: #1d5c46;           /* encre verte : données observées */
  --theorie: #b42318;           /* encre rouge : loi de Benford */
  --zone: rgba(180, 35, 24, 0.14);
  --lien: #1d5c46;
  --bouton-fond: #17251f;
  --bouton-texte: #f7f9f6;
  --focus: #b42318;

  --police-texte: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "URW Palladio L", Georgia, serif;
  --police-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --colonne: 41rem;
  --colonne-large: 58rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --fond: #121a17;
    --surface: #1a2420;
    --texte: #e4ece6;
    --texte-doux: #a5b4ac;
    --filet: #33443c;
    --filet-leger: #24312b;
    --observe: #7fd1ac;
    --theorie: #f1897d;
    --zone: rgba(241, 137, 125, 0.18);
    --lien: #7fd1ac;
    --bouton-fond: #e4ece6;
    --bouton-texte: #121a17;
    --focus: #f1897d;
  }
}

/* ---------- Base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font-family: var(--police-texte);
  font-size: 1.125rem;
  line-height: 1.7;
}

a {
  color: var(--lien);
  text-underline-offset: 0.15em;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

canvas,
svg,
img {
  max-width: 100%;
}

/* ---------- En-tête et navigation ---------- */

.entete {
  max-width: var(--colonne-large);
  margin: 0 auto;
  padding: 1.1rem 1.25rem 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  font-family: var(--police-ui);
  font-size: 0.92rem;
}

.entete__titre {
  color: var(--texte);
  font-weight: 700;
  text-decoration: none;
}

.navigation ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.navigation a {
  color: var(--texte-doux);
  text-decoration: none;
}

.navigation a:hover {
  color: var(--texte);
  text-decoration: underline;
}

.navigation a[aria-current="page"] {
  color: var(--texte);
  font-weight: 600;
}

/* ---------- Contenu ---------- */

main {
  padding: 0 1.25rem;
}

.texte {
  max-width: var(--colonne);
  margin: 0 auto;
}

h1,
h2,
h3 {
  line-height: 1.2;
  font-weight: 700;
}

h1 {
  font-size: clamp(2.1rem, 6vw, 3rem);
  margin: 2.25rem 0 1rem;
}

h2 {
  font-size: 1.6rem;
  margin: 3rem 0 0.75rem;
}

h3 {
  font-size: 1.2rem;
  margin: 2rem 0 0.5rem;
}

.chapo {
  font-size: 1.3rem;
  line-height: 1.55;
  color: var(--texte-doux);
  margin: 0 0 2rem;
}

var {
  font-style: italic;
}

.formule {
  margin: 1.25rem 0;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-left: 3px solid var(--theorie);
  font-size: 1.2rem;
  overflow-x: auto;
}

.encadre {
  margin: 1.5rem 0;
  padding: 1rem 1.25rem;
  border: 1px solid var(--filet);
  border-left: 3px solid var(--observe);
}

.encadre p:first-child {
  margin-top: 0;
}

.encadre p:last-child {
  margin-bottom: 0;
}

.mot-observe {
  color: var(--observe);
  font-weight: 600;
}

.mot-theorie {
  color: var(--theorie);
  font-weight: 600;
}

.references li {
  margin-bottom: 0.5rem;
}

.chiffres-tabulaires {
  font-variant-numeric: tabular-nums lining-nums;
}

/* ---------- La une : les neuf chiffres à leur taille de Benford ---------- */

.une {
  max-width: var(--colonne-large);
  margin: 0 auto;
}

.une h1 {
  max-width: var(--colonne);
  margin-left: auto;
  margin-right: auto;
}

/* Chaque chiffre a une hauteur proportionnelle à sa fréquence selon la loi :
   la ligne de chiffres est elle-même un diagramme en barres. */
.chiffres {
  --taille-1: clamp(5.5rem, 24vw, 13rem);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.25rem;
  margin: 1.5rem 0 0.5rem;
  padding-bottom: 0.25rem;
  border-bottom: 2px solid var(--texte);
  font-family: var(--police-texte);
  font-variant-numeric: lining-nums;
  line-height: 0.8;
}

.chiffre {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1 1 0;
  min-width: 0;
}

.chiffre__glyphe {
  font-size: calc(var(--taille-1) * var(--part) / 0.30103);
  font-weight: 700;
  transition: font-size 1.2s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.chiffre:first-child .chiffre__glyphe {
  color: var(--observe);
}

/* État de départ de l’animation d’ouverture : neuf chiffres égaux. */
.chiffres--egaux .chiffre__glyphe {
  font-size: calc(var(--taille-1) * 0.1111 / 0.30103);
}

.chiffres-legende {
  display: flex;
  justify-content: space-between;
  gap: 0.25rem;
  margin: 0 0 1.5rem;
  font-family: var(--police-ui);
  font-size: clamp(0.68rem, 2.2vw, 0.9rem);
  font-variant-numeric: tabular-nums;
  color: var(--texte-doux);
}

.chiffres-legende span {
  flex: 1 1 0;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .chiffre__glyphe {
    transition: none;
  }
}

/* ---------- Laboratoire (zone interactive) ---------- */

.labo {
  max-width: var(--colonne-large);
  margin: 2rem auto;
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--filet);
  border-radius: 3px;
}

.labo h2 {
  margin-top: 0;
}

.labo > p {
  max-width: var(--colonne);
}

.commandes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 1rem 1.5rem;
  margin: 1rem 0;
  font-family: var(--police-ui);
  font-size: 0.95rem;
}

.champ {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.champ[hidden] {
  display: none;
}

.champ__nom {
  font-weight: 600;
}

.champ output {
  font-variant-numeric: tabular-nums;
  font-weight: 400;
}

select,
input[type="range"],
input[type="number"],
input[type="file"],
textarea {
  font: inherit;
  accent-color: var(--observe);
}

select,
input[type="number"],
textarea {
  padding: 0.4rem 0.5rem;
  color: var(--texte);
  background: var(--fond);
  border: 1px solid var(--filet);
  border-radius: 3px;
}

input[type="number"],
input[type="range"],
textarea {
  width: 100%;
}

textarea {
  font-variant-numeric: tabular-nums;
  line-height: 1.45;
  resize: vertical;
}

.options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin: 1rem 0;
  font-family: var(--police-ui);
  font-size: 0.95rem;
}

.case {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
}

.bouton {
  padding: 0.55rem 1.1rem;
  font: 600 0.98rem var(--police-ui);
  color: var(--bouton-texte);
  background: var(--bouton-fond);
  border: 1px solid var(--bouton-fond);
  border-radius: 3px;
  cursor: pointer;
}

.bouton:hover {
  opacity: 0.88;
}

.bouton--discret {
  color: var(--texte);
  background: transparent;
  border-color: var(--filet);
}

.bouton:disabled {
  opacity: 0.45;
  cursor: default;
}

.erreur {
  margin: 1rem 0 0;
  padding: 0.5rem 0.75rem;
  font-family: var(--police-ui);
  font-size: 0.92rem;
  font-weight: 600;
  border-left: 3px solid var(--texte);
}

.erreur[hidden] {
  display: none;
}

.note {
  margin: 0.75rem 0 0;
  font-family: var(--police-ui);
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--texte-doux);
}

/* ---------- Histogramme des chiffres ---------- */

.histo {
  margin: 1rem 0 0;
  font-family: var(--police-ui);
}

.histo__titre {
  margin: 0 0 0.4rem;
  font-size: 0.9rem;
  font-weight: 600;
}

/* Zone de tracé : la marge gauche accueille les graduations. */
.histo__trace {
  position: relative;
  height: clamp(11rem, 32vw, 15rem);
  margin-left: 2.6rem;
  border-bottom: 1px solid var(--texte-doux);
  background: var(--fond);
}

.histo__graduation {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px solid var(--filet-leger);
}

.histo__graduation span {
  position: absolute;
  right: 100%;
  margin-right: 0.35rem;
  transform: translateY(-50%);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--texte-doux);
  white-space: nowrap;
}

.histo__colonnes {
  position: absolute;
  inset: 0;
  display: flex;
  gap: 6%;
  padding: 0 2%;
}

.histo--serre .histo__colonnes {
  gap: 1px;
  padding: 0 1px;
}

.histo__col {
  position: relative;
  flex: 1 1 0;
}

.histo__zone {
  position: absolute;
  left: -12%;
  right: -12%;
  background: var(--zone);
}

.histo--serre .histo__zone {
  left: 0;
  right: 0;
}

.histo__barre {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 0;
  background: var(--observe);
}

.histo--serre .histo__barre {
  left: 0;
  right: 0;
}

.histo__attendu {
  position: absolute;
  left: -14%;
  right: -14%;
  height: 0;
  border-top: 2.5px solid var(--theorie);
}

.histo--serre .histo__attendu {
  left: 0;
  right: 0;
  border-top-width: 2px;
}

.histo__axe {
  display: flex;
  gap: 6%;
  margin-left: 2.6rem;
  padding: 0.3rem 2% 0;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.histo--serre .histo__axe {
  gap: 1px;
  padding: 0.3rem 1px 0;
  font-size: 0.72rem;
}

.histo__axe span {
  flex: 1 1 0;
  text-align: center;
  white-space: nowrap;
}

.histo--serre .histo__axe span {
  overflow: visible;
}

.histo__legende {
  margin: 0.6rem 0 0;
  font-family: var(--police-ui);
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--texte-doux);
}

/* Deux histogrammes côte à côte quand la place le permet. */
.duo {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr));
  gap: 1.25rem 2rem;
}

/* ---------- Mesures chiffrées ---------- */

.mesures {
  margin-top: 1.25rem;
  font-family: var(--police-ui);
  font-size: 0.92rem;
}

.mesures dl {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 0.75rem 1.5rem;
  margin: 0;
}

.mesures dt {
  color: var(--texte-doux);
}

.mesures dd {
  margin: 0.1rem 0 0;
  font-size: 1.08rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---------- Tableaux (style registre) ---------- */

.tableau-defile {
  overflow-x: auto;
  margin: 1rem 0;
}

.tableau {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--police-ui);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.tableau caption {
  text-align: left;
  margin-bottom: 0.5rem;
  color: var(--texte-doux);
}

.tableau th,
.tableau td {
  padding: 0.4rem 0.6rem;
  text-align: right;
  border-bottom: 1px solid var(--filet-leger);
}

.tableau th:first-child,
.tableau td:first-child {
  text-align: left;
}

.tableau thead th {
  border-bottom: 2px solid var(--texte-doux);
  font-weight: 600;
}

.tableau .hors-plage {
  color: var(--theorie);
  font-weight: 600;
}

details {
  margin-top: 0.75rem;
  font-family: var(--police-ui);
  font-size: 0.92rem;
}

summary {
  cursor: pointer;
  color: var(--lien);
}

/* ---------- Règle logarithmique ---------- */

.regle {
  width: 100%;
  min-width: 640px; /* lisible sur petit écran : la règle défile horizontalement */
  height: auto;
  margin: 1rem 0 0.5rem;
  font-family: var(--police-ui);
}

.regle .segment {
  fill: var(--surface);
  stroke: var(--texte);
  stroke-width: 1;
}

.regle .segment--un {
  fill: var(--observe);
}

.regle .etiquette {
  fill: var(--texte);
  font-size: 15px;
  font-weight: 600;
}

.regle .etiquette--claire {
  fill: var(--fond);
}

.regle .graduation {
  fill: var(--texte-doux);
  font-size: 13px;
}

.regle .part {
  fill: var(--texte-doux);
  font-size: 12px;
}

/* ---------- Sommaire des pages ---------- */

.sommaire {
  list-style: none;
  margin: 1.5rem 0;
  padding: 0;
  border-top: 1px solid var(--filet);
}

.sommaire li {
  padding: 1.1rem 0;
  border-bottom: 1px solid var(--filet);
}

.sommaire h3 {
  margin: 0 0 0.25rem;
  font-size: 1.25rem;
}

.sommaire p {
  margin: 0;
  color: var(--texte-doux);
}

/* ---------- Pied de page ---------- */

.pied {
  margin-top: 4rem;
  padding: 0 1.25rem 3rem;
  font-family: var(--police-ui);
  font-size: 0.88rem;
  color: var(--texte-doux);
}

.pied__contenu {
  max-width: var(--colonne);
  margin: 0 auto;
  padding-top: 1.5rem;
  border-top: 1px solid var(--filet);
}

.pied p {
  margin: 0.4rem 0;
}

/* Texte réservé aux lecteurs d’écran. */
.visuellement-cache {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Nombre géant affiché par l’expérience des multiplications. */
.nombre-courant {
  margin: 1rem 0 0;
  font-family: var(--police-ui);
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}

.nombre-courant strong {
  font-family: var(--police-texte);
  font-size: 1.6rem;
  font-variant-numeric: lining-nums tabular-nums;
}

.nombre-courant .premier-chiffre {
  color: var(--observe);
}

/* Les 90 colonnes du test des deux premiers chiffres défilent sur petit écran. */
@media (max-width: 36rem) {
  .histo--serre {
    overflow-x: auto;
  }

  .histo--serre .histo__trace,
  .histo--serre .histo__axe {
    min-width: 34rem;
  }
}
