* {
  box-sizing: border-box;
}

:root {
  --bg: #000;
  --panel: #0a0a0a;
  --hover: #0e0e0e;
  --active: #1a1a1a;
  --line: #222;
  --line-strong: #3a3a3a;
  --text: #c3c3c3;
  --muted: #6e6e6e;
  --bright: #f2f2f2;
  --danger: #c0392b;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  color-scheme: dark;
}

/* Barre, modes, réglages et colonnes remplissent l'écran ; l'export est posé juste en dessous. */
body {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Franklin Gothic Medium", "Arial Narrow", Arial, sans-serif;
  font-weight: 300;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible {
  outline: 1px solid var(--bright);
  outline-offset: -3px;
}

[hidden] {
  display: none !important;
}

.label {
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- Barre d'outils ---------- */

/* Barre, modes et réglages : les séparateurs sont l'espace de 1 px entre des blocs opaques
   posés sur un fond couleur de trait. Ils restent alignés quel que soit le retour à la ligne. */
.bar,
.modes,
.tune {
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}

.bar {
  display: flex;
  flex-wrap: wrap;
}

.ctrl {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  padding: 16px 20px;
  background: var(--bg);
}

.is-libre .ctrl--wheel {
  pointer-events: none;
}

.is-libre .ctrl--wheel > * {
  opacity: 0.35;
}

/* Couleur active (fondamentale, ou colonne sélectionnée en mode libre) */
.panel {
  display: flex;
  flex: 1 1 440px;
  gap: 18px;
  padding: 16px 20px;
  background: var(--bg);
}

.panel__swatch {
  position: relative;
  flex: none;
  width: 96px;
  min-height: 96px;
  border: 1px solid var(--line);
  cursor: pointer;
}

.panel__swatch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  opacity: 0;
  cursor: pointer;
}

.panel__body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.panel__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 12px;
}

.panel__text {
  flex: 1 1 9em;
  width: 9em;
  min-width: 0;
  padding: 2px 0 4px;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.95rem;
  color: var(--bright);
}

.panel__text:focus {
  outline: none;
  border-bottom-color: var(--muted);
}

.panel__text.is-invalid {
  border-bottom-color: var(--danger);
}

.gamut {
  padding: 1px 6px;
  border: 1px solid var(--line-strong);
  font-size: 0.68rem;
  white-space: nowrap;
  color: var(--muted);
}

.channels {
  display: grid;
  gap: 8px;
}

.ch {
  display: grid;
  grid-template-columns: 1.1em 1fr 4.6em;
  align-items: center;
  gap: 12px;
}

.ch__name {
  font-size: 0.8rem;
  color: var(--muted);
}

.ch__num,
.angle__num {
  width: 100%;
  padding: 2px 0;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.85rem;
  text-align: right;
  appearance: textfield;
  -moz-appearance: textfield;
}

.ch__num:focus,
.angle__num:focus {
  outline: none;
  border-bottom-color: var(--muted);
}

.ch__num::-webkit-inner-spin-button,
.ch__num::-webkit-outer-spin-button,
.angle__num::-webkit-inner-spin-button,
.angle__num::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button,
.stepper input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Nombre de colonnes */
.stepper {
  display: inline-flex;
  align-self: flex-start;
  border: 1px solid var(--line);
}

.stepper__btn {
  width: 34px;
  background: none;
  border: 0;
  font-size: 1.1rem;
}

.stepper__btn:hover {
  background: var(--active);
  color: var(--bright);
}

.stepper input {
  width: 3.4em;
  padding: 6px 0;
  background: none;
  border: 0;
  border-inline: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 1rem;
  text-align: center;
  color: var(--bright);
  appearance: textfield;
  -moz-appearance: textfield;
}

.stepper input:focus {
  outline: none;
  background: var(--hover);
}

/* Boutons segmentés */
.seg {
  display: inline-flex;
  align-self: flex-start;
  border: 1px solid var(--line);
}

.seg button {
  padding: 7px 13px;
  background: none;
  border: 0;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.seg button + button {
  border-left: 1px solid var(--line);
}

.seg button:hover {
  color: var(--text);
}

.seg button[aria-checked="true"] {
  background: var(--active);
  color: var(--bright);
}

/* ---------- Sliders ---------- */

.slider {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 48px;
  margin: 0;
  background: var(--track, #1c1c1c);
  border-radius: 1px;
  outline: none;
  cursor: pointer;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.38);
  border: 0;
  border-radius: 1px;
}

.slider::-moz-range-thumb {
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.38);
  border: 0;
  border-radius: 1px;
}

.slider::-moz-range-track {
  background: transparent;
}

.slider:focus-visible {
  outline: 1px solid var(--bright);
  outline-offset: 2px;
}

/* ---------- Modes d'harmonie ---------- */

/* Une seule rangée tant que la place suffit, puis une grille (voir plus bas) :
   des colonnes alignées gardent les séparateurs dans l'axe d'une rangée à l'autre. */
.modes {
  display: grid;
  grid-auto-flow: column;
}

.mode {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 11px 18px 12px;
  background: var(--bg);
  border: 0;
  text-align: left;
  color: var(--muted);
}

.mode__name {
  font-size: 0.95rem;
  color: var(--text);
}

.mode__hint {
  font-size: 0.7rem;
  letter-spacing: 0.03em;
}

.mode:hover {
  background: var(--hover);
}

.mode[aria-pressed="true"] {
  background: var(--active);
  box-shadow: inset 0 -2px 0 var(--bright);
}

.mode[aria-pressed="true"] .mode__name {
  color: var(--bright);
}

/* ---------- Réglages du mode : angles, contraste, ajustements ---------- */

.tune {
  display: flex;
  flex-wrap: wrap;
}

.is-libre .tune {
  display: none;
}

.tune__group {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 20px;
  background: var(--bg);
}

.tune__group--angles {
  flex: 3 1 380px;
  align-items: stretch;
  container-type: inline-size;
}

/* Base étroite : la note passe à la ligne plutôt que de renvoyer le groupe sous les autres. */
.tune__group--adjust {
  flex-basis: 260px;
}

.tune__head,
.tune__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 18px;
}

.tune__note,
.tune__empty {
  max-width: 30em;
  margin: 0;
  font-size: 0.74rem;
  line-height: 1.45;
  color: var(--muted);
}

.tune__note:empty {
  display: none;
}

.tune__info {
  font-size: 0.85rem;
}

.angles {
  display: grid;
  gap: 8px;
}

.angle {
  display: grid;
  grid-template-columns: 4.2em 1fr 4em minmax(7em, max-content);
  align-items: center;
  gap: 12px;
}

.angle__name {
  font-size: 0.8rem;
  color: var(--muted);
}

.angle__interval {
  font-size: 0.78rem;
  color: var(--text);
}

/* Groupe étroit (tablette en paysage, téléphone) : l'intervalle passe sous le slider pour lui laisser la place. */
@container (max-width: 480px) {
  .angle {
    grid-template-columns: 3.6em 1fr 3.6em;
  }

  .angle__interval {
    grid-column: 2 / -1;
    margin-top: -4px;
  }

  .angle__interval:empty {
    display: none;
  }
}

.tones {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
}

.tones span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tones i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.tones em {
  font-family: "Franklin Gothic Medium", "Arial Narrow", Arial, sans-serif;
  font-style: normal;
  color: var(--text);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--muted);
  cursor: pointer;
}

.check input {
  margin: 0;
  accent-color: #ddd;
}

.link {
  padding: 0;
  background: none;
  border: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.link:hover:not(:disabled) {
  color: var(--bright);
}

.link:disabled {
  opacity: 0.35;
  cursor: default;
}

/* ---------- Colonnes ---------- */

.row {
  display: grid;
  flex: 1 0 auto;
  grid-template-columns: repeat(var(--n, 9), minmax(48px, 1fr));
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
}

.col {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Swatches jointifs : le séparateur de colonne ne court que sous les couleurs. */
.col:last-child .col__sliders,
.col:last-child .col__values {
  border-right: 0;
}

.col__swatch {
  position: relative;
  flex: 1 1 auto;
  min-height: 7.5rem;
  background: var(--swatch);
  color: var(--ink);
  cursor: pointer;
  transition: background-color 0.18s ease;
}

.col__index {
  position: absolute;
  top: 8px;
  left: 9px;
  font-family: var(--mono);
  font-size: 0.75rem;
  opacity: 0.7;
}

.col__root,
.col__adj {
  display: none;
}

.col.is-root .col__root,
.col.is-adjusted .col__adj {
  display: inline;
}

.col__set {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 28px;
  height: 28px;
  padding: 0;
  background: none;
  border: 0;
  font-size: 1rem;
  color: var(--ink);
  opacity: 0;
  transition: opacity 0.15s;
}

.col__swatch:hover .col__set,
.col__set:focus-visible {
  opacity: 0.7;
}

.col__set:hover {
  opacity: 1 !important;
}

.is-libre .col__set,
.col.is-root .col__set {
  display: none;
}

@media (hover: none) {
  .col__set {
    opacity: 0.6;
  }
}

.col__reset {
  position: absolute;
  right: 3px;
  bottom: 3px;
  display: none;
  width: 28px;
  height: 28px;
  padding: 0;
  background: none;
  border: 0;
  font-size: 1rem;
  color: var(--ink);
  opacity: 0.75;
}

.col__reset:hover {
  opacity: 1;
}

.col.is-adjusted .col__reset {
  display: block;
}

/* Test de contraste : texte blanc et texte noir, dans leur vraie couleur */
.col__contrast {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 0 4px;
  pointer-events: none;
}

body[data-contrast="off"] .col__contrast {
  display: none;
}

.contrast {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  max-width: 100%;
  text-align: center;
}

.contrast--white {
  color: #fff;
}

.contrast--black {
  color: #000;
}

/* 16 px : taille de texte normale, celle à laquelle s'applique le seuil AA 4.5:1 */
.contrast__sample {
  font-size: 16px;
  font-weight: 400;
  line-height: 1.2;
}

.contrast__ratio {
  font-family: var(--mono);
  font-size: 0.72rem;
}

.contrast__grade {
  max-width: 100%;
  overflow: hidden;
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.contrast.is-pass .contrast__grade {
  font-weight: 700;
}

.col__flash {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--bright);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.col.is-copied .col__flash {
  opacity: 0.9;
}

.col__sliders {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 4px;
  border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.col__slider {
  display: grid;
  grid-template-columns: 1em minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  font-size: 0.68rem;
  color: var(--muted);
}

.col__values {
  position: relative;
  display: block;
  width: 100%;
  padding: 10px 4px 12px;
  background: none;
  border: 0;
  border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.74rem;
  line-height: 1.65;
  text-align: center;
  cursor: copy;
}

.col__parts {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  column-gap: 0.6em;
}

.col__parts span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.col__values:hover {
  background: var(--hover);
  color: var(--bright);
}

/* ---------- Export ---------- */

.export {
  position: absolute;
  top: 100%;
  right: 0;
  left: 0;
  padding: 22px 20px 48px;
}

.export__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 22px;
  margin-bottom: 12px;
}

.export__fields {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 22px;
}

.field {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
}

.field input {
  width: 7em;
  padding: 2px 0;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.85rem;
}

.field input:focus {
  outline: none;
  border-bottom-color: var(--muted);
}

.btn {
  padding: 7px 14px;
  background: none;
  border: 1px solid var(--line-strong);
  font-size: 0.82rem;
  letter-spacing: 0.06em;
}

.btn:hover:not(:disabled) {
  background: var(--active);
  color: var(--bright);
}

.btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.export__bar .btn {
  margin-left: auto;
}

.export__out {
  max-height: 26rem;
  margin: 0;
  padding: 16px 18px;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.55;
  color: #ddd;
}

/* ---------- Écrans moyens, tablettes, téléphones ---------- */

/* Les 11 modes ne tiennent plus sur une rangée : grille de 6, puis 4, puis 3 colonnes.
   Dans chacune il reste 2 places sur la dernière rangée (11 = 6 + 5 = 4 + 4 + 3 = 3 × 3 + 2) :
   « Libre » s'étend sur 2 colonnes pour la remplir. */
@media (max-width: 1559px) {
  .modes {
    grid-auto-flow: row;
    grid-template-columns: repeat(6, 1fr);
  }

  .mode:last-child {
    grid-column: span 2;
  }
}

/* Tablette en portrait : le panneau prend toute la largeur, les réglages se partagent la suivante. */
@media (max-width: 1000px) {
  .panel {
    flex-basis: 100%;
  }

  .ctrl {
    flex: 1 1 0;
  }

  .modes {
    grid-template-columns: repeat(4, 1fr);
  }

  .mode {
    padding: 10px 14px 11px;
  }

  .tune__group--angles {
    flex-basis: 100%;
  }
}

/* Tablette en paysage : hauteur comptée, on resserre pour que la palette reste visible. */
@media (min-width: 721px) and (max-height: 900px) and (orientation: landscape) {
  .ctrl,
  .panel {
    padding-block: 12px;
  }

  .panel__swatch {
    width: 80px;
    min-height: 80px;
  }

  .mode {
    padding-block: 8px 9px;
  }

  .tune__group {
    padding-block: 10px;
  }
}

@media (max-width: 720px) {
  .panel {
    padding: 14px 16px;
  }

  .panel__swatch {
    width: 64px;
    min-height: 64px;
  }

  .ctrl {
    flex: 1 1 auto;
    padding: 12px 16px;
  }

  .modes {
    grid-template-columns: repeat(3, 1fr);
  }

  .mode {
    padding: 9px 12px;
  }

  .tune__group {
    flex: 1 1 100%;
    padding: 12px 16px;
  }
}

/* ---------- Écrans tactiles : cibles à la taille du doigt ---------- */

@media (pointer: coarse) {
  /* Curseur de 48 px plus un peu de course par colonne */
  .row {
    grid-template-columns: repeat(var(--n, 9), minmax(64px, 1fr));
  }

  .col__sliders {
    padding-inline: 2px;
  }

  .seg button {
    min-height: 40px;
    padding-inline: 14px;
  }

  .stepper__btn {
    width: 44px;
  }

  .stepper input {
    padding-block: 10px;
  }

  .btn {
    min-height: 40px;
  }

  .check {
    min-height: 32px;
  }

  .check input {
    width: 18px;
    height: 18px;
  }

  .link {
    min-height: 32px;
  }

  .col__set,
  .col__reset {
    width: 40px;
    height: 40px;
  }
}
