:root {
  color-scheme: light dark;

  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e4e9;
  --text: #14161a;
  --text-muted: #666c76;
  --accent: #2f6df6;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --warn-bg: #fff8e5;
  --warn-text: #7a5200;
  --warn-border: #f0d9a0;
  --shadow: 0 1px 2px rgba(16, 18, 22, 0.06), 0 8px 24px rgba(16, 18, 22, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121316;
    --surface: #1b1d21;
    --border: #2c2f35;
    --text: #f0f1f3;
    --text-muted: #9aa1ac;
    --accent: #5a8dff;
    --accent-text: #0d1117;
    --danger: #ff7a6b;
    --warn-bg: #2a2313;
    --warn-text: #e8c882;
    --warn-border: #4a3d1c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 2.5rem 1.25rem 4rem;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 44rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-bottom: 0.5rem;
}

/* Pastille d'identité : le glyphe reprend celui du favicon. */
.brand__mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
}

.app__header h1 {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 650;
  letter-spacing: -0.025em;
}

.app__subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Les icônes suivent la taille et la couleur du texte qui les accompagne. */
.icon {
  width: 1em;
  height: 1em;
  flex: none;
  vertical-align: -0.125em;
}

.icon--brand {
  width: 1.35rem;
  height: 1.35rem;
}

.panel,
.result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

/* Onglets de mode */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 1.25rem;
  padding: 0.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.tabs button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  flex: 1 1 6rem;
  padding: 0.55rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 7px;
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.tabs button:hover:not([aria-selected="true"]) {
  color: var(--text);
}

.tabs button[aria-selected="true"] {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(16, 18, 22, 0.06);
}

/* L'onglet actif se repère aussi à la couleur de son icône, pas seulement au fond. */
.tabs button[aria-selected="true"] .icon {
  color: var(--accent);
}

.tabs button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.field {
  display: block;
}

.field__label,
.option__label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.field__input,
.option__control {
  width: 100%;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.field__input:hover,
.option__control:hover {
  border-color: var(--text-muted);
}

.field__input {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.95rem;
}

.field__input:focus-visible,
.option__control:focus-visible,
.button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* L'espacement vertical appartient au conteneur, via gap, et jamais aux champs :
   une marge sur un frère adjacent décale le second champ d'une paire placée
   côte à côte. Sans marge sur les enfants, aucun désalignement n'est possible. */
[role="tabpanel"] {
  display: grid;
  gap: 1rem;
  align-content: start;
}

.options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 1rem;
  align-items: start;
}

/* Le dépliant n'est pas un conteneur de champs : son espacement reste explicite. */
.advanced .options {
  margin-top: 0.9rem;
}

.option__label output {
  text-transform: none;
  letter-spacing: normal;
  font-variant-numeric: tabular-nums;
}

input[type="range"].option__control {
  padding: 0;
  border: none;
  background: none;
  accent-color: var(--accent);
  height: 2.6rem;
}

.result {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
}

.preview {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 16rem;
  padding: 1rem;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: var(--bg);
}

.preview__canvas {
  display: none;
  width: 100%;
  max-width: 20rem;
  height: auto;
  padding: 0.6rem;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(16, 18, 22, 0.1), 0 6px 20px rgba(16, 18, 22, 0.12);
  /* Les modules restent nets quand le canvas est mis à l'échelle. */
  image-rendering: pixelated;
}

.preview--ready .preview__canvas {
  display: block;
}

.preview--ready .preview__placeholder {
  display: none;
}

.preview__placeholder {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.status {
  margin: 0;
  min-height: 1.4rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.status--error {
  color: var(--danger);
}

.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.check input {
  margin: 0;
  accent-color: var(--accent);
}

.check label {
  font-size: 0.88rem;
  color: var(--text);
}

.notice {
  width: 100%;
  margin: 0;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--warn-border);
  border-radius: 9px;
  background: var(--warn-bg);
  color: var(--warn-text);
  font-size: 0.82rem;
}

[hidden] {
  display: none !important;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
}

.button {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.button:hover:not(:disabled) {
  border-color: var(--accent);
}

.button--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.app__footer {
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.app__footer .icon {
  color: var(--accent);
}

.app__footer a {
  color: var(--accent);
}

.advanced__help {
  margin: 0.7rem 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

textarea.field__input {
  resize: vertical;
  min-height: 5.5rem;
}

.optional {
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
  opacity: 0.75;
}

/* Respecte le réglage système « réduire les animations ». */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* Section « Plus de détails » : les champs secondaires, repliés par défaut. */
.more > summary,
.advanced > summary {
  cursor: pointer;
  width: fit-content;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  list-style: none;
  transition: color 0.15s ease;
}

.more > summary:hover,
.advanced > summary:hover {
  color: var(--text);
}

.more > summary::-webkit-details-marker,
.advanced > summary::-webkit-details-marker {
  display: none;
}

.more > summary::before,
.advanced > summary::before {
  content: "▸ ";
}

.more[open] > summary::before,
.advanced[open] > summary::before {
  content: "▾ ";
}

.more > summary:focus-visible,
.advanced > summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Comme les tabpanels : l'espacement vient du conteneur, jamais des champs. */
.more__body {
  display: grid;
  gap: 1rem;
  align-content: start;
  margin-top: 0.9rem;
}

.links {
  display: grid;
  gap: 0.5rem;
}

.links__list {
  display: grid;
  gap: 0.5rem;
}

.button--ghost {
  justify-content: center;
  width: fit-content;
  padding: 0.4rem 0.7rem;
  font-size: 0.82rem;
  color: var(--accent);
  background: none;
  border-style: dashed;
}

/* Légende de la feuille imprimée : inutile à l'écran. */
.print-caption {
  display: none;
}

/* Réglages du QR code : séparés des champs, puisqu'ils n'en font pas partie. */
.advanced {
  width: 100%;
  margin-top: 0.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* À l'impression, seul le code et sa légende comptent. */
@media print {
  body {
    padding: 0;
    background: #fff;
    color: #000;
  }

  .app__header,
  .panel,
  .status,
  .notice,
  .actions,
  .advanced,
  .app__footer {
    display: none !important;
  }

  .result {
    border: none;
    box-shadow: none;
    padding: 0;
    background: none;
    /* Le code se retrouve au milieu de la feuille, prêt à être affiché. */
    justify-content: center;
    min-height: 90vh;
  }

  .preview {
    border: none;
    background: none;
    padding: 0;
    min-height: 0;
  }

  .preview__canvas {
    max-width: 11cm;
    padding: 0;
    box-shadow: none;
  }

  .print-caption {
    display: block;
    margin: 0.8cm 0 0;
    text-align: center;
    font-size: 12pt;
    line-height: 1.5;
    color: #000;
    white-space: pre-line;
  }
}

/* Contenu éditorial : sous l'outil, pour ne pas retarder son usage. */
.content {
  max-width: 44rem;
  color: var(--text);
}

.content h2 {
  margin: 2rem 0 0.6rem;
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: -0.015em;
}

.content h2:first-child {
  margin-top: 0;
}

.content h3 {
  margin: 1.4rem 0 0.4rem;
  font-size: 0.98rem;
  font-weight: 600;
}

.content p,
.content li {
  margin: 0.5rem 0;
  font-size: 0.94rem;
  line-height: 1.65;
  color: var(--text-muted);
}

.content ul {
  margin: 0.5rem 0;
  padding-left: 1.2rem;
}

.content strong {
  color: var(--text);
  font-weight: 600;
}

.content code {
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  font: 0.86em ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text);
}

@media print {
  .content {
    display: none !important;
  }
}
