/* Piano 1 ligne, auto-ajusté, sans largeur fixe */
.piano {
  --height: 120px;            /* hauteur des blanches */
  --key-gap: 2px;             /* espace entre blanches */
  --white-count: 14;          /* mis à jour en JS */
  /* largeur d'une blanche en tenant compte des gaps */
  --column-w: calc((100% - (var(--white-count) - 1) * var(--key-gap)) / var(--white-count));

  width: 100%;
  display: block;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  padding: 10px;
  border-radius: 14px;
  box-sizing: border-box;
}

.piano-inner {
  position: relative;
  width: 100%;
  height: var(--height);
}

/* --- LIGNE DES BLANCHES : flex, pas de wrap --- */
.white-keys {
  position: relative;
  display: flex;
  flex-wrap: nowrap;
  gap: var(--key-gap);
  height: 100%;
}

/* --- LIGNE DES NOIRES : overlay absolu --- */
.black-keys {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: calc(var(--height) * 0.62);
  pointer-events: none; /* les enfants restent cliquables */
  z-index: 3;
}

/* ---- Touches blanches (aucune largeur fixe !) ---- */
.piano-key.white {
    all:unset;
    position: relative;
    flex: 0 0 var(--column-w);  /* largeur auto en fonction du nombre de blanches */
    height: 100%;
    background: #fff;
    border-radius: 0 0 8px 8px;
    border: 1px solid #e5e7eb;
    box-shadow: inset 0 -2px 0 rgba(0,0,0,.06), 0 3px 0 rgba(0,0,0,.1);
    cursor: pointer;
    box-sizing: border-box;
}

.piano-key.white.active {
  background: #f3f4f6;
  box-shadow: inset 0 -1px 0 rgba(0,0,0,.12), 0 1px 0 rgba(0,0,0,.08);
  transform: translateY(1px);
}

/* ---- Touches noires ---- */
.piano-key.black {
    all:unset;
  position: absolute;
  top: 0;
  height: 100%;
  width: calc(var(--column-w) * 0.62); /* proportionnelle à la blanche */
  /* Centre entre la blanche i et i+1, en tenant compte du gap */
  left: calc(
    (var(--i) * (var(--column-w) + var(--key-gap))) + var(--column-w) + (var(--key-gap) / 2)
  );
  transform: translateX(-50%);
  background: linear-gradient(#111827, #000);
  border-radius: 0 0 10px 10px;
  border: 1px solid #111827;
  box-shadow: inset 0 -2px 0 rgba(255,255,255,.05), 0 6px 10px rgba(0,0,0,.35);
  z-index: 4;
  cursor: pointer;
  pointer-events: auto; /* réactive le clic sur la touche */
  box-sizing: border-box;
}

.piano-key.black.active {
  background: linear-gradient(#1f2937, #0b0b0b);
  transform: translateX(-50%) translateY(1px);
}

/* ---- Libellés ---- */
.piano-key .label {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  font: 500 clamp(9px, 1.2vw, 11px)/1.2 ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell;
  color: #555;
  pointer-events: none;
}
.piano-key.black .label { color: #e5e7eb; }

/* Focus clavier */
.piano-key:focus-visible {
  outline: 2px solid #4f46e5;
  outline-offset: 2px;
  border-radius: 6px;
}
