/*
 * Cardinale — feuille de style du site.
 *
 * Le monde de l'application, porté au web sans traduction : deux valeurs, l'encre et le
 * papier, et des trames de Bayer là où une autre feuille poserait un gris. Les jetons
 * viennent de `src/theme/tokens.ts`, la grammaire de `DESIGN.md`.
 *
 * Un seul écart assumé sur l'application : le survol. `DESIGN.md` le refuse — l'application
 * est tactile. Sur un site consulté à la souris, un lien sans retour est un défaut ; le
 * retour employé est donc l'inversion, le seul mécanisme d'état du système.
 */

/* --------------------------------------------------------------- La police */

/*
 * Cardinale Pixel — dérivée de Jersey 25 (SIL OFL 1.1), capitale K redessinée.
 * Voir assets/OFL.txt. Sous-ensemble latin, 4,9 ko.
 */
@font-face {
  font-family: "Cardinale Pixel";
  src: url("cardinale-pixel.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* --------------------------------------------------------------- Les jetons */

:root {
  /* Système à un bit, encre marine. Le mode sombre est la pile retournée. */
  --paper: #ffffff;
  --ink: #0e2a47;
  --ink-muted: #5c7590;
  --rule: #b9c6d4;
  --on-ink: #ffffff;

  /* Le trait qui structure, à la place des fonds gris. */
  --stroke: 2px;
  --radius: 6px;
  --radius-cell: 4px;
  --radius-rail: 3px;

  /* Rythme d'espacement du monde : 8 / 10 / 16 / 20, prolongé pour une page. */
  --s1: 8px;
  --s2: 10px;
  --s3: 16px;
  --s4: 20px;
  --s5: 32px;
  --s6: 48px;
  --s7: 72px;

  --measure: 62ch;
  --page: 760px;

  /*
   * Trames de Bayer 4 × 4, tuile de 8 px, point de 2 px — le rendu de `Dither` à
   * l'échelle 2. Elles servent de masque : la couleur vient de l'encre du thème, si bien
   * qu'un seul jeu de motifs couvre les deux modes.
   */
  --dither-light: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Cpath fill='%23000' d='M0 0h2v2H0zM4 0h2v2H4zM0 4h2v2H0zM4 4h2v2H4z'/%3E%3C/svg%3E");
  --dither-medium: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Cpath fill='%23000' d='M0 0h2v2H0zM4 0h2v2H4zM2 2h2v2H2zM6 2h2v2H6zM0 4h2v2H0zM4 4h2v2H4zM2 6h2v2H2zM6 6h2v2H6z'/%3E%3C/svg%3E");
  --dither-heavy: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Cpath fill='%23000' d='M0 0h8v2H0zM2 2h2v2H2zM6 2h2v2H6zM0 4h8v2H0zM2 6h2v2H2zM6 6h2v2H6z'/%3E%3C/svg%3E");
}

/*
 * À couverture égale, une trame claire sur fond sombre paraît plus dense — les points
 * brillants s'étalent à l'œil. `ditherFor()` descend chaque palier d'un cran en mode
 * inversé ; ici, chaque variable désigne simplement le motif du cran inférieur.
 */
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #071522;
    --ink: #eaf1f8;
    --ink-muted: #8fa6bc;
    --rule: #24405c;
    --on-ink: #071522;

    --dither-light: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Cpath fill='%23000' d='M0 0h2v2H0zM4 4h2v2H4z'/%3E%3C/svg%3E");
    --dither-medium: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Cpath fill='%23000' d='M0 0h2v2H0zM4 0h2v2H4zM0 4h2v2H0zM4 4h2v2H4z'/%3E%3C/svg%3E");
    --dither-heavy: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Cpath fill='%23000' d='M0 0h2v2H0zM4 0h2v2H4zM2 2h2v2H2zM6 2h2v2H6zM0 4h2v2H0zM4 4h2v2H4zM2 6h2v2H2zM6 6h2v2H6z'/%3E%3C/svg%3E");
  }
}

/* --------------------------------------------------------------- Le socle */

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

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

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  /* La voix qui se lit : police système, lisible en français, suit la taille choisie. */
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    sans-serif;
  font-size: 16px;
  line-height: 24px;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

/*
 * La voix qui nomme : titres, intitulés, boutons, chiffres, clés. La frontière est le mot
 * et non le corps — « Série en cours » est un nom et passe en bitmap, une phrase reste en
 * police système.
 */
h1,
h2,
h3,
.pixel,
.label,
.btn,
.figure,
.chip,
.nav a,
.brand__name {
  font-family: "Cardinale Pixel", "Courier New", monospace;
  font-weight: 400;
}

p,
li,
dd,
figcaption,
label,
input,
select,
textarea {
  font-family: inherit;
}

a {
  color: inherit;
}

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

hr {
  border: 0;
  border-top: var(--stroke) solid var(--ink);
  margin: var(--s5) 0;
}

::selection {
  background: var(--ink);
  color: var(--paper);
}

:focus-visible {
  outline: var(--stroke) solid var(--ink);
  outline-offset: 3px;
}

/* Un lien d'évitement, visible dès qu'il prend le focus. */
.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 10;
  background: var(--paper);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius);
  padding: var(--s2) var(--s3);
  font-family: "Cardinale Pixel", monospace;
}

.skip:focus {
  left: var(--s3);
  top: var(--s3);
}

/* --------------------------------------------------------------- La page */

.shell {
  max-width: var(--page);
  margin: 0 auto;
  padding: 0 var(--s4);
}

main {
  padding-bottom: var(--s7);
}

/* --------------------------------------------------------------- L'en-tête */

.masthead {
  border-bottom: var(--stroke) solid var(--ink);
  margin-bottom: var(--s6);
}

.masthead .shell {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding-top: var(--s3);
  padding-bottom: var(--s3);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  text-decoration: none;
}

.brand svg {
  display: block;
  width: 22px;
  height: 22px;
  fill: var(--ink);
}

.brand__name {
  font-size: 22px;
  line-height: 26px;
  letter-spacing: 0.5px;
}

.nav {
  display: flex;
  gap: var(--s1);
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav a {
  display: block;
  padding: 6px var(--s2);
  font-size: 15px;
  line-height: 20px;
  text-decoration: none;
  border: var(--stroke) solid transparent;
  border-radius: var(--radius-cell);
}

/* L'inversion est le seul mécanisme d'état du système. */
.nav a:hover,
.nav a:focus-visible {
  border-color: var(--ink);
}

.nav a[aria-current="page"] {
  background: var(--ink);
  color: var(--on-ink);
  border-color: var(--ink);
}

/* --------------------------------------------------------------- Le titrage */

h1 {
  font-size: 44px;
  line-height: 50px;
  letter-spacing: 0.5px;
  margin: 0 0 var(--s3);
}

h2 {
  font-size: 26px;
  line-height: 32px;
  margin: var(--s6) 0 var(--s3);
}

h3 {
  font-size: 19px;
  line-height: 26px;
  margin: var(--s4) 0 var(--s1);
}

/* Intitulés de section, en capitales suivies comme la source. */
.label {
  font-size: 15px;
  line-height: 20px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
}

.lede {
  font-size: 19px;
  line-height: 29px;
  max-width: var(--measure);
  margin: 0 0 var(--s4);
}

p,
ul,
ol,
dl {
  max-width: var(--measure);
}

p {
  margin: 0 0 var(--s3);
}

.muted {
  color: var(--ink-muted);
}

/* Deux réglages de marge, en classes plutôt qu'en attribut `style` — voir `.gauge--*`. */
.u-flush {
  margin: 0;
}

.u-tight {
  margin: 0 0 6px;
}

.caption {
  font-size: 13px;
  line-height: 19px;
  color: var(--ink-muted);
  max-width: var(--measure);
}

/* Chiffres à chasse fixe : sans eux, un compteur qui passe de 9 à 10 déplace ce qui l'entoure. */
.figure {
  font-variant-numeric: tabular-nums;
  font-size: 20px;
  line-height: 26px;
}

/* --------------------------------------------------------------- La fenêtre */

/*
 * La brique du monde : un rectangle cerné d'un trait de 2 points, jamais une carte à
 * ombre douce. La profondeur est un semis de points décalé de 6 points vers le bas-droite
 * — la façon dont une interface à un bit a toujours figuré une ombre.
 */
.pane {
  position: relative;
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
  margin: 0 0 var(--s4);
}

.pane::after {
  content: "";
  position: absolute;
  inset: 6px -6px -6px 6px;
  border-radius: var(--radius);
  background-color: var(--ink);
  -webkit-mask-image: var(--dither-medium);
  mask-image: var(--dither-medium);
  -webkit-mask-size: 8px 8px;
  mask-size: 8px 8px;
  -webkit-mask-repeat: repeat;
  mask-repeat: repeat;
  z-index: -1;
  pointer-events: none;
}

/* Une fenêtre empilée renonce à son ombre : sur le même bord, elles se brouillent. */
.pane--flat::after {
  display: none;
}

.pane__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: var(--s1) 12px;
  border-bottom: var(--stroke) solid var(--ink);
  border-radius: var(--radius-cell) var(--radius-cell) 0 0;
}

/* Trois cases au coin d'une barre de titre : ce rectangle est une fenêtre, pas un bloc. */
.pane__widgets {
  display: flex;
  gap: 4px;
  flex: none;
}

.pane__widgets i {
  display: block;
  width: 9px;
  height: 9px;
  border: var(--stroke) solid var(--ink);
}

.pane__body {
  padding: var(--s3);
}

.pane__body > :last-child {
  margin-bottom: 0;
}

/* --------------------------------------------------------------- Le relevé */

/*
 * Intitulé, conduite pointillée, valeur. Le pointillé porte le regard de l'un à l'autre —
 * c'est le filet intérieur du monde, jamais un fond.
 */
.ledger {
  margin: 0;
  padding: 0;
  list-style: none;
  max-width: none;
}

/*
 * Une ligne de relevé, comme `LedgerRow` : intitulé, conduite, valeur. Pas de filet entre
 * deux lignes — la conduite suffit à porter le regard, et deux pointillés à quatre pixels
 * l'un de l'autre se brouillent.
 */
.ledger li {
  display: flex;
  align-items: baseline;
  gap: var(--s1);
  min-height: 40px;
  padding: var(--s1) 0;
  max-width: none;
}

/* `flex-shrink: 1`, comme `LedgerRow` : sur un téléphone, « Flammes numériques et
   substituts » déborderait de la fenêtre plutôt que de repasser à la ligne. */
.ledger dt,
.ledger .ledger__name {
  font-family: "Cardinale Pixel", monospace;
  font-size: 18px;
  line-height: 24px;
  flex: 0 1 auto;
  overflow-wrap: anywhere;
}

.ledger__lead {
  flex: 1 1 auto;
  border-bottom: 1px dotted var(--rule);
  transform: translateY(-4px);
  min-width: var(--s4);
}

.ledger__value {
  flex: none;
  font-family: "Cardinale Pixel", monospace;
  font-variant-numeric: tabular-nums;
  font-size: 18px;
  line-height: 24px;
}

/* --------------------------------------------------------------- La jauge */

.gauge {
  height: 10px;
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-rail);
  overflow: hidden;
  display: flex;
  margin: 6px 0 0;
}

/* La part vue : une trame. La part acquise : l'aplat plein. Les deux s'emboîtent. */
.gauge__seen {
  background-color: var(--ink);
  -webkit-mask-image: var(--dither-heavy);
  mask-image: var(--dither-heavy);
  -webkit-mask-size: 8px 8px;
  mask-size: 8px 8px;
}

.gauge__mastered {
  background: var(--ink);
}

/*
 * Les deux jauges d'exemple de la page d'accueil. Leurs proportions vivent ici et non
 * dans un attribut `style` : la page peut alors être servie sous une politique de
 * sécurité qui refuse tout style en ligne.
 */
.gauge--recognise .gauge__mastered {
  width: 34%;
}
.gauge--recognise .gauge__seen {
  width: 42%;
}
.gauge--produce .gauge__mastered {
  width: 11%;
}
.gauge--produce .gauge__seen {
  width: 38%;
}

/* --------------------------------------------------------------- L'échelle */

/* L'échelle de Leitner, 1-3-7-14-30-60-120, acquis au quatrième palier. */
.ladder {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s1);
  list-style: none;
  margin: 0 0 var(--s3);
  padding: 0;
  max-width: none;
}

.ladder li {
  max-width: none;
  min-width: 62px;
  flex: 1 1 62px;
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-cell);
  padding: var(--s1) 4px;
  text-align: center;
}

/* Acquis : l'aplat plein. C'est l'inversion, pas une teinte d'état. */
.ladder li[data-mastered] {
  background: var(--ink);
  color: var(--on-ink);
}

.ladder__step {
  display: block;
  font-size: 11px;
  line-height: 15px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  font-family: "Cardinale Pixel", monospace;
}

.ladder__days {
  display: block;
  font-family: "Cardinale Pixel", monospace;
  font-variant-numeric: tabular-nums;
  font-size: 22px;
  line-height: 28px;
}

/* --------------------------------------------------------------- Les cartes */

.grid {
  display: grid;
  gap: var(--s4);
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin: 0 0 var(--s4);
}

.grid .pane {
  margin: 0;
}

/* --------------------------------------------------------------- Les pavillons */

.flags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s3);
  list-style: none;
  margin: 0 0 var(--s5);
  padding: 0;
  max-width: none;
}

.flags li {
  max-width: none;
  text-align: center;
}

/* `figure` porte 40 px de marge latérale par défaut : la gouttière ne serait plus la nôtre. */
.flags figure {
  margin: 0;
}

.flags svg {
  display: block;
  width: 96px;
  height: 72px;
}

.flags figcaption {
  font-family: "Cardinale Pixel", monospace;
  font-size: 12px;
  line-height: 16px;
  letter-spacing: 0.4px;
  color: var(--ink-muted);
  margin-top: 6px;
}

/* --------------------------------------------------------------- Les boutons */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  align-items: center;
  margin: 0 0 var(--s4);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 12px var(--s4);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  font-size: 19px;
  line-height: 26px;
  text-decoration: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

/* L'appui inverse. C'est le seul retour dont une interface à un bit dispose. */
.btn:hover,
.btn:focus-visible,
.btn:active {
  background: var(--ink);
  color: var(--on-ink);
}

.btn--solid {
  background: var(--ink);
  color: var(--on-ink);
}

.btn--solid:hover,
.btn--solid:focus-visible,
.btn--solid:active {
  background: var(--paper);
  color: var(--ink);
}

/* Une pastille d'information, cernée comme tout le reste. */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-cell);
  padding: 5px var(--s2);
  font-size: 13px;
  line-height: 18px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

/* --------------------------------------------------------------- Le formulaire */

.form {
  max-width: var(--measure);
}

.field {
  margin: 0 0 var(--s4);
}

.field > label {
  display: block;
  font-family: "Cardinale Pixel", monospace;
  font-size: 15px;
  line-height: 20px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.field__hint {
  display: block;
  font-size: 13px;
  line-height: 19px;
  color: var(--ink-muted);
  margin-bottom: 6px;
}

/*
 * Aucun contrôle système visible : ni le champ d'iOS, ni la liste déroulante native
 * dessinée par le navigateur. Un seul suffirait à trahir tout ce qui l'entoure.
 */
.field input,
.field select,
.field textarea {
  display: block;
  width: 100%;
  min-height: 52px;
  padding: 13px 14px;
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
  line-height: 24px;
  -webkit-appearance: none;
  appearance: none;
}

.field textarea {
  min-height: 168px;
  resize: vertical;
}

.field select {
  /* Le chevron est dessiné sur la grille de 24, épaisseur 2, extrémités carrées. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' fill='none' stroke='%235c7590' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 44px;
}

@media (prefers-color-scheme: dark) {
  .field select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' fill='none' stroke='%238fa6bc' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  }
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--ink-muted);
}

.field-row {
  display: grid;
  gap: var(--s3);
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.field-row .field {
  margin-bottom: var(--s4);
}

/* --------------------------------------------------------------- Le corps de texte */

.prose h2 {
  padding-top: var(--s3);
  border-top: var(--stroke) solid var(--ink);
}

.prose ul,
.prose ol {
  padding-left: var(--s4);
  margin: 0 0 var(--s3);
}

.prose li {
  margin-bottom: 6px;
}

.prose dl {
  margin: 0 0 var(--s3);
}

.prose dt {
  font-family: "Cardinale Pixel", monospace;
  font-size: 18px;
  line-height: 24px;
  margin-top: var(--s3);
}

.prose dd {
  margin: 4px 0 0;
  max-width: var(--measure);
}

.prose a {
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.prose a:hover,
.prose a:focus-visible {
  background: var(--ink);
  color: var(--on-ink);
  text-decoration: none;
}

/* --------------------------------------------------------------- Le pied */

.colophon {
  border-top: var(--stroke) solid var(--ink);
  padding: var(--s4) 0 var(--s5);
}

.colophon .shell {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s3);
  align-items: baseline;
  justify-content: space-between;
}

.colophon p {
  margin: 0;
  font-size: 13px;
  line-height: 19px;
  color: var(--ink-muted);
}

.colophon ul {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s3);
  list-style: none;
  margin: 0;
  padding: 0;
}

.colophon a {
  font-family: "Cardinale Pixel", monospace;
  font-size: 14px;
  line-height: 19px;
  text-decoration: none;
  border-bottom: 1px dotted var(--rule);
}

.colophon a:hover,
.colophon a:focus-visible {
  border-bottom-color: var(--ink);
}

/* --------------------------------------------------------------- L'étroit */

@media (max-width: 560px) {
  :root {
    --s6: 36px;
    --s7: 48px;
  }

  h1 {
    font-size: 34px;
    line-height: 40px;
  }

  h2 {
    font-size: 22px;
    line-height: 28px;
  }

  .masthead .shell {
    align-items: flex-start;
  }

  .flags svg {
    width: 72px;
    height: 54px;
  }
}

/* Le trait porte tout : sans lui, il ne resterait rien à l'impression. */
@media print {
  .pane::after,
  .skip,
  .nav {
    display: none;
  }
  body {
    background: #fff;
    color: #000;
  }
}
