@layer tokens, base, layout, composants;

@layer composants {
    .interrupteur-theme:has(input[type="checkbox"]) {
        position: relative; display: inline-flex; align-items: center; padding: 2px;
        min-height: 48px; cursor: pointer;
    }
    .interrupteur-theme input {
        position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0;
    }
    .rail-theme {
        display: block; width: 80px; height: 38px; border: 3px solid var(--primaire); border-radius: 2rem;
        background: var(--surface);
    }
    .curseur-theme {
        display: grid; place-items: center; width: 40px; height: 40px; margin-top: -4px;
        margin-left: -3px; border-radius: 50%; color: var(--sur-primaire);
        background: var(--primaire);
        transition: transform .2s ease;
    }
    .curseur-theme svg { grid-area: 1 / 1; width: 24px; height: 24px }
    .lune-theme { display: none }
    .interrupteur-theme input:checked + .rail-theme .curseur-theme {
        transform: translateX(40px);
    }
    .interrupteur-theme input:checked + .rail-theme .soleil-theme { display: none }
    .interrupteur-theme input:checked + .rail-theme .lune-theme { display: block }
    .interrupteur-theme input:focus-visible + .rail-theme { outline: var(--anneau); outline-offset: 5px }
    @media (prefers-reduced-motion: reduce) {
        .curseur-theme { transition: none }
    }
    @media (forced-colors: active) {
        .rail-theme, .curseur-theme { border: 2px solid ButtonText }
        .curseur-theme { color: ButtonText }
    }
    .recherche { display: grid; align-items: end; gap: var(--e4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)) }
    .formulaire { max-width: 38rem }
    .pile > button { justify-self: start }
    label { font-weight: 600 }
    label:has(input[type="checkbox"]) { display: block; min-height: 44px; padding-block: var(--e2) }
    input[type="checkbox"] { width: 1.15rem; height: 1.15rem; vertical-align: middle; accent-color: var(--primaire) }
    [aria-invalid="true"] { border: 2px solid var(--danger) }
    .danger { background: var(--danger); border-color: var(--danger); color: var(--sur-danger) }
    .zone-danger { border-inline-start: .35rem solid var(--danger) }
    .alerte { display: flex; align-items: baseline; gap: var(--e2); padding: var(--e3) var(--e4); background: var(--surface); border-inline-start: .3rem solid currentColor; color: var(--info) }
    .alerte svg { flex: none; align-self: flex-start; margin-top: .2em }
    .alerte[role="alert"], .danger-statut { color: var(--danger) }
    .badge { display: inline-block; padding: .1em .65em; border: 1px solid currentColor; border-radius: 2em; font-size: var(--petit); font-weight: 650 }
    .etiquette { display: inline-block; padding: .1em .65em; border: 1px solid currentColor; border-radius: .35em; font-size: var(--petit); font-weight: 650 }
    .etiquette-place, .etiquette-bientot, .etiquette-complet { color: #fff }
    .etiquette-place { background: #175c36 }
    .etiquette-bientot { background: #784b00 }
    .etiquette-complet { background: #992e36 }
    .etiquette-neutre { color: var(--doux) }
    .visuellement-masque { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0 }
    .succes { color: var(--succes) }
    .info { color: var(--info) }
    .alerte-statut { color: var(--alerte) }
    .neutre { color: var(--doux) }
    .cartes article { position: relative; border-top: .3rem solid var(--primaire) }
    .cartes ul { display: flex; flex-wrap: wrap; gap: var(--e2); margin: 0; padding: 0; list-style: none }
    .lien-carte::after { content: ""; position: absolute; inset: 0; border-radius: var(--rayon) }
    .lien-carte:focus-visible::after { outline: var(--anneau); outline-offset: 3px }
    .epreuves { padding-inline-start: var(--e5) }
    .epreuves li + li { margin-top: var(--e3) }
    .comparaison { display: grid; gap: var(--e4) }
    @media (min-width: 48rem) {
        .comparaison { grid-template-columns: repeat(2, minmax(0, 1fr)) }
    }
    @media (forced-colors: active) {
        button, .bouton, .badge, .etiquette { border: 1px solid ButtonText }
    }
}

@layer tokens {
    :root {
        color-scheme: light dark;
        --fond: light-dark(#f3f6f4, #131d1a); --surface: light-dark(#fff, #202e29);
        --texte: light-dark(#192f28, #edf4ef); --doux: light-dark(#465e55, #bccbc3);
        --bord: light-dark(#75867e, #889f93); --primaire: light-dark(#075c47, #88dec0);
        --sur-primaire: light-dark(#fff, #102f24); --lien: light-dark(#075c82, #94d8fa);
        --focus: light-dark(#7442a4, #e2bcff); --danger: light-dark(#992e36, #ffa6ad);
        --sur-danger: light-dark(#fff, #40161d); --succes: light-dark(#175c36, #a4e8b3);
        --alerte: light-dark(#784b00, #ffd28b); --info: var(--lien);
        --e1: .25rem; --e2: .5rem; --e3: .75rem; --e4: 1rem;
        --e5: 1.5rem; --e6: 2rem; --e7: 3rem; --e8: 4rem;
        --petit: .875rem; --corps: 1rem; --titre: clamp(2rem, 5vw, 3.75rem);
        --intertitre: clamp(1.4rem, 3vw, 2rem); --rayon: .75rem;
        --ombre: 0 .25rem 1rem #192f280c; --anneau: 3px solid var(--focus);
    }
}

@layer base {
    * { box-sizing: border-box }
    body { margin: 0; background: var(--fond); color: var(--texte); font: var(--corps)/1.6 system-ui, sans-serif; overflow-wrap: anywhere }
    h1, h2, h3 { line-height: 1.15; text-wrap: balance; margin: 0 0 .6em }
    h1 { font-size: var(--titre); letter-spacing: -.035em }
    h2 { font-size: var(--intertitre) }
    a { color: var(--lien); text-underline-offset: .2em }
    a:hover, a[aria-current="page"] { text-decoration-thickness: .16em }
    :focus-visible { outline: var(--anneau); outline-offset: 3px }
    img { display: block; max-width: 100%; max-height: 32rem; object-fit: contain }
    article img { max-height: 12rem }
    input, select, button { font: inherit; max-width: 100%; min-width: 0 }
    input:not([type="checkbox"], [type="hidden"]), select {
        display: block; width: 100%; min-height: 44px; margin-top: var(--e1); padding: var(--e2);
        color: var(--texte); background: var(--surface); border: 1px solid var(--bord); border-radius: .35rem;
    }
    button, .bouton {
        display: inline-flex; align-items: center; justify-content: center; min-height: 44px;
        padding: var(--e2) var(--e4); font-weight: 650; color: var(--sur-primaire);
        background: var(--primaire); border: 1px solid var(--primaire); border-radius: .45rem;
        cursor: pointer; text-align: center; text-decoration: none;
    }
    :is(button, .bouton):hover { text-decoration: underline }
    .secondaire { color: var(--primaire); background: var(--surface) }
    .evitement { position: absolute; z-index: 2; top: 0; left: var(--e4); padding: var(--e3); background: var(--surface) }
    .evitement:not(:focus) { clip-path: inset(100%); pointer-events: none }
}

@layer layout {
    .conteneur { width: min(72rem, calc(100% - 2rem)); margin-inline: auto }
    main { padding-block: clamp(2rem, 6vw, 4rem); min-height: 65vh }
    .bandeau, footer { background: var(--surface); padding-block: var(--e4); border-block: 1px solid var(--bord) }
    .bandeau { border-top: .35rem solid var(--primaire) }
    .barre, .grappe { display: flex; flex-wrap: wrap; align-items: center; gap: var(--e2) var(--e4) }
    .barre { justify-content: space-between }
    nav a, .marque { display: inline-flex; align-items: center; min-height: 44px }
    .marque { gap: var(--e2); color: var(--texte); text-decoration: none }
    .marque img { width: 4.5rem; height: auto; padding: .25rem; background: #fff; border-radius: .35rem }
    .nom-marque, .signature-marque { display: block; line-height: 1.2 }
    .nom-marque { font-size: 1.4rem; font-weight: 800; letter-spacing: -.045em }
    .nom-marque span { color: var(--primaire) }
    .signature-marque { font-size: .75rem }
    .rubrique { display: block; color: var(--doux); font-size: var(--petit); font-weight: 650; letter-spacing: .06em }
    .pile { display: grid; gap: var(--e4); align-content: start }
    .pile > * { min-width: 0; margin-block: 0 }
    .grille { display: grid; gap: var(--e5); grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr)) }
    .lecture { max-width: 66ch }
    .panneau, article { background: var(--surface); padding: clamp(1rem, 3vw, 2rem); border: 1px solid var(--bord); border-radius: var(--rayon); box-shadow: var(--ombre) }
}
