/* Mesures Atelier : palette provisoire (2026-11-24) */
:root {
  --bg: #B6D8F2;
  --surface: color-mix(in srgb, #B6D8F2 88%, #18534F);
  --card: #FFFFFF;
  --text: #18534F;
  --accent: #516079;
  --on-accent: #FAF2EA;
  --mark: #FEEAA1;
  --soft: #FEEAA1;
  --line: #18534F33;
  --bigname: #18534F1f;
  --error-bg: #B6D8F2;
  --error: #CE6A6B;
  --radius: 8px;
  --radius-sm: 6px;
  --border-w: 1px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-head: var(--font);
  --gutter: clamp(16px, 4vw, 56px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-mode="light"]) {
      --bg: #6A645A;
    --surface: #625c53;
    --card: #5d5850;
    --text: #F1F1D3;
    --accent: #FEEAA1;
    --on-accent: #18534F;
    --mark: #FEEAA1;
    --soft: #5f5a51;
    --line: #8a8479;
    --bigname: #7f796e;
    --error: #F9968B;
    color-scheme: dark;
  }
}
:root[data-mode="dark"] {
  --bg: #6A645A;
  --surface: #625c53;
  --card: #5d5850;
  --text: #F1F1D3;
  --accent: #FEEAA1;
  --on-accent: #18534F;
  --mark: #FEEAA1;
  --soft: #5f5a51;
  --line: #8a8479;
  --bigname: #7f796e;
  --error: #F9968B;
  color-scheme: dark;
}

/* Thème « Papier » */
:root[data-theme="paper"] {
  --radius: 3px;
  --radius-sm: 2px;
  --font-head: Georgia, "Times New Roman", serif;
}
:root[data-theme="paper"] body {
  background-image: repeating-linear-gradient(0deg, transparent 0 31px, var(--line) 31px 32px);
  background-attachment: local;
}
:root[data-theme="paper"] .card,
:root[data-theme="paper"] .tool,
:root[data-theme="paper"] .text-block { border-color: var(--text); background: var(--bg); }
:root[data-theme="paper"] .field select,
:root[data-theme="paper"] .field input { border-style: dashed; }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: max(16px, 1rem);
  line-height: 1.6;
}
h1, h2, h3 { font-family: var(--font-head); font-weight: 600; line-height: 1.25; margin: 0 0 .6em; }
h1 { font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.4rem); }
h2 { font-size: clamp(1.2rem, 1rem + .8vw, 1.6rem); margin-top: 1.4em; }
a { color: var(--text); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: var(--gutter); top: 8px; background: var(--card); padding: 8px 12px; z-index: 10; }

/* Texte justifié avec coupures de mots, sans grands blancs */
/* Les textes courts des cartes sont centrés : justifiés sur une colonne étroite, ils feraient de grands blancs. */
.card-text { text-align: center; text-wrap: balance; }
.prose p, .faq p, .lead {
  text-align: justify;
  hyphens: auto;
  -webkit-hyphens: auto;
  overflow-wrap: break-word;
}

/* En-tête */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px var(--gutter);
  border-bottom: var(--border-w) solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; }
.brand img { display: block; }
.brand-name { font-family: var(--font-head); font-weight: 600; font-size: 1.15rem; }
.controls { display: flex; gap: 8px; flex-wrap: wrap; }

/* Bouton à plusieurs positions qui se manipule aussi en glissant */
.slide {
  position: relative; display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--surface); border: var(--border-w) solid var(--line); border-radius: var(--radius);
  padding: 3px; touch-action: none; user-select: none; -webkit-user-select: none;
}
.slide button {
  position: relative; z-index: 1; border: 0; background: transparent; color: var(--text);
  font: inherit; font-size: .85rem; padding: 6px 12px; min-width: 3.2em; cursor: pointer;
  border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center;
  transition: color .2s;
}
.slide button[aria-checked="true"] { color: var(--on-accent); }
.slide .thumb {
  position: absolute; top: 3px; bottom: 3px; left: 3px; border-radius: var(--radius-sm);
  background: var(--accent); transition: transform .25s cubic-bezier(.2,.8,.2,1);
  pointer-events: none;
}
.slide.dragging .thumb { transition: none; }

/* Contenu pleine largeur avec marges */
main { padding: 8px var(--gutter) 48px; }
.hero { padding: 28px 0 8px; }
.prose { max-width: none; }
.block { margin-top: 28px; }
.block-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.block-head h2 { margin: 0; }
.text-block {
  background: var(--card); border: var(--border-w) solid var(--line); border-radius: var(--radius);
  padding: clamp(16px, 3vw, 32px);
}
.back {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 12px; padding: 6px 12px;
  border: var(--border-w) solid var(--line); border-radius: var(--radius); text-decoration: none; background: var(--card);
}
.lead { font-size: 1.05rem; }

/* Recherche */
.search input {
  font: inherit; color: var(--text); background: var(--card); border: var(--border-w) solid var(--line);
  border-radius: var(--radius); padding: 8px 12px; width: min(340px, 100%);
}

/* Cartes d'outils : toutes de la même taille */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-top: 16px; grid-auto-rows: 1fr; }
.card {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center;
  background: var(--card); border: var(--border-w) solid var(--line); border-radius: var(--radius);
  padding: 20px; text-decoration: none; min-height: 170px; transition: border-color .2s, transform .2s;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card-icon {
  width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
  background: var(--mark); color: #18534F; border-radius: var(--radius-sm); font-size: 1.4rem; font-weight: 700;
}
.card-name { font-weight: 600; font-family: var(--font-head); }
.card-text { font-size: .92rem; width: 100%; }
.empty { margin-top: 16px; }

/* Outil */
.tool {
  margin-top: 20px; background: var(--card); border: var(--border-w) solid var(--line); border-radius: var(--radius);
  padding: clamp(16px, 3vw, 32px);
}
.options { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: .92rem; }
.field select, .field input {
  font: inherit; color: var(--text); background: var(--bg); border: var(--border-w) solid var(--line);
  border-radius: var(--radius-sm); padding: 8px 10px; min-height: 42px;
}
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; align-items: center; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px;
  font: inherit; font-weight: 600; padding: 8px 18px; border-radius: var(--radius-sm); cursor: pointer;
  background: var(--accent); color: var(--on-accent); border: var(--border-w) solid var(--accent); text-decoration: none;
}
.btn.secondary { background: transparent; color: var(--text); border-color: var(--line); }
.btn:active { transform: translateY(1px); }
.check { display: inline-flex; align-items: center; gap: 8px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.error { color: var(--text); background: var(--surface); border-left: 4px solid var(--error); padding: 8px 12px; margin-top: 12px; border-radius: 0; }

/* Fiche générée (aperçu et impression) */
.sheet { margin-top: 20px; background: #FFFFFF; color: #18534F; border: 1px solid #E8D5CC; border-radius: var(--radius-sm); padding: clamp(14px, 3vw, 36px); }
.sheet-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; border-bottom: 1px solid #E8D5CC; padding-bottom: 10px; margin-bottom: 18px; }
.sheet-title { font-family: var(--font-head); font-size: 1.3rem; font-weight: 600; margin: 0; }
.sheet-lines { display: flex; gap: 24px; font-size: .95rem; }
.sheet-lines span { display: inline-block; min-width: 9em; border-bottom: 1px dotted #6A645A; }
.answers-title { margin-top: 28px; }

.ops { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 28px 18px; }
.op {
  font-family: ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace; font-size: 1.25rem;
  display: flex; justify-content: center; align-items: flex-start;
}
.op table { border-collapse: collapse; }
.op td { width: 1.15em; height: 1.55em; text-align: center; padding: 0; }
.op .sign { width: 1.3em; }
.op tr.rule td { border-top: 2px solid #18534F; }
.op .ans { color: #226D68; font-weight: 700; }
.div { display: grid; grid-template-columns: auto auto; }
.div .dividend { padding-right: .5em; }
.div .divisor { border-left: 2px solid #18534F; border-bottom: 2px solid #18534F; padding: 0 .5em; }
.div .quotient { grid-column: 2; padding: 0 .5em; border-left: 2px solid #18534F; min-height: 1.55em; }
.div .rest { grid-column: 1; text-align: right; padding-right: .5em; }

/* FAQ */
.faq details { border-top: var(--border-w) solid var(--line); padding: 10px 0; }
.faq summary { cursor: pointer; font-weight: 600; }
.steps li { margin: 4px 0; }
.contact dt { font-weight: 600; margin-top: 8px; }
.contact dd { margin: 0; }

/* Bandeau cookies */
.cookie {
  position: fixed; left: var(--gutter); right: var(--gutter); bottom: 16px; z-index: 20;
  background: var(--card); border: var(--border-w) solid var(--line); border-radius: var(--radius);
  padding: 16px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  box-shadow: 0 8px 30px rgba(24, 83, 79, .15);
}
.cookie p { margin: 0; flex: 1 1 320px; text-align: justify; hyphens: auto; }
.cookie .actions { margin: 0; }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--text); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* Pied de page et nom géant */
.foot { border-top: var(--border-w) solid var(--line); padding: 32px var(--gutter) 0; overflow: hidden; }
.foot-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 24px; }
.foot ul { list-style: none; padding: 0; margin: 0; }
.foot li { margin: 6px 0; }
.foot-title { font-weight: 600; margin: 0 0 8px; }
.foot-note { margin: 0; text-align: justify; hyphens: auto; }
.bigname {
  font-family: var(--font-head); font-weight: 700; color: var(--bigname);
  font-size: clamp(56px, 13.5vw, 240px); line-height: 1.25; padding: .1em 0 .18em;
  white-space: nowrap; text-align: left; letter-spacing: -.02em; overflow: hidden;
}
.bigname span { display: inline-block; transform: translateY(60%); opacity: 0; transition: transform .7s cubic-bezier(.2,.8,.2,1), opacity .7s; transition-delay: calc(var(--i) * 45ms); }
.bigname.in span { transform: none; opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .bigname span { transform: none; opacity: 1; transition: none; }
  .slide .thumb, .card { transition: none; }
}

@media (max-width: 640px) {
  .top { flex-direction: column; align-items: flex-start; }
  .controls { width: 100%; }
  .sheet-lines { flex-direction: column; gap: 8px; }
}

/* Impression : seule la fiche sort */
@media print {
  @page { margin: 12mm; }
  body { background: #fff !important; }
  .top, .foot, .back, .tool-head, .text-block, .block, .options, .actions, .cookie, .error, .skip { display: none !important; }
  main, .tool { padding: 0 !important; margin: 0 !important; border: 0 !important; background: #fff !important; }
  .sheet { border: 0; padding: 0; margin: 0; }
  .sheet.answers { break-before: page; }
  .sheet.answers[hidden] { display: block !important; }
}

/* Cases à cocher en grille (tables) et champs larges */
.field.wide { grid-column: 1 / -1; }
fieldset.field { border: var(--border-w) solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; margin: 0; }
fieldset.field legend { padding: 0 6px; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.sheet.bare { padding: 0; border: 0; background: transparent; }

/* Fiches à base de dessins (fractions, droites, horloges) */
.items { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 26px 18px; }
.items.lines { grid-template-columns: 1fr; gap: 30px; }
.item { display: flex; flex-direction: column; align-items: center; gap: 8px; break-inside: avoid; }
.item svg { width: 100%; height: auto; max-width: 180px; overflow: visible; }
.items.lines .item svg { max-width: none; }
.item .label { font-size: 1.15rem; min-height: 1.6em; display: flex; align-items: center; justify-content: center; gap: 6px; }
.blank { display: inline-block; min-width: 2.4em; border-bottom: 1.5px solid #18534F; height: 1.2em; }
.frac { display: inline-flex; flex-direction: column; align-items: center; line-height: 1.1; font-size: 1.2rem; }
.frac .bar { width: 100%; min-width: 1.6em; border-top: 2px solid #18534F; margin: 2px 0; }
.frac .ans { color: #226D68; font-weight: 700; }
.calc-list { columns: 3 220px; column-gap: 32px; font-size: 1.15rem; }
.calc-list p { margin: 0 0 14px; break-inside: avoid; font-variant-numeric: tabular-nums; }
.calc-list .ans { color: #226D68; font-weight: 700; }
.grid-page { width: 100%; height: auto; display: block; background: #fff; border: 1px solid #E8D5CC; }
@media print {
  .grid-page { border: 0; width: 186mm; height: 270mm; }
  .item, .calc-list p { break-inside: avoid; }
}
.frac .blank { min-width: 1.9em; height: 1.5em; border: 1.5px solid #18534F; border-radius: 3px; }
/* Tous les dessins d'une fiche occupent la même hauteur, pour des cases alignées */
.items:not(.lines) .item svg { height: 130px; }

/* Alignement des formulaires : tous les champs d'une même rangée commencent et finissent à la même hauteur */
.options { align-items: start; }
.field > span:first-child, fieldset.field > legend { line-height: 1.35; }
.field:has(textarea) { grid-column: 1 / -1; }
.field textarea { min-height: 6.5em; }
@media (min-width: 641px) {
  /* les libellés réservent toujours deux lignes, calées en bas : une case ne descend jamais à cause d'un libellé long */
  .options > .field:not(:has(textarea)):not(fieldset) > span:first-child { min-height: 2.7em; display: flex; align-items: flex-end; }
}


/* Corrections issues des tests (2026-11-23) */
.sheet.bare { color: var(--text); }
::placeholder { color: var(--text); opacity: .9; }
.ask { margin-top: 12px; padding: 12px 14px; border: 1px solid var(--line); border-left: 4px solid var(--error); border-radius: 0; background: var(--surface); }
.ask p { margin: 0 0 8px; }
@media (max-width: 640px) {
  .top { gap: 8px; padding-top: 10px; padding-bottom: 10px; }
  .controls { flex-wrap: nowrap; gap: 6px; width: 100%; justify-content: space-between; }
  .slide button { padding: 5px 7px; min-width: 0; font-size: .78rem; }
}

/* Impression : consignes d'écran masquées */
@media print { .hint, .note, .ask, .empty { display: none !important; } }
.sheet-title { overflow-wrap: anywhere; }
/* Bandeau cookies plus discret sur téléphone */
@media (max-width: 640px) {
  .cookie { left: 8px; right: 8px; bottom: 8px; padding: 10px 12px; gap: 8px; }
  .cookie p { font-size: .82rem; line-height: 1.4; flex-basis: 100%; }
  .cookie .btn { min-height: 36px; padding: 4px 14px; font-size: .9rem; }
}

/* Éléments posés sur une feuille blanche : toujours foncés sur clair, même en mode sombre */
.sheet:not(.bare) .btn.secondary { color: inherit; border-color: currentColor; }
.sheet:not(.bare) .res:not(.main) { background: #f5efe6; border-color: #E8D5CC; color: #18534F; }
.sheet:not(.bare) .res.main { color: #18534F; }
.sheet:not(.bare) .calc-table th { background: #f5efe6; color: #18534F; }
.sheet:not(.bare) .calc-table input, .sheet:not(.bare) .calc-table select { background: #fff; color: #18534F; border-color: #E8D5CC; }
.tt td.break { color: #18534F; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Outils importés : sortie texte, grilles à imprimer, pixel art */
.legacy-out { white-space: pre-wrap; background: #fff; color: #18534F; border: 1px solid #E8D5CC; border-radius: var(--radius-sm); padding: 14px; margin: 14px 0 0; font-family: ui-monospace, Consolas, "Courier New", monospace; font-size: .95rem; overflow-wrap: anywhere; max-height: 28rem; overflow: auto; }
.print-grid { display: grid; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); margin-top: 14px; background: #fff; color: #18534F; border: 1px solid #6A645A; break-inside: avoid; }
.print-grid > * { border: 1px solid #6A645A; padding: 10px 6px; text-align: center; min-height: 64px; display: flex; align-items: center; justify-content: center; white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; background: #fff; color: #18534F; }
.print-grid.pixel > button { padding: 0; min-height: 0; aspect-ratio: 1; cursor: pointer; }
.pixel-control { display: flex; gap: 8px; align-items: center; margin-top: 14px; }
@media print { .print-grid.pixel > button { print-color-adjust: exact; -webkit-print-color-adjust: exact; } .legacy-out { max-height: none; border: 0; } }
