/*
 * Styles de l'application.
 *
 * N'utilise que les variables de tokens.css : aucune couleur ni dimension en
 * dur ici.
 */

*, *::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);
    font-size: var(--t-base);
    line-height: 1.6;
    /* Réserve la place de la barre de défilement pour éviter que la page ne
       sursaute en passant d'une vue courte à une vue longue. */
    scrollbar-gutter: stable;
}

h1, h2, h3 { font-family: var(--police-titre); line-height: 1.25; margin: 0; font-weight: 600; }
h1 { font-size: var(--t-titre); }
h2 { font-size: var(--t-grand); }
h3 { font-size: var(--t-moyen); }

p { margin: 0; }
img { max-width: 100%; display: block; }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent-fort); }

/* Anneau de focus visible uniquement au clavier : indispensable pour la
   navigation sans souris, invisible au clic à la souris. */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--r-petit);
}

/* --- Mise en page ------------------------------------------------------- */

.enveloppe {
    max-width: var(--largeur-max);
    margin: 0 auto;
    padding: var(--e4);
}

.entete {
    position: sticky;
    top: 0;
    z-index: 10;
    background: color-mix(in srgb, var(--fond) 88%, transparent);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--bord);
}

.entete__interieur {
    max-width: var(--largeur-max);
    margin: 0 auto;
    padding: var(--e3) var(--e4);
    display: flex;
    align-items: center;
    gap: var(--e3);
}

.marque {
    font-family: var(--police-titre);
    font-size: var(--t-grand);
    font-weight: 600;
    color: var(--texte);
    text-decoration: none;
    margin-right: auto;
}

.marque:hover { color: var(--accent); }

/* --- Boutons ------------------------------------------------------------ */

.bouton {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--e2);
    min-height: var(--tactile);
    padding: var(--e2) var(--e4);
    border: 1px solid transparent;
    border-radius: var(--r);
    background: var(--accent);
    color: var(--sur-accent);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background-color .15s, border-color .15s;
}

.bouton:hover { background: var(--accent-fort); color: var(--sur-accent); }

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

.bouton--discret:hover { background: var(--fond-doux); color: var(--texte); }

.bouton--nu {
    background: transparent;
    color: var(--texte-doux);
    border-color: transparent;
    padding: var(--e2);
}

.bouton--nu:hover { background: var(--fond-doux); color: var(--texte); }

.bouton[disabled] { opacity: .5; cursor: not-allowed; }

/* --- Cartes ------------------------------------------------------------- */

.carte {
    background: var(--carte);
    border: 1px solid var(--bord);
    border-radius: var(--r-grand);
    box-shadow: var(--ombre);
}

/* --- Écran de connexion ------------------------------------------------- */

.connexion {
    min-height: 100dvh;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: var(--e5);
    padding: var(--e5);
    text-align: center;
}

.connexion__titre { font-size: 2.5rem; }
.connexion__accroche { color: var(--texte-doux); max-width: 26rem; }

.connexion__bouton {
    /* Le bouton Google s'injecte dans ce conteneur ; il faut lui réserver sa
       hauteur pour éviter que la page ne se décale à son apparition. */
    min-height: 44px;
    display: grid;
    place-items: center;
}

/* --- Messages ----------------------------------------------------------- */

.message {
    padding: var(--e3) var(--e4);
    border-radius: var(--r);
    border: 1px solid var(--bord);
    background: var(--carte);
    color: var(--texte-doux);
}

.message--erreur {
    border-color: color-mix(in srgb, var(--danger) 40%, var(--bord));
    background: color-mix(in srgb, var(--danger) 8%, var(--carte));
    color: var(--texte);
}

/* --- Compte ------------------------------------------------------------- */

.compte { display: flex; align-items: center; gap: var(--e2); }

.compte__avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--r-rond);
    border: 1px solid var(--bord);
}

.compte__nom { font-size: var(--t-petit); color: var(--texte-doux); }

@media (max-width: 30rem) {
    .compte__nom { display: none; }
}

/* --- États divers ------------------------------------------------------- */

.vide {
    text-align: center;
    color: var(--texte-doux);
    padding: var(--e7) var(--e4);
    display: grid;
    gap: var(--e3);
    justify-items: center;
}

.chargement {
    color: var(--texte-faible);
    padding: var(--e6);
    text-align: center;
}

/* Masque visuellement sans retirer du flux d'accessibilité : le texte reste
   annoncé par les lecteurs d'écran. */
.lecteur-seul {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
    }
}

/* --- Barre de titre et actions ------------------------------------------ */

.barre {
    display: flex;
    align-items: center;
    gap: var(--e3);
    flex-wrap: wrap;
    margin-bottom: var(--e4);
}

.barre__actions { margin-left: auto; display: flex; gap: var(--e2); }

.decompte { color: var(--texte-faible); font-size: var(--t-petit); margin-bottom: var(--e3); }
.faible { color: var(--texte-doux); }

.lien-retour {
    display: inline-block;
    color: var(--texte-doux);
    text-decoration: none;
    font-size: var(--t-petit);
    margin-bottom: var(--e3);
}

.lien-retour:hover { color: var(--accent); }

/* --- Recherche ---------------------------------------------------------- */

.recherche { margin-bottom: var(--e5); }

.recherche__champ {
    width: 100%;
    min-height: var(--tactile);
    padding: var(--e2) var(--e4);
    font: inherit;
    color: var(--texte);
    background: var(--carte);
    border: 1px solid var(--bord);
    border-radius: var(--r-rond);
}

.recherche__champ::placeholder { color: var(--texte-faible); }

/* --- Grille de recettes ------------------------------------------------- */

.grille {
    display: grid;
    /* auto-fill plutôt qu'auto-fit : une seule recette garde la largeur d'une
       carte au lieu de s'étirer sur toute la ligne. */
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr));
    gap: var(--e4);
}

.carte-recette {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    transition: transform .15s, box-shadow .15s;
}

.carte-recette:hover {
    transform: translateY(-2px);
    box-shadow: var(--ombre-forte);
    color: inherit;
}

.carte-recette__image {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    background: var(--fond-doux);
}

.carte-recette__image--absente {
    display: grid;
    place-items: center;
    font-size: 2.5rem;
    opacity: .35;
}

.carte-recette__corps { padding: var(--e4); display: grid; gap: var(--e1); }
.carte-recette__titre { font-size: var(--t-moyen); }

.carte-recette__resume {
    color: var(--texte-doux);
    font-size: var(--t-petit);
    /* Deux lignes maximum : les cartes gardent la même hauteur quelle que soit
       la longueur de la description. */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.carte-recette__meta { color: var(--texte-faible); font-size: var(--t-petit); }

/* --- Fiche recette ------------------------------------------------------ */

.fiche__entete { margin-bottom: var(--e6); }
.fiche__image { width: 100%; max-height: 22rem; object-fit: cover; border-radius: var(--r-grand); margin-bottom: var(--e4); }
.fiche__resume { color: var(--texte-doux); margin-top: var(--e2); }
.fiche__infos, .fiche__portions { color: var(--texte-faible); font-size: var(--t-petit); margin-top: var(--e2); }

.fiche {
    display: grid;
    gap: var(--e6);
    grid-template-columns: 1fr;
}

/* Deux colonnes sur grand écran : ingrédients à gauche, étapes à droite —
   la disposition d'un livre de cuisine. */
@media (min-width: 48rem) {
    .fiche { grid-template-columns: minmax(0, 20rem) minmax(0, 1fr); gap: var(--e7); align-items: start; }
    .fiche__ingredients { position: sticky; top: 5rem; }
}

.fiche h2 { margin-bottom: var(--e3); }

.groupe { margin-bottom: var(--e4); }
.groupe__titre { font-size: var(--t-base); color: var(--texte-doux); margin-bottom: var(--e2); }

.ingredients { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--e2); }

.ingredients__ligne {
    padding: var(--e2) 0;
    border-bottom: 1px solid var(--bord);
    display: grid;
    gap: 2px;
}

.ingredients__ligne:last-child { border-bottom: 0; }
.ingredients__note { font-size: var(--t-petit); color: var(--texte-faible); }

.etapes { padding: 0; margin: 0; list-style: none; counter-reset: etape; display: grid; gap: var(--e4); }

.etapes__ligne {
    counter-increment: etape;
    display: grid;
    grid-template-columns: 2rem 1fr;
    gap: var(--e3);
    align-items: start;
}

.etapes__ligne::before {
    content: counter(etape);
    display: grid;
    place-items: center;
    width: 2rem; height: 2rem;
    border-radius: var(--r-rond);
    background: var(--accent-doux);
    color: var(--accent);
    font-weight: 700;
    font-size: var(--t-petit);
}

.etapes__minuteur { grid-column: 2; font-size: var(--t-petit); color: var(--texte-faible); }

.fiche__notes { margin-top: var(--e6); }
.fiche__pied { margin-top: var(--e7); padding-top: var(--e4); border-top: 1px solid var(--bord); display: grid; gap: var(--e3); }
.fiche__actions { display: flex; gap: var(--e2); flex-wrap: wrap; }

.etiquettes { display: flex; flex-wrap: wrap; gap: var(--e2); margin-top: var(--e3); }

.etiquette {
    padding: 2px var(--e3);
    border-radius: var(--r-rond);
    background: var(--accent-doux);
    color: var(--accent);
    font-size: var(--t-petit);
    font-weight: 600;
}

/* --- Formulaire --------------------------------------------------------- */

.formulaire { display: grid; gap: var(--e6); margin-top: var(--e4); }
.formulaire__section { display: grid; gap: var(--e4); }
.formulaire__legende { font-size: var(--t-moyen); }
.formulaire__aide { color: var(--texte-faible); font-size: var(--t-petit); margin-top: calc(var(--e3) * -1); }

.formulaire__grille {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr));
}

.champ { display: grid; gap: var(--e1); }
.champ__libelle { font-size: var(--t-petit); font-weight: 600; color: var(--texte-doux); }
.champ__requis { color: var(--danger); }
.champ__aide { font-size: var(--t-petit); color: var(--texte-faible); }

.champ__entree {
    width: 100%;
    min-height: var(--tactile);
    padding: var(--e2) var(--e3);
    font: inherit;
    color: var(--texte);
    background: var(--carte);
    border: 1px solid var(--bord);
    border-radius: var(--r);
}

.champ__entree:focus { border-color: var(--accent); }
textarea.champ__entree { min-height: 3rem; resize: vertical; }

.lignes { display: grid; gap: var(--e2); }

.ligne { display: flex; align-items: start; gap: var(--e2); }

.ligne__numero {
    flex: 0 0 1.5rem;
    margin-top: .7rem;
    text-align: right;
    color: var(--texte-faible);
    font-size: var(--t-petit);
    font-variant-numeric: tabular-nums;
}

.ligne__champ {
    flex: 1;
    min-width: 0;
    min-height: var(--tactile);
    padding: var(--e2) var(--e3);
    font: inherit;
    color: var(--texte);
    background: var(--carte);
    border: 1px solid var(--bord);
    border-radius: var(--r);
    resize: none;
    overflow: hidden;
}

.ligne__champ:focus { border-color: var(--accent); }
.ligne__boutons { display: flex; gap: 2px; }

.bouton-icone {
    width: var(--tactile);
    height: var(--tactile);
    display: grid;
    place-items: center;
    border: 1px solid transparent;
    border-radius: var(--r);
    background: transparent;
    color: var(--texte-faible);
    font-size: var(--t-base);
    cursor: pointer;
}

.bouton-icone:hover { background: var(--fond-doux); color: var(--texte); }

.formulaire__actions {
    display: flex;
    gap: var(--e2);
    flex-wrap: wrap;
    padding-top: var(--e4);
    border-top: 1px solid var(--bord);
}

@media (max-width: 30rem) {
    /* Au doigt, les deux actions principales méritent toute la largeur. */
    .formulaire__actions .bouton { flex: 1; }
}
