/* ==========================================================================
   Base — reset, typographie, primitives de mise en page
   Dépend de tokens.css.
   ========================================================================== */

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

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
    /* Compense l'en-tête fixe : sans ça, toute ancre atterrit sous la barre. */
    scroll-padding-top: calc(var(--nav-h) + var(--s-6));
}

body {
    margin: 0;
    /* Décalage sous l'en-tête fixe, appliqué globalement : les pages n'ont
       pas toutes la même structure et chacune compensait à sa façon. */
    padding-top: var(--nav-h);
    background: var(--ground);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: var(--t-base);
    line-height: var(--lh-base);
    font-weight: var(--fw-normal);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    font-variant-numeric: tabular-nums;
}

/* ---- Titres ------------------------------------------------------------- */
h1, h2, h3, h4, h5, h6 {
    margin: 0 0 var(--s-4);
    color: var(--ink);
    font-weight: var(--fw-semi);
    line-height: var(--lh-tight);
    text-wrap: balance;
}
h1 { font-size: var(--t-3xl); font-weight: var(--fw-bold); letter-spacing: -0.02em; }
h2 { font-size: var(--t-2xl); letter-spacing: -0.015em; margin-top: var(--s-12); }
h3 { font-size: var(--t-xl);  letter-spacing: -0.01em;  margin-top: var(--s-8); }
h4 { font-size: var(--t-lg); }
h5 { font-size: var(--t-md); }
h6 {
    font-size: var(--t-xs);
    text-transform: uppercase;
    letter-spacing: var(--track-caps);
    color: var(--ink-3);
}
h1:first-child, h2:first-child, h3:first-child { margin-top: 0; }

/* ---- Texte courant ------------------------------------------------------ */
p, ul, ol, dl, table, pre, blockquote, figure { margin: 0 0 var(--s-4); }
p { text-wrap: pretty; }
li + li { margin-top: var(--s-1); }
strong, b { font-weight: var(--fw-semi); color: var(--ink); }
small { font-size: var(--t-2xs); }

/* Longueur de ligne : on la contraint sur la prose, pas sur l'interface. */
/* Corps rédactionnel : on borne la longueur de ligne du texte courant, mais
   pas les tableaux ni les grilles, qui ont besoin de toute la largeur.
   Le « :not([class]) » laisse passer tout élément déjà pris en charge par un
   composant — une liste de cartes n'est pas un paragraphe. */
.prose > p:not([class]),
.prose > ul:not([class]),
.prose > ol:not([class]),
.prose > h2:not([class]),
.prose > h3:not([class]),
.prose > h4:not([class]),
.prose > blockquote:not([class]) { max-width: var(--measure); }

a {
    color: var(--accent);
    text-decoration: none;
    text-underline-offset: 0.18em;
    text-decoration-thickness: 1px;
    transition: color var(--dur-1) var(--ease);
}
a:hover { color: var(--accent-hover); text-decoration: underline; }

code, kbd, samp, pre { font-family: var(--font-mono); font-size: 0.92em; }
code {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r-xs);
    padding: 0.1em 0.35em;
}
pre {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: var(--s-4);
    overflow-x: auto;
}
pre code { background: none; border: 0; padding: 0; }

kbd {
    display: inline-block;
    min-width: 1.6em;
    padding: 0.15em 0.45em;
    background: var(--surface-2);
    border: 1px solid var(--line-strong);
    border-bottom-width: 2px;
    border-radius: var(--r-xs);
    font-size: var(--t-2xs);
    line-height: 1.4;
    text-align: center;
    color: var(--ink-2);
}

blockquote {
    padding-left: var(--s-4);
    border-left: 2px solid var(--accent-line);
    color: var(--ink-2);
}

hr {
    height: 0;
    margin: var(--s-10) 0;
    border: 0;
    border-top: 1px solid var(--line);
}

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

/* Les filtres masquent par l'attribut hidden : il doit l'emporter sur les
   display: flex/grid des composants. */
[hidden] { display: none !important; }
svg { flex-shrink: 0; }

/* ---- Accessibilité ------------------------------------------------------ */
:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
    border-radius: var(--r-xs);
}
:focus:not(:focus-visible) { outline: none; }

.skip-link {
    position: absolute;
    left: var(--s-4);
    top: calc(-1 * var(--s-20));
    z-index: 2000;
    padding: var(--s-3) var(--s-5);
    background: var(--accent);
    color: var(--accent-ink);
    font-size: var(--t-sm);
    font-weight: var(--fw-semi);
    border-radius: var(--r-sm);
    transition: top var(--dur-2) var(--ease);
}
.skip-link:focus { top: var(--s-3); text-decoration: none; }

.visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    margin: -1px; padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

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

/* ---- Primitives de mise en page ----------------------------------------- */
.container {
    width: 100%;
    max-width: var(--container);
    margin-inline: auto;
    padding-inline: var(--s-6);
}
.container--article { max-width: var(--container-article); }
.container--narrow  { max-width: var(--container-narrow); }

.page-main { min-height: 60vh; }

.section { padding-block: var(--s-16); }
.section--tight { padding-block: var(--s-10); }
.section--alt { background: var(--surface-2); }

.stack       { display: flex; flex-direction: column; gap: var(--s-4); }
.stack--sm   { gap: var(--s-2); }
.stack--lg   { gap: var(--s-8); }
.row         { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.row--between{ justify-content: space-between; }
.row--tight  { gap: var(--s-2); }

.grid { display: grid; gap: var(--s-6); }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
/* Grille qui se réorganise seule : remplace les repeat(4,1fr) figés qui
   faisaient déborder la 5e colonne du pied de page. */
.grid--auto { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

@media (max-width: 900px) {
    .grid--3, .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
    .grid--2, .grid--3, .grid--4 { grid-template-columns: minmax(0, 1fr); }
    .container { padding-inline: var(--s-4); }
    h1 { font-size: var(--t-2xl); }
    h2 { font-size: var(--t-xl); }
    h3 { font-size: var(--t-lg); }
    .section { padding-block: var(--s-10); }
}

/* ---- Utilitaires de texte ----------------------------------------------- */
.text-mono   { font-family: var(--font-mono); font-variant-ligatures: none; }
.text-muted  { color: var(--ink-2); }
.text-faint  { color: var(--ink-3); }
.text-sm     { font-size: var(--t-sm); }
.text-xs     { font-size: var(--t-xs); }
.text-lead   { font-size: var(--t-md); color: var(--ink-2); line-height: var(--lh-snug); }
.eyebrow {
    font-size: var(--t-xs);
    font-weight: var(--fw-semi);
    text-transform: uppercase;
    letter-spacing: var(--track-caps);
    color: var(--ink-3);
}
.scroll-x { overflow-x: auto; overscroll-behavior-x: contain; }
