/* Maille à part : papier écru, encre, et un seul accent rouge garance (teinture naturelle de la laine). */

:root {
  --papier: #f4efe4;
  --papier-fonce: #ebe4d4;
  --carte: #fbf8f1;
  --encre: #1e1b17;
  --encre-douce: #5d554a;
  --filet: #d5cbb7;
  --garance: #a3341f;
  --garance-pale: #f2dfd5;
  --mousse: #4c6a37;
  --echelle: 1;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "URW Palladio L", Georgia, serif;
  --sans: "Avenir Next", "Segoe UI", "Noto Sans", Ubuntu, "DejaVu Sans", system-ui, sans-serif;
  --mailles: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='12' viewBox='0 0 16 12'%3E%3Cpath d='M1 2l7 8 7-8' fill='none' stroke='%23a3341f' stroke-width='2'/%3E%3C/svg%3E");
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="clair"]) {
    --papier: #16140f;
    --papier-fonce: #211e18;
    --carte: #1c1a14;
    --encre: #ede6d8;
    --encre-douce: #b4aa99;
    --filet: #3b362d;
    --garance: #e37c63;
    --garance-pale: #3d241c;
    --mousse: #9fbf80;
    --mailles: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='12' viewBox='0 0 16 12'%3E%3Cpath d='M1 2l7 8 7-8' fill='none' stroke='%23e37c63' stroke-width='2'/%3E%3C/svg%3E");
    color-scheme: dark;
  }
}
:root[data-theme="sombre"] {
  --papier: #16140f;
  --papier-fonce: #211e18;
  --carte: #1c1a14;
  --encre: #ede6d8;
  --encre-douce: #b4aa99;
  --filet: #3b362d;
  --garance: #e37c63;
  --garance-pale: #3d241c;
  --mousse: #9fbf80;
  --mailles: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='12' viewBox='0 0 16 12'%3E%3Cpath d='M1 2l7 8 7-8' fill='none' stroke='%23e37c63' stroke-width='2'/%3E%3C/svg%3E");
  color-scheme: dark;
}

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

html {
  font-size: calc(100% * var(--echelle));
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--papier);
  color: var(--encre);
  font: 1.0625rem/1.6 var(--sans);
}

h1, h2, h3 { font-family: var(--serif); line-height: 1.2; font-weight: 600; margin: 1.6em 0 .5em; }
h1 { font-size: clamp(2rem, 5vw, 3rem); margin-top: .2em; letter-spacing: -.01em; }
h2 { font-size: 1.6rem; }
h3 { font-size: 1.25rem; }
p, ul, ol, dl { margin: 0 0 1em; }
a { color: var(--garance); text-underline-offset: .15em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--garance); outline-offset: 2px; }
button, input, select { font: inherit; color: inherit; }
abbr[data-def] { text-decoration: underline dotted var(--encre-douce); text-underline-offset: .2em; cursor: help; }
[hidden] { display: none !important; }

.invisible, .evitement:not(:focus) {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.evitement:focus { position: fixed; top: .5rem; left: .5rem; z-index: 10; background: var(--carte); padding: .5rem 1rem; }

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

.entete {
  display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: .5rem 2rem;
  max-width: 76rem; margin: 0 auto; padding: 1.4rem 1.25rem 1.1rem;
  position: relative;
}
.entete::after {
  content: ""; position: absolute; left: 1.25rem; right: 1.25rem; bottom: 0; height: 12px;
  background: var(--mailles) repeat-x left center;
}
.marque { text-decoration: none; color: var(--encre); display: flex; flex-direction: column; }
.marque-nom { font-family: var(--serif); font-size: 1.9rem; font-weight: 700; font-style: italic; letter-spacing: -.01em; line-height: 1.1; }
.marque-devise { font-size: .78rem; text-transform: uppercase; letter-spacing: .12em; color: var(--encre-douce); margin-top: .2rem; }
.nav { display: flex; gap: 1.2rem; flex-wrap: wrap; font-size: .95rem; padding-bottom: .2rem; }
.nav a { color: var(--encre); text-decoration: none; border-bottom: 1px solid transparent; }
.nav a:hover { border-bottom-color: var(--encre); }
.nav .langue { font-weight: 600; color: var(--garance); }

main { max-width: 76rem; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }

.pied {
  max-width: 76rem; margin: 0 auto; padding: 1.5rem 1.25rem 7rem;
  border-top: 1px solid var(--filet); color: var(--encre-douce); font-size: .9rem;
}
.pied p { margin: .2rem 0; }

/* ---------- Accueil ---------- */

.accueil-intro { font-family: var(--serif); font-size: clamp(1.25rem, 2.6vw, 1.6rem); line-height: 1.4; max-width: 46rem; margin: .5rem 0 1.5rem; }

.recherche input {
  width: 100%; padding: .9rem 1rem; font-size: 1.15rem;
  background: var(--carte); border: 2px solid var(--encre); border-radius: 2px;
}
.recherche input::placeholder { color: var(--encre-douce); }

.catalogue { display: grid; grid-template-columns: 15rem 1fr; gap: 2rem; margin-top: 1.5rem; align-items: start; }
.filtres > summary { font-family: var(--serif); font-size: 1.2rem; font-weight: 600; cursor: pointer; padding: .2rem 0; list-style: none; }
.filtres > summary::-webkit-details-marker { display: none; }
.filtres > summary::after { content: " +"; color: var(--garance); }
.filtres[open] > summary::after { content: " −"; }
.filtre { border: 0; border-top: 1px solid var(--filet); margin: .6rem 0 0; padding: .6rem 0 0; }
.filtre legend { font-size: .78rem; text-transform: uppercase; letter-spacing: .1em; color: var(--encre-douce); padding: 0; margin-bottom: .3rem; }
.filtre label { display: flex; align-items: center; gap: .5rem; padding: .25rem 0; cursor: pointer; }
.filtre .nb { margin-left: auto; color: var(--encre-douce); font-size: .85rem; font-variant-numeric: tabular-nums; }
.filtre label.vide { opacity: .45; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--garance); width: 1.1rem; height: 1.1rem; }
.lien-discret { background: none; border: 0; padding: .8rem 0 0; color: var(--garance); text-decoration: underline; cursor: pointer; }

.resultats-tete { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .8rem; }
.compte { margin: 0; font-weight: 600; }
.tri { font-size: .9rem; color: var(--encre-douce); }
.tri select { margin-left: .4rem; padding: .3rem .4rem; background: var(--carte); border: 1px solid var(--filet); border-radius: 2px; }

.cartes { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(15.5rem, 1fr)); gap: 1.1rem; }
.carte a { display: flex; flex-direction: column; height: 100%; text-decoration: none; color: var(--encre); background: var(--carte); border: 1px solid var(--filet); border-radius: 2px; transition: border-color .15s; }
.carte a:hover { border-color: var(--encre); }
.carte a:hover h3 { text-decoration: underline; text-decoration-color: var(--garance); }
.carte-apercu { height: 8.5rem; overflow: hidden; border-bottom: 1px solid var(--filet); background: var(--carte); }
.carte-apercu svg { display: block; width: 100%; height: 100%; }
.carte-texte { padding: .9rem 1rem 1rem; display: flex; flex-direction: column; flex: 1; }
.carte h3 { margin: 0 0 .35rem; font-size: 1.2rem; }
.carte p { font-size: .95rem; color: var(--encre-douce); margin-bottom: .7rem; }
.carte .badges { margin-top: auto; margin-bottom: 0; }
.aucun { padding: 2rem 0; font-family: var(--serif); font-size: 1.2rem; }

.badges { display: flex; flex-wrap: wrap; gap: .35rem; }
.badge {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; line-height: 1;
  padding: .32rem .45rem .28rem; border: 1px solid var(--filet); border-radius: 2px; color: var(--encre-douce); background: var(--papier);
}
.badge-type { border-color: var(--encre); color: var(--encre); }
.badge-dp { border-color: var(--garance); color: var(--garance); }
.niveau-debutant::before { content: "● "; }
.niveau-intermediaire::before { content: "●● "; }
.niveau-confirme::before { content: "●●● "; }
[class*="niveau-"]::before { color: var(--garance); letter-spacing: -.1em; }

/* ---------- Fiches ---------- */

.fil { font-size: .9rem; color: var(--encre-douce); margin-bottom: 1rem; }
.fil a { color: var(--encre-douce); }
.fiche-tete { max-width: 52rem; }
.chapeau { font-family: var(--serif); font-size: 1.35rem; line-height: 1.45; margin-top: 1rem; }
.fiche-corps { display: grid; grid-template-columns: minmax(0, 1fr) 21rem; gap: 2.5rem; margin-top: 1.5rem; align-items: start; }
.fiche-intro { max-width: 44rem; }
.fiche-intro h2 { font-size: 1.3rem; }
.fiche-bref { background: var(--carte); border: 1px solid var(--filet); border-top: 3px solid var(--encre); padding: 1rem 1.2rem .4rem; border-radius: 2px; }
.fiche-bref h2 { margin-top: 0; font-size: 1.25rem; }
.fiche-bref h3 { font-size: 1.05rem; margin-top: 1.2rem; }
.fiche-bref ul { padding-left: 1.1rem; font-size: .95rem; }
.fiche-infos { margin: 0; font-size: .95rem; }
.fiche-infos div { display: grid; grid-template-columns: 7.5rem 1fr; gap: .6rem; padding: .4rem 0; border-bottom: 1px dotted var(--filet); }
.fiche-infos dt { color: var(--encre-douce); }
.fiche-infos dd { margin: 0; }
.liste-liens { list-style: "→ "; }

.statut { font-size: .92rem; padding: .7rem .9rem; border-left: 3px solid var(--garance); background: var(--garance-pale); }
.statut-relu { border-left-color: var(--mousse); background: transparent; color: var(--mousse); font-weight: 600; }
.table-relecture .statut-relu { padding: 0; border: 0; }

.notes, .origine { max-width: 52rem; }
.notes ul, .origine ul { padding-left: 1.2rem; }
.notes li, .origine li { margin-bottom: .4rem; }
.origine { border-top: 1px solid var(--filet); margin-top: 1.5rem; }
.origine h2 { font-size: 1.3rem; }

.patron { margin-top: 2.5rem; border-top: 2px solid var(--encre); }
.patron-tete { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 2rem; justify-content: space-between; }
.patron-tete h2 { margin: 1rem 0 .4rem; }
.tailles { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; }
.tailles legend { float: left; margin-right: .5rem; font-weight: 600; }
.tailles label { cursor: pointer; }
.tailles input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.tailles label span, .tailles label { display: inline-block; }
.tailles label { padding: .35rem .75rem; border: 1px solid var(--filet); border-radius: 2px; background: var(--carte); }
.tailles label:has(input:checked) { border-color: var(--encre); background: var(--encre); color: var(--papier); }
.tailles label:has(input:focus-visible) { outline: 3px solid var(--garance); outline-offset: 2px; }
.tl.choisie { font-weight: 700; color: var(--garance); }

.outils { display: flex; gap: .6rem; flex-wrap: wrap; }
.outils button, .reglages-ligne button, .ajout-compteur button {
  padding: .5rem .9rem; border: 1px solid var(--encre); background: var(--carte); border-radius: 2px; cursor: pointer;
}
.outils .bouton-principal { background: var(--garance); border-color: var(--garance); color: #fff; font-weight: 600; }
.outils .si-on { display: none; }
.tricot .outils .si-on { display: inline; }
.tricot .outils .si-off { display: none; }

.section-patron { padding-top: .5rem; }
.section-patron h3 { font-size: 1.4rem; display: flex; align-items: baseline; gap: .6rem; }
.section-patron.active h3::before { content: ""; width: .7rem; height: .7rem; background: var(--garance); flex: none; transform: translateY(-.1rem); }

.etapes { list-style: none; padding: 0; margin: 0 0 1rem; counter-reset: etape; max-width: 52rem; }
.etape { counter-increment: etape; border-left: 4px solid transparent; transition: background-color .15s; }
.etape label { display: grid; grid-template-columns: 2.2rem 1fr; gap: .4rem; padding: .55rem .6rem .55rem .4rem; cursor: pointer; }
.etape input { width: 1.35rem; height: 1.35rem; margin: .15rem 0 0 .2rem; }
.etape label > span::before { content: counter(etape) ". "; font-weight: 700; color: var(--encre-douce); font-variant-numeric: tabular-nums; }
.etape.courante { border-left-color: var(--garance); background: var(--garance-pale); }
.etape.faite label > span { color: var(--encre-douce); }
.etape.faite label > span::before { color: var(--mousse); }

/* ---------- Diagrammes ---------- */

.graphique { margin: 1rem 0 1.5rem; background: var(--carte); border: 1px solid var(--filet); padding: 1rem; border-radius: 2px; }
.graphique-defile { overflow-x: auto; }
.diagramme { display: block; height: auto; margin: 0 auto; width: max(min(calc(var(--colonnes, 10) * 1.6rem), 100%), calc(var(--colonnes, 10) * 1.1rem)); }
.graphique figcaption { margin-top: .6rem; font-size: .92rem; }
.graphique figcaption p { margin: 0 0 .3rem; }
.lecture { color: var(--encre-douce); }
.graphique details { margin-top: .6rem; border-top: 1px dotted var(--filet); padding-top: .4rem; }
.graphique summary { cursor: pointer; font-weight: 600; padding: .2rem 0; }
.legende ul { list-style: none; padding: 0; margin: .4rem 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr)); gap: .4rem 1rem; font-size: .92rem; }
.legende li { display: flex; gap: .6rem; align-items: center; }
.symbole { flex: none; }
.rangs-ecrits { padding-left: 0; list-style: none; margin: .4rem 0 0; }
.rangs-ecrits li { padding: .3rem 0; border-bottom: 1px dotted var(--filet); }
.rang-libelle { font-weight: 600; }

svg .grille { stroke: var(--encre-douce); stroke-width: 1; fill: none; opacity: .55; }
svg .fond-rang { fill: transparent; }
svg .rang.actif .fond-rang { fill: var(--garance-pale); }
svg .rang.actif .num { fill: var(--garance); font-weight: 700; }
svg .num { font: 11px var(--sans); fill: var(--encre-douce); text-anchor: middle; dominant-baseline: central; }
svg .trait { stroke: var(--encre); stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
svg .plein { fill: var(--encre); stroke: none; }
svg .vide { fill: var(--filet); }
svg .bande { fill: var(--carte); stroke: var(--encre); stroke-width: 1.6; stroke-linejoin: round; }
svg .bande.devant { stroke-width: 2; }
.symbole .fond-case { fill: var(--carte); }
.symbole .cadre { fill: none; stroke: var(--encre-douce); stroke-width: 1; }
.vignette .grille { opacity: .3; }
.vignette .trait { stroke-width: 2.4; }

/* ---------- Compteur (atelier) ---------- */

.atelier {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  background: var(--papier-fonce); border-top: 2px solid var(--encre);
  padding: .55rem max(1rem, env(safe-area-inset-left)) calc(.55rem + env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-right));
}
.atelier-ligne { max-width: 76rem; margin: 0 auto; display: flex; align-items: center; gap: .8rem; }
.atelier-section { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.atelier-titre { font-family: var(--serif); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.atelier-progression { font-size: .82rem; color: var(--encre-douce); }
.atelier-nav { display: flex; gap: .3rem; }
.bouton-icone { width: 2.6rem; height: 2.6rem; border: 1px solid var(--encre); background: var(--carte); border-radius: 2px; font-size: 1.4rem; line-height: 1; cursor: pointer; }
.compteur-principal { display: flex; align-items: center; gap: .5rem; }
.compteur-valeur { font-family: var(--serif); font-size: 2.1rem; font-weight: 700; min-width: 3ch; text-align: center; font-variant-numeric: tabular-nums lining-nums; }
.bouton-moins, .bouton-plus { border-radius: 2px; cursor: pointer; line-height: 1; font-weight: 700; }
.bouton-moins { width: 2.8rem; height: 2.8rem; background: var(--carte); border: 1px solid var(--encre); font-size: 1.5rem; }
.bouton-plus { width: 3.8rem; height: 3.8rem; background: var(--garance); color: #fff; border: 0; font-size: 2.2rem; touch-action: manipulation; }
.bouton-plus:active { transform: scale(.96); }
.atelier-rang { max-width: 76rem; margin: .4rem auto 0; font-size: 1rem; }
.atelier-rang:empty { display: none; }
.atelier-rang strong { color: var(--garance); }
.atelier-reglages { max-width: 76rem; margin: .7rem auto 0; padding-top: .7rem; border-top: 1px solid var(--filet); max-height: 55vh; overflow: auto; }
.compteurs-extra { display: grid; gap: .4rem; margin-bottom: .6rem; }
.compteur-extra { display: flex; align-items: center; gap: .5rem; }
.compteur-extra .nom { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compteur-extra output { font-family: var(--serif); font-size: 1.5rem; font-weight: 700; min-width: 2.5ch; text-align: center; font-variant-numeric: tabular-nums; }
.compteur-extra button { width: 2.4rem; height: 2.4rem; border: 1px solid var(--encre); background: var(--carte); border-radius: 2px; cursor: pointer; font-size: 1.2rem; }
.compteur-extra .suppr { border: 0; background: none; color: var(--garance); width: auto; font-size: .9rem; text-decoration: underline; }
.ajout-compteur { display: flex; gap: .5rem; margin-bottom: .8rem; }
.ajout-compteur input { flex: 1; min-width: 0; padding: .45rem .6rem; border: 1px solid var(--filet); background: var(--carte); border-radius: 2px; }
.reglages-ligne { display: flex; flex-wrap: wrap; gap: .8rem 1.5rem; align-items: center; margin-bottom: .6rem; }
.reglages-ligne .groupe { display: inline-flex; gap: .3rem; align-items: center; }
.reglages-ligne button { padding: .35rem .6rem; }
.reglages-ligne button[aria-pressed="true"] { background: var(--encre); color: var(--papier); }
.interrupteur { display: inline-flex; gap: .4rem; align-items: center; cursor: pointer; }
.aide { font-size: .85rem; color: var(--encre-douce); }
.lien-danger { background: none; border: 0; padding: 0; color: var(--garance); text-decoration: underline; cursor: pointer; }

.bulle {
  position: absolute; z-index: 20; max-width: min(22rem, calc(100vw - 2rem));
  background: var(--encre); color: var(--papier); padding: .6rem .8rem; border-radius: 2px; font-size: .92rem; line-height: 1.4;
}

/* ---------- Mode tricot ---------- */

.tricot { --echelle-tricot: 1.15; }
.tricot .entete, .tricot .pied, .tricot .fil, .tricot .fiche-corps, .tricot .notes, .tricot .origine, .tricot .chapeau, .tricot .badges { display: none; }
.tricot main { padding-top: .8rem; }
.tricot h1 { font-size: 1.6rem; }
.tricot .patron { margin-top: .5rem; }
.tricot .etape label { font-size: calc(1.15rem * var(--echelle-tricot)); padding-top: .8rem; padding-bottom: .8rem; }
.tricot .etape input { width: 1.6rem; height: 1.6rem; }
.tricot .atelier-rang { font-size: 1.15rem; }

/* ---------- Pages de texte ---------- */

.texte-page { max-width: 48rem; }
.texte-page li { margin-bottom: .4rem; }
.table-abr, .table-relecture { border-collapse: collapse; width: 100%; font-size: .97rem; }
.table-abr th, .table-abr td, .table-relecture th, .table-relecture td { text-align: left; vertical-align: top; padding: .5rem .6rem; border-bottom: 1px solid var(--filet); }
.table-abr th { white-space: nowrap; font-family: var(--serif); width: 1%; }
.table-relecture thead th { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--encre-douce); }
.page-langue main { display: flex; flex-direction: column; align-items: start; padding-top: 20vh; }
.page-langue p { font-size: 1.5rem; font-family: var(--serif); }

/* ---------- Petits écrans ---------- */

@media (max-width: 860px) {
  .catalogue { grid-template-columns: 1fr; gap: 1rem; }
  .filtres-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: 0 1.5rem; }
  .fiche-corps { grid-template-columns: 1fr; gap: 1rem; }
}
@media (max-width: 560px) {
  body { font-size: 1rem; }
  .atelier-nav { display: none; }
  .atelier-ligne { gap: .5rem; }
  .compteur-valeur { font-size: 1.8rem; }
  .bouton-plus { width: 3.4rem; height: 3.4rem; }
  .fiche-infos div { grid-template-columns: 6.5rem 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- Impression ---------- */

@media print {
  :root { --papier: #fff; --carte: #fff; --papier-fonce: #fff; --encre: #000; --garance: #000; --garance-pale: #eee; color-scheme: light; }
  .entete::after, .nav, .atelier, .outils, .tailles, .pied, .fil, .evitement, .statut a { display: none !important; }
  body { font-size: 11pt; }
  .etape label { padding: .2rem 0; }
  .graphique { break-inside: avoid; border: 0; padding: 0; }
  .section-patron { break-inside: auto; }
  a { color: #000; text-decoration: none; }
}
.renvoi { font-style: italic; color: var(--encre-douce); }
