* {
  box-sizing: border-box;
}

:root {
  --color-bg: #eef0f7;
  --color-surface: #ffffff;
  --color-surface-alt: #f6f6fb;
  --color-border: #d7d7e4;
  --color-text: #262631;
  --color-text-muted: #6b6b7c;
  --color-primary: #5b52d6;
  --color-primary-hover: #473fc0;
  --color-primary-soft: #eeecfb;
  --radius-sm: 6px;
  --radius-md: 12px;
  --shadow-sm: 0 1px 2px rgba(30, 30, 60, 0.08);
  --shadow-md: 0 4px 16px rgba(30, 30, 60, 0.12);
}

/* Add font styling and other global styles here */
@font-face {
  font-family : 'Material Symbols Rounded Variable';
  font-weight: 200;
  font-style: normal;
  src: url('./fonts/material-symbols-rounded-latin-200-normal.woff2') format('woff2'), url('./fonts/material-symbols-rounded-latin-200-normal.woff') format('woff');
}

nav {
  position: absolute;
  top:0;
  right:0;
  padding:0.2em 0.2em 1em 1em;
  border-radius: 0 0 0 100% ;
  border: 2px var(--color-border) solid;
  background: var(--color-surface-alt);
  box-shadow: var(--shadow-sm);
}
nav img {
  width: 60px;
  clip: auto;
  border-radius: 100%;
  transform: scaleX(-1);
}

.material .page .grid > div, .material .page .question .numero, .material .page .legend-lettre, .material #palette button .numero, .material .palette button .numero {
  font-family: 'Material Symbols Rounded Variable', sans-serif;
  font-weight: 200;
  font-style: normal;
  letter-spacing: normal;
  text-transform: none;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -moz-font-feature-settings: 'liga';
  -moz-osx-font-smoothing: grayscale;
}
.blue {
  color: blue;
}

@page {
  size: A4 portrait;
  margin: 0;
}
#pixelCanvas, #croppedImageCanvas {
  display: none;
}
#unCropButton {
  display: block;
  margin: 0.6em auto 0;
}
body {
  font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
  color: var(--color-text);
  line-height: 1.45;
}
header {
  background-color: var(--color-surface);
  padding: 0.8em 1em 0.8em;
  text-align: center;
  margin-bottom: 0.5em;
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}
header > div {
  max-width: 900px;
  margin: 0 auto;
}
header h1 {
  font-size: 1.5em;
  color: var(--color-primary-hover);
  margin: 0 0 0.3em;
}
header > div > p {
  color: var(--color-text-muted);
  margin: 0.3em 0;
}
header label, #reglages label, #presentation label {
  cursor: pointer;
}
main[size="A4"]{
  width: 210mm;
  min-height: 297mm;
}
main[size="A4"][layout="landscape"]{
  width: 277mm;
  min-height: 210mm;
}
.hidden {
  display: none;
}
.centered-text {
  text-align: center;
}
fieldset {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-alt);
  box-shadow: var(--shadow-sm);
  padding: 0.5em 0.8em 0.7em;
  margin-bottom: 0.7em;
  text-align: left;
}
fieldset legend {
  padding-left: 0.5em;
  padding-right: 0.5em;
  font-weight: bold;
  color: var(--color-primary-hover);
  text-transform: uppercase;
  font-size: 0.9em;
  letter-spacing: 0.03em;
}
fieldset br {
  display: block;
  margin: 0.25em 0;
}
fieldset input[type="number"],
fieldset input[type="text"],
fieldset select,
#fieldset-md textarea {
  font: inherit;
  padding: 0.35em 0.5em;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
}
fieldset input[type="number"] {
  width: 4.5em;
}
fieldset input[type="text"] {
  min-width: 10em;
}
fieldset input[type="checkbox"],
fieldset input[type="radio"] {
  accent-color: var(--color-primary);
  width: 1.05em;
  height: 1.05em;
  vertical-align: middle;
}
fieldset input[type="range"] {
  width: 7em;
  vertical-align: middle;
}
fieldset label:has(input[type="range"]) {
  white-space: nowrap;
}
fieldset input:focus,
fieldset select:focus,
#fieldset-md textarea:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
  border-color: var(--color-primary);
}
/* réglages : à côté de la feuille sur grand écran, au-dessus sinon (cf. @media screen) */
#reglages {
  max-width: 700px;
  margin: 0 auto 1em;
  padding: 0 1em;
}
#fieldset-md textarea {
  width: 100%;
  height: 12.5em;
}
button {
  font: inherit;
  padding: 0.5em 1em;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: #fff;
  cursor: pointer;
  transition: background-color .15s ease, transform .05s ease;
}
button:hover {
  background: var(--color-primary-hover);
}
button:active {
  transform: translateY(1px);
}
#testMDButton {
  font-size: 0.75em;
  padding: 0.2em 0.6em;
  margin-left: 0.4em;
}
#imageInput {
  display: none;
}
#imageInput + label {
  padding: 0.7em 1em;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  display: block;
  text-align: center;
  line-height: 1.5em;
  background: var(--color-surface);
  color: var(--color-text-muted);
  transition: border-color .15s ease, background-color .15s ease, color .15s ease;
}
#imageInput + label:hover, #imageInput + label.dragover  {
  background-color: var(--color-primary-soft);
  border-color: var(--color-primary);
  color: var(--color-primary-hover);
}

/* Autres styles pour personnaliser l'apparence */

#gridCut {
  position:absolute;
  border: 1px solid black;
  display: grid;
  width:100%;
  font-size: xx-large; /* taille maximale, ajustée par generateGridCut selon la taille des cases */
}
/* numéros des feuilles masqués (case à cocher « Numéroter les feuilles ») */
#gridCut.sans-numeros {
  font-size: 0 !important;
}
#gridCut > div {
  border: 1pt dotted red;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  font-size: inherit;
  text-shadow: 2px 2px white;
}

.palette button, #palette button {
  height: 22px;
  margin: 5px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.75em;
  line-height: 1.1;
  box-shadow: var(--shadow-sm);
  transition: transform .1s ease, box-shadow .1s ease;
}
.palette button:hover, #palette button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
#palette button {
  height: 44px;
}
.centered {
  margin: auto;
}
.palette, #palette {
  display: flex;
  flex-wrap: wrap;
}
/* La palette cliquable de chaque page ne sert qu'à colorier à l'écran :
   elle flotte au-dessus de la page sans jamais s'imprimer ni influencer
   la mise en page (sinon elle déborde avec les grandes palettes). */
.page > .palette.noprint {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  transform: translateY(-100%);
  margin-bottom: 0.3cm;
  justify-content: center;
  z-index: 5;
}
.page > .palette.noprint button {
  flex-grow: 0;
}

button.selected {
  outline: 2px solid var(--color-text);
  outline-offset: -2px;
}

button.white {
  color: white
}
button.black {
  color: black
}

#presentation table {
  border-collapse: collapse;
}
#presentation th {
  padding: 0.3em 1em;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  font-size: 0.8em;
  letter-spacing: 0.04em;
}
#presentation td {
  padding: 0.5em 1em;
  vertical-align: top;
}
/* les réglages sous les images ne doivent pas élargir leur colonne */
#presentation td > .noprint {
  max-width: 320px;
}
#presentation img {
  max-width: 300px;
  height: auto;
}
#originalCroppingCanvas {
  position: absolute;
}

#bigCanvas {
  max-width: 100%;
  height: auto;
  max-height: 480px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: flex-start;
}
/* retour à la ligne forcé entre deux lignes de la légende (cf. equilibrerLegendes) */
.legend-saut {
  flex-basis: 100%;
  height: 0;
}
.legend-column {
  min-width: 1.6cm;
  margin: 0.1cm 0.2cm;
  border: 1px solid black;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.legend-color {
  height: 0.4cm;
  text-align: center;
  font-size: 0.8em;
}
/* légende avec énoncés : lettre(s) de la couleur à la place de l'aplat de couleur */
.legend-color.legend-lettre {
  height: auto;
  min-height: 0.6cm;
  font-size: 1.1em;
  padding: 0.1cm 0.2cm;
}
.legend-vide {
  min-height: 0.6cm;
  border-top: 1px solid black;
  text-align: center;
  padding: 0.1cm 0.2cm;
}
.questions {
  width: 90%;
  display: grid;
}

.questions {
  grid-template-columns: repeat(auto-fill, minmax(40%, 1fr));
}
.questions.s1 {
  grid-template-columns: repeat(auto-fill, minmax(30%, 1fr));
  font-size: 0.8em;
}

.questions.s2 {
  grid-template-columns: repeat(auto-fill, minmax(22%, 1fr));
  font-size: 0.7em;
}

.question {
  margin-right: 2em;
  display: grid;
  grid-template-columns:3.2em 1fr;
  margin-bottom: 0.2cm;
  align-items: center;
}

.question .numero, .question .pastille {
  print-color-adjust: exact;
  -webkit-print-color-adjust: exact;
  box-sizing: border-box;
  border: 1px solid black;
  border-radius: 50%;
  padding: 0.2em;
  width: 2.2em;
  height: 2.2em;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25em;
}

/* nom de couleur à la place de la pastille : pastille élargie, texte sur deux lignes au besoin */
.question:has(.pastille-texte) {
  grid-template-columns: 5.6em 1fr;
}
.question .pastille.pastille-texte {
  width: 4.6em;
  border-radius: 1.1em;
  font-size: 0.8em;
  line-height: 1.1;
  text-align: center;
  padding: 0.2em 0.3em;
}

.page {
  width: 200mm;
  min-height: 277mm;
  display: flex;
  flex-direction: column;
  align-items: center;
  align-content: center;
  justify-content: flex-end;
  position: relative;
  /* réserve la place du titre (position absolue) pour que le contenu
     aligné en bas (énoncés inclus) ne remonte jamais par-dessus */
  padding-top: 1.8cm;
}
/* énoncés et grille sur des pages séparées : contenu bien plus court
   qu'une page A4, on le remonte en haut plutôt que de le coller en bas */
/* énoncés dans la page de la grille : centrés dans l'espace entre le titre et la grille */
.page.grid-page:not(.separated) > .questions {
  margin-top: auto;
  margin-bottom: auto;
}
.page.questions-page,
.page.grid-page.separated {
  justify-content: flex-start;
}

/* Signalement d'une page qui dépasse la hauteur imprimable d'une A4
   (cf. #overflowWarning et le bouton "Séparer les énoncés") */
.page.page-overflow {
  outline: 2px dashed #c0392b;
  outline-offset: -2px;
}
.page-overflow-badge {
  position: absolute;
  top: 0.2cm;
  right: 0.2cm;
  background: #c0392b;
  color: #fff;
  font-size: 0.7em;
  padding: 0.2em 0.6em;
  border-radius: var(--radius-sm);
  z-index: 6;
}
/* la palette flottante de la 1re grille remonte au-dessus de sa page :
   on réserve la place pour qu'elle ne recouvre pas ce qui précède (ex.
   le bandeau d'alerte de débordement). Ciblé sur la grille réellement
   première : si une page d'énoncés séparée passe devant, elle n'a pas
   de palette et ne doit pas hériter de cette marge. */
#grilles > section:first-child > .grid-page {
  margin-top: 2.2cm;
}
#overflowWarning {
  max-width: 900px;
  margin: 0 auto 1em;
  padding: 0.7em 1em;
  border: 1px solid #c0392b;
  background: #fdecea;
  color: #7a231b;
  border-radius: var(--radius-md);
  text-align: center;
}
#overflowWarning button {
  margin-left: 0.6em;
  background: #c0392b;
}
#overflowWarning button:hover {
  background: #9c2c1c;
}

.page > h2 {
  position: absolute;
  top: 0;
  margin-top: 0.5cm;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.3em;
  padding-bottom: 0.15em;
  border-bottom: 2px solid black;
}

.grid {
  display: grid;
}
.page > .grid {
  margin-bottom: 0.5cm;
}
.page .grid > div {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #a6a6a6;
  color: #c1c1c1;
  box-sizing: border-box;
}
#iagenerated, .precision {
  font-size: small;
  font-style: italic;
}
@media screen {
  html {
    background: rgb(204, 204, 204);
    padding: 0;
    margin: 0;
  }
  body {
    padding: 0;
    margin: 0;
  }
  main {
    position: relative;
    padding: 5mm 5mm 0 5mm;
    background: white;
    display: block;
    margin: 0.5em auto;
    /*margin-bottom: 0.5cm;*/
    box-shadow: 0 0 0.5cm rgba(0, 0, 0, 0.5);
  }
  /* panneau de réglages à gauche de la feuille, toujours visible quand on fait défiler */
  @media (min-width: 1180px) {
    #atelier {
      display: flex;
      justify-content: center;
      align-items: flex-start;
      gap: 1.5em;
    }
    #reglages {
      position: sticky;
      top: 0.5em;
      flex: 0 0 320px;
      width: 320px;
      max-height: calc(100vh - 1em);
      overflow-y: auto;
      margin: 0.5em 0;
      padding: 0 0.3em 0 0;
    }
    #atelier > main {
      margin: 0.5em 0;
    }
  }
  .footer:not(:last-of-type)::before {
    content: ' ';
    position: absolute;
    display: block;
    box-shadow: 0 0.2cm 0.2cm rgba(0,0,0,0.5);
    height: 5mm;
    width: 210mm;
    margin-left:-5mm;
    z-index: 5;
}
.footer:not(:last-of-type) {
    margin-bottom: 2cm;
}
.footer:not(:last-of-type)::after {
    position: absolute;
    z-index: 2;
    content: ' ';
    display: block;
    margin-top:5mm;
    height: 0.5cm;
    width: 220mm;
    margin-left:-10mm;
    background-color: rgb(204,204,204);
}

}
@media print {
  .footer:not(:last-of-type) {
    page-break-after: always;
  }
  #grilles section {
    padding-top:5mm;
  }
  /* la marge de l'écran ferait déborder la première page, et sa légende sur la page suivante */
  #grilles > section:first-child > .grid-page {
    margin-top: 0;
  }
  .legend, .legend-column {
    break-inside: avoid;
  }
  .noprint {
    display: none !important;
  }
  .page.page-overflow {
    outline: none;
  }
  html, body {
    margin: 0;
    padding:0;
  }
  main {
    padding: 5mm 5mm 0 5mm;
    margin:0;
  }
}
/* Indicateur de calcul en cours */
#calculEnCours {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: rgba(238, 240, 247, 0.8);
  color: var(--color-text);
  font-weight: bold;
}
#calculEnCours.hidden {
  display: none;
}
#calculEnCours .spinner {
  width: 3rem;
  height: 3rem;
  border: 5px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: tourne 0.8s linear infinite;
}
@keyframes tourne {
  to { transform: rotate(360deg); }
}

header > div > p.liens-legaux {
  font-size: 0.85em;
}
