:root {
  --bg: #f1f3f6;
  --surface: #ffffff;
  --surface-2: #e8ebf1;
  --line: #d3d8e2;
  --ink: #1a2130;
  --muted: #66708a;
  --accent: #4652c9;
  --accent-ink: #ffffff;
  --accent-soft: #e2e5fb;
  --root: #c98a1e;
  --root-soft: #fbefd6;
  --key-white: #fbfbfc;
  --key-black: #262b38;
  --key-line: #b9bfcc;
  --focus: #4652c9;
  --shadow: 0 1px 2px rgba(20, 28, 48, 0.06), 0 8px 24px -12px rgba(20, 28, 48, 0.18);
  --font-ui: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #12151c;
    --surface: #1b1f29;
    --surface-2: #242938;
    --line: #333a4c;
    --ink: #e8eaf0;
    --muted: #9aa3b8;
    --accent: #8c94f0;
    --accent-ink: #12151c;
    --accent-soft: #2b3060;
    --root: #e6a73a;
    --root-soft: #45351a;
    --key-white: #e4e6ec;
    --key-black: #14171f;
    --key-line: #8a90a0;
    --focus: #8c94f0;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12151c;
  --surface: #1b1f29;
  --surface-2: #242938;
  --line: #333a4c;
  --ink: #e8eaf0;
  --muted: #9aa3b8;
  --accent: #8c94f0;
  --accent-ink: #12151c;
  --accent-soft: #2b3060;
  --root: #e6a73a;
  --root-soft: #45351a;
  --key-white: #e4e6ec;
  --key-black: #14171f;
  --key-line: #8a90a0;
  --focus: #8c94f0;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.page {
  max-width: 1120px;
  margin: 0 auto;
  padding-block: 28px 56px;
  padding-inline: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
}
.page > * { min-width: 0; }
@media (min-width: 700px) { .page { padding-inline: 32px; } }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- En-tête ---------- */
.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 24px;
}
.masthead h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(28px, 4vw, 40px);
  letter-spacing: -0.01em;
  line-height: 1.1;
  text-wrap: balance;
}
.masthead p { margin: 0; color: var(--muted); max-width: 52ch; }

/* ---------- Contrôles ---------- */
.controls {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px 20px;
  align-items: end;
}
@media (min-width: 560px) { .field.wide { grid-column: span 2; } }
.field { display: grid; gap: 6px; }
.field > label, .field > .label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}
select {
  font: inherit;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}
.segmented {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
  flex-wrap: wrap;
}
.segmented button {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: transparent;
  border-radius: 6px;
  padding: 6px 8px;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}
.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(20, 28, 48, 0.12);
}
.btn {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ---------- Bande de la gamme ---------- */
.scale-strip {
  display: grid;
  gap: 12px;
}
.scale-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
}
.scale-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 24px;
}
.scale-head .formulas { display: grid; gap: 2px; justify-items: end; text-align: right; min-width: 0; max-width: 100%; }
.scale-head .formula { color: var(--muted); font-family: var(--font-mono); font-size: 13px; overflow-wrap: anywhere; }
.notes {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr) auto) minmax(0, 1fr) auto;
  gap: 8px 4px;
  align-items: center;
}
.step {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 2px 6px;
  min-width: 26px;
  text-align: center;
  line-height: 1.4;
  white-space: nowrap;
}
.step.s1 { color: var(--accent); background: var(--accent-soft); }
.step.s3 { color: var(--root); background: var(--root-soft); }
.step.to-octave { opacity: 0.55; }
.note-chip {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 6px 8px;
  display: grid;
  justify-items: center;
  gap: 2px;
  text-align: center;
  min-width: 0;
}
.note-chip .n {
  font-family: var(--font-display);
  font-size: clamp(20px, 3.4vw, 30px);
  line-height: 1;
  font-weight: 500;
}
.note-chip .d { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
.note-chip.is-root { border-color: var(--root); background: var(--root-soft); }
.note-chip.in-chord { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

/* ---------- Armure et gammes relatives ---------- */
.relatives .sig { font-family: var(--font-mono); font-size: 13px; color: var(--ink); text-align: right; min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
.relatives .panel-head { min-width: 0; }
.relatives .sig .alt { color: var(--root); }
.relatives-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 8px;
}
.rel-chip {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 8px 10px;
  display: grid;
  gap: 2px;
  text-align: left;
  min-width: 0;
}
.rel-chip:hover { border-color: var(--accent); }
.rel-chip .t { font-family: var(--font-display); font-size: 20px; line-height: 1.1; font-weight: 500; }
.rel-chip .t small { font-family: var(--font-mono); font-size: 11px; color: var(--muted); margin-left: 6px; font-weight: 400; }
.rel-chip .s { font-size: 12.5px; color: var(--muted); line-height: 1.3; }
.rel-chip.is-current { border-color: var(--root); background: var(--root-soft); cursor: default; }
.rel-chip:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Tableau des armures ---------- */
details.panel { display: block; }
details.panel > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary::before {
  content: "▸";
  color: var(--muted);
  font-size: 12px;
  margin-right: -4px;
}
details.panel[open] > summary::before { content: "▾"; }
details.panel > summary h3 {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}
details.panel > summary .hint { margin: 0; }
.cof-wrap { margin-top: 10px; border: 0; box-shadow: none; border-radius: 0; background: transparent; }
.cof-table {
  border-collapse: separate;
  border-spacing: 2px;
  table-layout: fixed;
  min-width: 1040px;
  width: 100%;
  font-family: var(--font-mono);
  font-size: 12.5px;
}
.cof-table th {
  font-weight: 500;
  color: var(--muted);
  padding: 4px 2px;
  text-align: center;
  vertical-align: bottom;
}
.cof-table col.mode-col { width: 140px; }
.cof-table th.mode { text-align: left; font-family: var(--font-ui); font-size: 12.5px; padding-right: 10px; white-space: nowrap; }
.cof-table th.mode small { display: block; color: var(--muted); font-weight: 400; font-size: 11px; }
.cof-table th .acc {
  display: block;
  font-size: 10px;
  color: var(--muted);
  font-weight: 400;
  line-height: 1.35;
  white-space: normal;
  max-width: 56px;
  margin: 2px auto 0;
}
.cof-table th.k0 { color: var(--ink); }
.cof-table td { padding: 0; text-align: center; }
.cof-btn {
  width: 100%;
  border: 1px solid transparent;
  background: var(--surface-2);
  border-radius: 6px;
  padding: 5px 4px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.2;
  white-space: nowrap;
}
.cof-btn:hover { border-color: var(--accent); }
.cof-table .is-col .cof-btn { background: var(--accent-soft); }
.cof-table .is-col th { color: var(--ink); }
.cof-btn.is-cell { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.cof-table tr.is-major .cof-btn { font-weight: 600; }

/* ---------- Instruments ---------- */
.instruments {
  display: grid;
  gap: 16px;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px 16px;
  display: grid;
  gap: 10px;
}
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.panel-head h3 {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.legend span::before {
  content: "";
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: -1px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.legend .l-root::before { background: var(--root); border-color: var(--root); }
.legend .l-chord::before { background: var(--accent); border-color: var(--accent); }

.piano-wrap { overflow-x: auto; }
.piano {
  position: relative;
  height: 128px;
  min-width: 560px;
  display: flex;
  user-select: none;
}
.key {
  position: relative;
  border: 1px solid var(--key-line);
  padding: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 12px;
  transition: background 120ms;
}
.key.white {
  flex: 1;
  background: var(--key-white);
  color: #4a5164;
  border-radius: 0 0 5px 5px;
  margin-right: -1px;
  padding-bottom: 6px;
}
.key.black {
  position: absolute;
  top: 0;
  width: 4.1%;
  height: 62%;
  background: var(--key-black);
  color: #d5d8e2;
  border-radius: 0 0 4px 4px;
  z-index: 2;
  padding-bottom: 5px;
  font-size: 11px;
}
.key .lbl { pointer-events: none; }
.key.in-scale .lbl {
  background: var(--surface-2);
  color: var(--ink);
  border-radius: 999px;
  padding: 1px 6px;
}
.key.is-root .lbl { background: var(--root); color: #1a1408; }
.key.in-chord .lbl { background: var(--accent); color: var(--accent-ink); }
.key.in-chord.white { background: color-mix(in srgb, var(--accent) 18%, var(--key-white)); }
.key.in-chord.black { background: color-mix(in srgb, var(--accent) 45%, var(--key-black)); }
.key.playing { filter: brightness(0.9); }

.fret-wrap { overflow-x: auto; }
.fretboard { display: block; min-width: 560px; width: 100%; height: auto; }
.fretboard .string { stroke: var(--key-line); }
.fretboard .fret { stroke: var(--line); }
.fretboard .nut { stroke: var(--muted); stroke-width: 4; }
.fretboard .inlay { fill: var(--surface-2); }
.fretboard .fret-num { fill: var(--muted); font-family: var(--font-mono); font-size: 10px; }
.fretboard .pos circle { fill: var(--surface); stroke: var(--line); stroke-width: 1; }
.fretboard .pos text {
  fill: var(--ink);
  font-family: var(--font-mono);
  font-size: 9.5px;
  text-anchor: middle;
  dominant-baseline: central;
}
.fretboard .pos.is-root circle { fill: var(--root); stroke: var(--root); }
.fretboard .pos.is-root text { fill: #1a1408; }
.fretboard .pos.in-chord circle { fill: var(--accent); stroke: var(--accent); }
.fretboard .pos.in-chord text { fill: var(--accent-ink); }

/* ---------- Grille des accords ---------- */
.chords-section { display: grid; gap: 12px; }
.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
table.chords {
  border-collapse: collapse;
  width: 100%;
  min-width: 640px;
}
table.chords th, table.chords td {
  text-align: left;
  vertical-align: top;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
table.chords th {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}
table.chords tbody tr:last-child td { border-bottom: 0; }
table.chords tbody tr.is-tonic td:first-child { box-shadow: inset 3px 0 0 var(--root); }
td.deg { white-space: nowrap; width: 1%; }
table.chords th:first-child { width: 1%; }
td.deg .roman {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 500;
  line-height: 1;
}
td.deg .fn { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
td.deg .note { display: block; font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
.chord-btn {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
  padding: 6px 8px;
  margin: -6px -8px;
  text-align: left;
  display: grid;
  gap: 2px;
  min-width: 100%;
}
.chord-btn:hover { background: var(--surface-2); border-color: var(--line); }
.chord-btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.chord-btn .sym { font-weight: 600; font-size: 15.5px; white-space: nowrap; }
.chord-btn .nts { font-family: var(--font-mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
.col-hidden { display: none; }

/* ---------- Détail de l'accord sélectionné ---------- */
.chord-detail {
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 16px;
  display: grid;
  gap: 12px;
}
.chord-detail .top {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
}
.chord-detail h3 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 30px;
  line-height: 1;
}
.chord-detail h3 small { font-family: var(--font-ui); font-size: 14px; color: var(--muted); margin-left: 10px; }
.chord-detail .tones {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.tone {
  display: grid;
  justify-items: center;
  gap: 1px;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 6px 12px;
  min-width: 56px;
}
.tone b { font-family: var(--font-display); font-size: 20px; font-weight: 500; line-height: 1.1; }
.tone span { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); }
.tone.is-root { background: var(--root-soft); }
.chord-detail .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.hint { color: var(--muted); font-size: 13px; margin: 0; }

@media (max-width: 640px) {
  .notes {
    gap: 5px 3px;
    overflow-x: auto;
    padding-bottom: 4px;
    grid-template-columns: repeat(6, minmax(60px, 1fr) auto) minmax(60px, 1fr) auto;
  }
  .note-chip .d { white-space: nowrap; }
  .step { font-size: 10.5px; padding: 1px 3px; min-width: 20px; }
  .scale-head .formulas { justify-items: start; text-align: left; }
  .note-chip { padding: 8px 2px 6px; border-radius: 8px; }
  .chord-detail h3 { font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
