:root {
  --bg: #0c1117;
  --panel: #141c25;
  --panel-2: #1a2632;
  --text: #eef4fb;
  --muted: #9fb0c1;
  --line: #5c6875;
  --wood: #7f5539;
  --wood-2: #9b6b45;
  --fret: #d7dce2;
  --string: #e5e7eb;
  --accent: #54b6ff;
  --root: #ffd166;
  --chord: #7ce38b;
  --scale: #78b9ff;
  --caged: #ff8f70;
  --caged-third: #7ce38b;
  --caged-fifth: #73c8ff;
  --degree-1: #ffd166;
  --degree-2: #73c8ff;
  --degree-3: #7ce38b;
  --degree-4: #c6a0ff;
  --degree-5: #ff9f68;
  --degree-6: #67e0d1;
  --degree-7: #ff84b7;
  --success: #7ce38b;
  --danger: #ff8d8d;
  --warning: #ffd166;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #182634 0, var(--bg) 45%);
  color: var(--text);
}

button, select, input { font: inherit; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.page {
  width: min(1500px, calc(100% - 28px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.hero { margin-bottom: 18px; }
.module-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 24px; }
.module-nav a { display: inline-flex; align-items: center; min-height: 44px; }
.module-nav a:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.back-link { display: inline-block; margin-bottom: 12px; color: var(--accent); }
.hero h1 { margin: 4px 0 6px; font-size: clamp(2rem, 4vw, 3.5rem); }
.eyebrow, .section-kicker { color: var(--accent); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; font-size: .78rem; }
.subtitle { color: var(--muted); max-width: 980px; margin: 0; }

.panel {
  background: linear-gradient(180deg, rgba(255,255,255,.025), transparent), var(--panel);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 18px;
  box-shadow: 0 18px 55px rgba(0,0,0,.22);
}

.controls { padding: 18px; margin-bottom: 18px; }
.inline-group { display: flex; flex-wrap: wrap; gap: 12px 22px; align-items: center; }
.control-grid { display: grid; grid-template-columns: repeat(5, minmax(180px, 1fr)); gap: 14px; margin-top: 16px; }
.control-grid label { display: grid; align-content: start; gap: 7px; color: var(--muted); font-size: .9rem; }
select {
  width: 100%;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 10px;
  padding: 10px 12px;
}

.small-action, .primary-action, .secondary-action, .orientation-button {
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
}
.small-action { border: 1px solid rgba(84,182,255,.45); background: rgba(84,182,255,.08); color: var(--text); font-size: .82rem; }
.primary-action { border: 1px solid var(--accent); background: var(--accent); color: #071019; font-weight: 800; }
.secondary-action { border: 1px solid rgba(255,255,255,.18); background: var(--panel-2); color: var(--text); }
button:disabled { opacity: .45; cursor: not-allowed; }

.switch-row { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  width: 42px;
  height: 24px;
  background: #394654;
  border-radius: 999px;
  position: relative;
  transition: .18s ease;
  flex: 0 0 auto;
}
.switch::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #fff;
  transition: .18s ease;
}
.switch-row input:checked + .switch { background: var(--accent); }
.switch-row input:checked + .switch::after { transform: translateX(18px); }

.strings-control { margin-top: 16px; display: grid; gap: 8px; }
.label-title { color: var(--muted); font-size: .9rem; }
.string-toggles { display: flex; gap: 8px; flex-wrap: wrap; }
.string-button {
  border: 1px solid rgba(255,255,255,.12);
  background: #222e39;
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 11px;
  cursor: pointer;
}
.string-button.active { background: rgba(84,182,255,.16); color: var(--text); border-color: rgba(84,182,255,.55); }

.legend { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 16px; min-height: 24px; color: var(--muted); font-size: .9rem; }
.legend-item { display: inline-flex; align-items: center; gap: 7px; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.legend-dot.root, .legend-dot.caged-root { background: var(--root); }
.legend-dot.chord, .legend-dot.caged-third { background: var(--chord); }
.legend-dot.scale, .legend-dot.caged-fifth { background: var(--scale); }
.legend-dot.caged { background: var(--caged); }
.legend-dot.degree-1 { background: var(--degree-1); }
.legend-dot.degree-2 { background: var(--degree-2); }
.legend-dot.degree-3 { background: var(--degree-3); }
.legend-dot.degree-4 { background: var(--degree-4); }
.legend-dot.degree-5 { background: var(--degree-5); }
.legend-dot.degree-6 { background: var(--degree-6); }
.legend-dot.degree-7 { background: var(--degree-7); }
.legend-ring { width: 14px; height: 14px; border-radius: 50%; border: 3px solid var(--caged); display: inline-block; }
.degree-legend { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; }
.degree-title { color: var(--text); font-weight: 700; }

.learning-panel { padding: 18px; margin-bottom: 18px; }
.learning-heading { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; }
.learning-heading h2 { margin: 3px 0 7px; }
.learning-heading .section-kicker { margin: 0; }
.learning-intro { color: var(--muted); margin: 0; max-width: 920px; line-height: 1.5; }
.builder-switch { margin-top: 7px; flex: 0 0 auto; }
.builder-body { margin-top: 16px; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.08); transition: opacity .18s ease; }
.builder-body.is-disabled { opacity: .48; }
.builder-prompt { margin: 0 0 12px; font-size: 1.05rem; font-weight: 750; }
.builder-notes { display: grid; grid-template-columns: repeat(12, minmax(54px, 1fr)); gap: 7px; }
.builder-note {
  min-height: 46px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
}
.builder-note.selected { border-color: var(--accent); box-shadow: inset 0 0 0 2px rgba(84,182,255,.35); }
.builder-note.correct { background: rgba(124,227,139,.2); border-color: var(--success); }
.builder-note.wrong { background: rgba(255,141,141,.2); border-color: var(--danger); }
.builder-note.missing { border-color: var(--warning); border-style: dashed; }
.builder-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.builder-feedback { min-height: 24px; margin-top: 12px; color: var(--muted); line-height: 1.5; }
.builder-feedback strong { color: var(--text); }

.fretboard-panel { padding: 18px; overflow: hidden; }
.fretboard-toolbar { display: flex; justify-content: flex-end; margin-bottom: 14px; }
.orientation-button { border: 1px solid var(--accent); background: var(--panel-2); color: var(--text); }
.fretboard-scroll { overflow-x: auto; padding-bottom: 8px; }
.fretboard {
  min-width: 1220px;
  display: grid;
  grid-template-columns: 80px repeat(16, minmax(64px, 1fr));
  grid-template-rows: 36px repeat(6, 58px);
  background: linear-gradient(90deg, var(--wood), var(--wood-2));
  border-radius: 14px;
  overflow: hidden;
  border: 2px solid #4e3528;
  position: relative;
}

.fret-label, .string-label, .cell { position: relative; display: flex; align-items: center; justify-content: center; }
.fret-label { background: #111922; color: var(--muted); font-size: .78rem; border-right: 1px solid rgba(255,255,255,.08); }
.string-label { background: #111922; color: var(--text); font-size: .8rem; text-align: center; border-top: 1px solid rgba(255,255,255,.06); }
.cell { border-right: 3px solid rgba(225,231,238,.82); }
.cell::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  height: var(--string-width, 2px);
  background: linear-gradient(180deg, #fff, #a6aab0);
  box-shadow: 0 1px 1px rgba(0,0,0,.6);
}
.cell.nut { border-right-width: 7px; border-right-color: #f3ead7; }
.note {
  position: relative;
  z-index: 2;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: .82rem;
  color: #091017;
  background: rgba(238,244,251,.9);
  box-shadow: 0 3px 10px rgba(0,0,0,.25);
}
.note.muted-visual { opacity: .16; }
.note.chord-tone { background: var(--chord); }
.note.root-tone { background: var(--root); box-shadow: 0 0 0 3px rgba(255,209,102,.24); }
.note.scale-tone { background: var(--scale); }
.note.scale-secondary { opacity: .68; transform: scale(.88); }
.note.hidden-note { color: transparent; background: transparent; box-shadow: none; }
.note.degree-1 { background: var(--degree-1); }
.note.degree-2 { background: var(--degree-2); }
.note.degree-3 { background: var(--degree-3); }
.note.degree-4 { background: var(--degree-4); }
.note.degree-5 { background: var(--degree-5); }
.note.degree-6 { background: var(--degree-6); }
.note.degree-7 { background: var(--degree-7); }
.note.degree-badge::after, .note.degree-tone::after {
  content: attr(data-degree);
  position: absolute;
  right: -5px;
  bottom: -7px;
  min-width: 17px;
  height: 17px;
  padding: 0 3px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #111922;
  color: var(--text);
  font-size: .55rem;
  font-weight: 800;
  box-shadow: 0 1px 5px rgba(0,0,0,.35);
}
.note.chord-outline { box-shadow: 0 0 0 4px rgba(124,227,139,.9), 0 3px 10px rgba(0,0,0,.25); transform: scale(1.04); opacity: 1; }
.note.root-outline { box-shadow: 0 0 0 4px rgba(255,209,102,.95), 0 3px 10px rgba(0,0,0,.25); }

/* CAGED enrichi : 1 / 3 / 5 restent lisibles quel que soit le niveau choisi. */
.note.caged-degree-1 { background: var(--root); }
.note.caged-degree-3 { background: var(--caged-third); }
.note.caged-degree-5 { background: var(--caged-fifth); }
.note.caged-extension { background: #d4b4ff; opacity: .72; transform: scale(.88); }
.note.caged-chord-position { outline: 3px solid var(--caged); outline-offset: 2px; opacity: 1; transform: scale(1); }
.note.caged-chord-position::before {
  content: attr(data-caged-shape);
  position: absolute;
  top: -13px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--text);
  background: #111922;
  border-radius: 999px;
  padding: 1px 4px;
  font-size: .48rem;
  line-height: 1.2;
  white-space: nowrap;
}

.marker {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: rgba(255,255,255,.24);
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
}
.marker.double::after {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: rgba(255,255,255,.24);
  top: -26px;
}

.fretboard.vertical {
  min-width: 0;
  width: 100%;
  max-width: 560px;
  margin-inline: auto;
  grid-template-columns: 36px repeat(6, minmax(0, 1fr));
  grid-template-rows: 48px repeat(16, 60px);
  background: linear-gradient(180deg, var(--wood), var(--wood-2));
}
.vertical .string-label { white-space: pre-line; border-top: 0; border-left: 1px solid rgba(255,255,255,.06); }
.vertical .fret-label { font-size: .7rem; }
.vertical .cell { min-width: 0; border-right: 0; border-bottom: 3px solid rgba(225,231,238,.82); }
.vertical .cell.nut { border-bottom-width: 7px; border-bottom-color: #f3ead7; }
.vertical .cell::before {
  top: 0;
  bottom: 0;
  left: 50%;
  right: auto;
  width: var(--string-width, 2px);
  height: auto;
  transform: translateX(-50%);
  background: linear-gradient(90deg, #fff, #a6aab0);
}
.vertical .note { width: min(34px, calc(100% - 6px)); height: auto; aspect-ratio: 1; font-size: .75rem; }
.vertical .note.degree-badge::after, .vertical .note.degree-tone::after { left: 50%; right: auto; bottom: -12px; transform: translateX(-50%); white-space: nowrap; }
.vertical .note.caged-chord-position::before { top: -12px; }
.vertical .marker { width: 5px; height: 5px; bottom: 3px; }
.vertical .marker.double { margin-left: -5px; }
.vertical .marker.double::after { width: 5px; height: 5px; top: 0; left: 10px; }

.hint { color: var(--muted); font-size: .85rem; margin: 12px 0 0; }
.help { margin-top: 18px; padding: 18px; }
.help h2 { margin: 0 0 14px; }
.help-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.help article { background: rgba(255,255,255,.03); border-radius: 12px; padding: 14px; }
.help h3 { margin: 0 0 6px; }
.help p { color: var(--muted); margin: 0; line-height: 1.5; }

@media (max-width: 1180px) {
  .control-grid { grid-template-columns: repeat(3, minmax(180px, 1fr)); }
  .builder-notes { grid-template-columns: repeat(6, minmax(54px, 1fr)); }
}

@media (max-width: 850px) {
  .control-grid, .help-grid { grid-template-columns: 1fr; }
  .page { width: min(100% - 18px, 1500px); padding-top: 16px; }
  .fretboard-panel, .controls, .help, .learning-panel { padding: 13px; }
  .learning-heading { flex-direction: column; }
  .builder-switch { margin-top: 0; }
  .builder-notes { grid-template-columns: repeat(4, minmax(54px, 1fr)); }
}

/* L'encadrement blanc de la case reste indépendant des couleurs musicales. */
[hidden] { display: none !important; }
.switch-row { min-height: 44px; }
.switch-row input:focus-visible + .switch { outline: 3px solid var(--accent); outline-offset: 3px; }
.fretboard-toolbar { flex-wrap: wrap; gap: 10px; }
.analysis-mode .cell { padding: 0; border-top: 0; border-left: 0; border-bottom: 0; border-radius: 0; background: transparent; color: inherit; cursor: pointer; min-height: 44px; min-width: 44px; }
.analysis-mode.vertical { min-width: 298px; grid-template-columns: 30px repeat(6, minmax(44px, 1fr)); }
.analysis-mode.vertical .cell { border-right: 0; border-bottom: 3px solid rgba(225,231,238,.82); }
.analysis-mode.vertical .cell.nut { border-bottom-width: 7px; border-bottom-color: #f3ead7; }
.analysis-mode .cell.user-selected { box-shadow: inset 0 0 0 3px #fff; }
.analysis-mode .cell.user-selected::after { content: '✓'; position: absolute; top: 1px; right: 2px; z-index: 4; font: 800 11px/14px system-ui; color: #111; background: #fff; border-radius: 3px; padding: 0 2px; }
.analysis-mode .cell:focus-visible { outline: 3px dashed #fff; outline-offset: -6px; z-index: 5; }
.analysis-context { color: var(--text); line-height: 1.5; }
.analysis-panel { margin-top: 18px; padding: 18px; }
.analysis-panel details + details { margin-top: 14px; border-top: 1px solid rgba(255,255,255,.15); padding-top: 14px; }
.analysis-panel summary { min-height: 44px; padding: 10px 0; cursor: pointer; font-size: 1.1rem; font-weight: 750; }
.analysis-panel summary:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.analysis-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
@media (max-width: 380px) {
  .page { width: calc(100% - 8px); }
  .fretboard-panel { padding: 4px; }
}
.analysis-results { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 12px; margin: 12px 0; }
.analysis-card { min-width: 0; padding: 14px; border: 1px solid rgba(255,255,255,.15); border-radius: 12px; background: var(--panel-2); overflow-wrap: anywhere; }
.analysis-card h3 { margin: 0 0 10px; font-size: 1.05rem; }
.analysis-card p { margin: 7px 0; line-height: 1.45; color: var(--muted); }
.analysis-card .match-status, .analysis-card .selection-roles { color: var(--text); }
.analysis-card button { margin-top: 8px; max-width: 100%; }
.analysis-card button[aria-pressed="true"] { border-color: var(--accent); }
.result-group { grid-column: 1 / -1; margin: 0; }
#analysisScaleInfo p { line-height: 1.5; overflow-wrap: anywhere; }
.analysis-card.matches-selection { border: 2px solid #fff; }
.analysis-card button + button { margin-left: 8px; }
@media (max-width: 600px) {
  .analysis-card button { display: block; width: 100%; }
  .analysis-card button + button { margin-left: 0; }
}
.string-button, select { min-height: 44px; }
@media (max-width: 600px) {
  .analysis-results { grid-template-columns: 1fr; }
}
