/* ===== Piano — thème scène sombre, accent ambre ===== */
:root {
  --bg: #0b0d12;
  --bg-2: #14161d;
  --surface: #1a1d26;
  --border: #2a2e3a;
  --text: #e8e6e1;
  --text-dim: #9a9890;
  --accent: #f59e0b;
  --accent-deep: #d97706;
  --felt: #7f1d1d;
  --white-key: linear-gradient(180deg, #f7f4ec 0%, #efeadf 82%, #ddd6c6 100%);
  --white-key-down: linear-gradient(180deg, #e8e2d4 0%, #ddd5c2 82%, #c9c0aa 100%);
  --black-key: linear-gradient(180deg, #34363c 0%, #17181c 12%, #060708 90%);
  --black-key-down: linear-gradient(180deg, #232429 0%, #101114 12%, #030304 90%);
  --focus: 0 0 0 3px rgba(245, 158, 11, .55);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(1100px 500px at 50% 62%, rgba(245, 158, 11, .07), transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-user-select: none;
  user-select: none;
}

/* ===== Barre du haut ===== */
.topbar {
  position: relative;
  z-index: 100; /* le popover réglages doit passer au-dessus de la scène */
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 13, 18, .7);
  backdrop-filter: blur(8px);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: .04em;
  background: linear-gradient(90deg, #fbbf24, #f59e0b, #d97706);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.logo { width: 26px; height: 26px; color: var(--accent); }
.logo.big { width: 44px; height: 44px; }

.note-display {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 110px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-variant-numeric: tabular-nums;
}
.nd-note { font-size: 20px; font-weight: 700; color: var(--accent); min-width: 46px; }
.nd-key { font-size: 13px; color: var(--text-dim); }

.controls { display: flex; align-items: center; gap: 10px; margin-left: auto; flex-wrap: wrap; }

.ctl-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 14px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color .2s, background .2s, transform .15s;
  touch-action: manipulation;
}
.ctl-btn:hover { border-color: var(--accent-deep); }
.ctl-btn:active { transform: scale(.97); }
.ctl-btn:focus-visible { outline: none; box-shadow: var(--focus); }
.ctl-btn svg { width: 18px; height: 18px; color: var(--text-dim); }

.ctl-btn .dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: #3f4351;
  transition: background .15s, box-shadow .15s;
}
.ctl-btn.on { border-color: var(--accent-deep); }
.ctl-btn.on .dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }

.transpose { display: inline-flex; }
.transpose .ctl-btn { border-radius: 0; }
.transpose .ctl-btn:first-child { border-radius: 10px 0 0 10px; }
.transpose .ctl-btn:last-child { border-radius: 0 10px 10px 0; border-left: none; }
.ctl-btn.sq {
  min-width: 44px;
  justify-content: center;
  padding: 8px 10px;
  font-size: 17px;
  font-weight: 600;
}
.ctl-btn.val {
  min-width: 52px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  border-left: none;
}
.ctl-btn.val.active { color: var(--accent); }

.vol {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.vol svg { width: 18px; height: 18px; color: var(--text-dim); }
.vol input[type="range"] { width: 110px; accent-color: var(--accent); cursor: pointer; }
.vol input[type="range"]:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 4px; }

.settings-wrap { position: relative; }
.settings-pop {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 210px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 14px 34px -12px rgba(0, 0, 0, .8);
}
.settings-pop .sp-title {
  margin: 0 0 2px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.settings-pop .sp-note {
  margin: 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-dim);
}
.settings-pop .sp-note strong { color: var(--accent); }
.settings-pop label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  cursor: pointer;
  min-height: 28px;
}
.settings-pop label.opt-off { opacity: .4; }
.settings-pop input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}
.settings-pop .sp-slider {
  gap: 10px;
  font-size: 13px;
  color: var(--text-dim);
}
.settings-pop .sp-slider span { min-width: 62px; }
.settings-pop .sp-slider b { color: var(--accent); font-variant-numeric: tabular-nums; }
.settings-pop .sp-slider input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
}
.settings-pop .sp-slider select {
  flex: 1;
  min-width: 0;
  min-height: 32px;
  padding: 4px 8px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
/* Ascenseur permanent du menu réglages : on VOIT qu'il y a de quoi défiler */
.settings-pop {
  scrollbar-width: thin;
  scrollbar-color: var(--accent-deep) var(--border);
}
.settings-pop::-webkit-scrollbar { width: 6px; }
.settings-pop::-webkit-scrollbar-track { background: var(--border); border-radius: 3px; }
.settings-pop::-webkit-scrollbar-thumb { background: var(--accent-deep); border-radius: 3px; }

.sp-version {
  margin: 4px 0 0;
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  letter-spacing: .04em;
}

/* Indicateur « il y a plus de réglages en bas » */
.sp-more {
  display: none;
  position: sticky;
  bottom: -14px;
  margin: -10px -16px -14px;
  padding: 22px 0 6px;
  justify-content: center;
  background: linear-gradient(180deg, transparent, var(--surface) 60%);
  pointer-events: none;
}
.sp-more svg {
  width: 18px;
  height: 18px;
  color: var(--accent);
  animation: sp-bounce 1.4s ease-in-out infinite;
}
@keyframes sp-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(4px); }
}
.settings-pop.scroll-hint .sp-more { display: flex; }

.sp-reset {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--text-dim);
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.sp-reset:hover { color: var(--accent); border-color: var(--border); }
.sp-reset:focus-visible { outline: none; box-shadow: var(--focus); }
.sp-reset svg { width: 13px; height: 13px; }

.badge {
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  color: #0b0d12;
  background: var(--accent);
  border-radius: 999px;
}
.badge-off { background: #64748b; color: #f1f5f9; }

/* ===== Scène ===== */
.stage {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 22px;
  padding: 26px 18px 34px;
}

/* ===== Arène : piano + panneau partition, dockable ===== */
.arena {
  display: flex;
  gap: 18px;
  width: min(1500px, 100%);
  justify-content: center;
}
.arena[data-dock="bottom"] { flex-direction: column; }
.arena[data-dock="top"]    { flex-direction: column-reverse; }
.arena[data-dock="right"]  { flex-direction: row; align-items: stretch; }
.arena[data-dock="left"]   { flex-direction: row-reverse; align-items: stretch; }

/* En mode latéral : panneau redimensionnable en largeur, piano prend le reste */
.arena[data-dock="left"] .piano-shell,
.arena[data-dock="right"] .piano-shell { flex: 1; min-width: 0; }
.arena[data-dock="left"] .sheet,
.arena[data-dock="right"] .sheet {
  width: 340px;
  min-width: 240px;
  max-width: 75vw;
  resize: horizontal;
  overflow: auto;
}
.arena[data-dock="left"] .sheet textarea,
.arena[data-dock="right"] .sheet textarea { min-height: 160px; }

/* En portrait sur petit écran, pas la place pour un panneau latéral :
   tout passe en colonne. En paysage, le choix de dock est respecté. */
@media (max-width: 900px) and (orientation: portrait) {
  /* pas de panneau latéral en portrait : gauche/droite/bas → sous le piano,
     mais on respecte le dock « haut » (panneau au-dessus du piano) */
  .arena { flex-direction: column !important; }
  .arena[data-dock="top"] { flex-direction: column-reverse !important; }
  .arena .sheet { width: 100% !important; resize: none; }
}

/* En paysage, la largeur des touches suit le curseur (comme ailleurs) :
   si les touches débordent, l'ascenseur horizontal réapparaît ; si on
   réduit la largeur, tout le clavier tient à l'écran. */

.fx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

.piano-shell {
  width: min(1500px, 100%);
  padding: 16px 16px 22px;
  border-radius: 18px;
  background: linear-gradient(180deg, #23180f 0%, #170f09 60%, #0e0906 100%);
  border: 1px solid #3a2a18;
  box-shadow:
    0 30px 60px -20px rgba(0, 0, 0, .8),
    0 0 90px -30px rgba(245, 158, 11, .25),
    inset 0 1px 0 rgba(255, 255, 255, .05);
}

.piano-scroll { overflow-x: auto; border-radius: 8px; }

/* Bande « cascade » : les notes à jouer tombent vers leur touche */
.cascade {
  display: block;
  width: 100%;
  min-width: max(calc(940px * var(--key-w, 1)), 100%);
  height: clamp(80px, 14vw, 130px);
  border-radius: 8px 8px 0 0;
  background: linear-gradient(180deg, rgba(8, 10, 16, 0) 0%, rgba(8, 10, 16, .35) 100%);
}
.cascade[hidden] { display: none; }
/* espace compté : pas de cascade en touches seules ni en paysage roté */
body.keys-only .cascade,
body.css-landscape .cascade { display: none !important; }

.piano {
  position: relative;
  height: calc(clamp(150px, 26vw, 260px) * var(--key-h, 1));
  /* si le zoom rend le clavier plus étroit que l'écran, il s'étire pour le remplir */
  min-width: max(calc(940px * var(--key-w, 1)), 100%);
  border-radius: 0 0 8px 8px;
  /* feutre rouge au-dessus des touches */
  border-top: 7px solid var(--felt);
  background: #0a0a0c;
  touch-action: none;
  overflow: hidden; /* les étiquettes ne créent pas de défilement à petit zoom */
}

/* touch-action: none sur les touches → réponse instantanée à l'effleurement
   (le navigateur ne « guette » plus un éventuel défilement avant de valider). */
.key { position: absolute; top: 0; cursor: pointer; touch-action: none; }

.key.white {
  height: 100%;
  background: var(--white-key);
  border: 1px solid #b9b2a0;
  border-top: none;
  border-radius: 0 0 5px 5px;
  box-shadow: inset 0 -6px 8px -6px rgba(0, 0, 0, .45);
  transition: background .05s;
  z-index: 1;
}
.key.white.down {
  background: linear-gradient(180deg, #9ec8ff 0%, #5ea3f8 70%, #3b82f6 100%);
  border-color: #2f6cd0;
  box-shadow:
    inset 0 -3px 5px -4px rgba(0, 0, 0, .5),
    inset 0 4px 10px rgba(255, 255, 255, .35),
    0 0 18px rgba(59, 130, 246, .95),
    0 0 36px rgba(34, 211, 238, .5);
}
.key.white.down .lbl { color: #0b2b5e; }
.key.white.down .lbl-key { border-color: #3b82f6; background: rgba(219, 234, 254, .85); }

.key.black {
  height: 62%;
  background: var(--black-key);
  border: 1px solid #000;
  border-top: none;
  border-radius: 0 0 4px 4px;
  box-shadow:
    0 4px 6px rgba(0, 0, 0, .6),
    inset 0 -8px 10px -8px rgba(255, 255, 255, .18);
  transition: background .05s;
  z-index: 2;
}
.key.black.down {
  background: linear-gradient(180deg, #3f7fe8 0%, #2563c9 12%, #123a7d 90%);
  height: 61%;
  box-shadow:
    0 2px 3px rgba(0, 0, 0, .55),
    0 0 18px rgba(59, 130, 246, 1),
    0 0 36px rgba(34, 211, 238, .55),
    inset 0 -6px 8px -8px rgba(255, 255, 255, .3);
}
.key.black.down .lbl { color: #dbeafe; }

/* Étiquettes des touches */
.key .lbl {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 600;
  pointer-events: none;
  display: none;
}
.key.white .lbl { bottom: 8px; color: #6b6656; }
.key.black .lbl { bottom: 6px; color: #b3ada0; font-size: 10px; }

body[data-labels="keys"]  .lbl-key  { display: block; }
body[data-labels="notes"] .lbl-note { display: block; }

.key .lbl-key { text-transform: none; }
.key.white .lbl-key {
  min-width: 17px;
  padding: 2px 0;
  border: 1px solid #cfc8b6;
  border-radius: 4px;
  background: rgba(255, 255, 255, .55);
}

/* Marqueur du Do central (C4) */
.key.c4::after {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 26px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: rgba(217, 119, 6, .55);
}
body[data-labels="keys"] .key.c4::after,
body[data-labels="notes"] .key.c4::after { bottom: 30px; }

/* ===== Touches suggérées (Key Assist / partition) — bleu ===== */
.key.white.hint {
  background: linear-gradient(180deg, #c7ddfb 0%, #93bdf5 82%, #6ea5ec 100%);
  box-shadow: inset 0 -6px 8px -6px rgba(0, 0, 0, .45), 0 0 18px rgba(59, 130, 246, .65);
}
.key.black.hint {
  background: linear-gradient(180deg, #1e4e96 0%, #143668 12%, #0b1f3f 90%);
  box-shadow: 0 4px 6px rgba(0, 0, 0, .6), 0 0 18px rgba(59, 130, 246, .8);
}
.key.hint .lbl { color: #123763; }
.key.white.hint .lbl-key { border-color: #7fa9dd; background: rgba(219, 234, 254, .75); }
.key.black.hint .lbl { color: #bfdbfe; }

/* ===== Panneau partition ===== */
.sheet {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.sheet textarea {
  width: 100%;
  max-width: 100%;
  resize: both;   /* agrandissable librement, hauteur ET largeur */
  min-height: 64px;
  padding: 10px 12px 16px;   /* place pour la poignée en bas à droite */
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  /* Poignée de redimensionnement bien visible : chevrons accent en bas à droite */
  background-color: var(--bg);
  background-image: linear-gradient(135deg,
    transparent 0 3px, var(--accent) 3px 5px,
    transparent 5px 8px, var(--accent) 8px 10px,
    transparent 10px 13px, var(--accent) 13px 15px, transparent 15px);
  background-repeat: no-repeat;
  background-position: right 4px bottom 4px;
  background-size: 16px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.sheet textarea:focus-visible { outline: none; box-shadow: var(--focus); }
/* Zone de préhension agrandie et transparente (les chevrons ci-dessus font le visuel) */
.sheet textarea::-webkit-resizer { background: transparent; }
.sheet-lib { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sheet-lib .maxbtn { margin-left: auto; min-width: 38px; justify-content: center; }
.sheet-lib .maxbtn svg { width: 15px; height: 15px; }

/* Menu « ⋯ » d'actions secondaires de la bibliothèque */
.lib-more-wrap { position: relative; display: inline-flex; }
.lib-more-wrap .sq { min-width: 38px; justify-content: center; }
.lib-more-wrap .sq svg { width: 18px; height: 18px; }
.lib-more-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 95;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 150px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .5);
}
.lm-item {
  min-height: 38px;
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
  text-align: left;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
}
.lm-item:hover { background: var(--bg); border-color: var(--border); }
.lm-item:focus-visible { outline: none; box-shadow: var(--focus); }
.lm-item.danger { border-color: #dc2626; color: #fecaca; }

/* Panneau maximisé : lecture épurée — partition en GRAND + barre de lecture ;
   les outils (bibliothèque, recherche…) sont repliés dans un tiroir dépliable via ⌄. */
.sheet.max {
  position: fixed;
  inset: 80px 18px 18px 18px;
  z-index: 90;
  width: auto !important;
  max-width: none !important;
  resize: none;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .75), 0 0 0 1px var(--border);
}
/* Ordre en agrandi : en-tête (outils/fermer) → partition → lecture en bas */
.sheet.max .sheet-lib     { order: -3; justify-content: flex-end; }
.sheet.max .save-row      { order: -2; }
.sheet.max .midi-search   { order: -2; }
.sheet.max .midi-results  { order: -2; }
/* La partition remplit tout l'espace ; width/height en !important pour écraser
   la taille figée que l'utilisateur a pu donner à la zone via le resize (styles inline). */
.sheet.max textarea       { order: -1; flex: 1; resize: none; width: 100% !important; height: auto !important; min-height: 0; font-size: 18px; line-height: 1.8; }
.sheet.max .sheet-actions { order: 0; }

/* Le bouton « détacher » reste visible dans l'en-tête agrandi, groupé à droite. */
.sheet-lib .detachbtn { margin-left: auto; }

/* Le bouton ⌄ « outils » n'apparaît qu'en agrandi. */
.toolsbtn { display: none; }
.sheet.max .toolsbtn { display: inline-flex; }
.sheet.max .toolsbtn svg { transition: transform .18s; }
.sheet.max.max-tools .toolsbtn svg { transform: rotate(180deg); }

/* Tiroir replié par défaut : on masque les contrôles bibliothèque + recherche,
   en gardant ⤢ (détacher), ⌄ (outils) et ⛶ (fermer) dans l'en-tête. */
.sheet.max:not(.max-tools) .sheet-lib > :not(.maxbtn):not(.toolsbtn):not(.detachbtn) { display: none; }
.sheet.max:not(.max-tools) .save-row,
.sheet.max:not(.max-tools) .midi-search,
.sheet.max:not(.max-tools) .midi-results { display: none; }
/* Barre de lecture réduite à l'essentiel quand le tiroir est fermé */
.sheet.max:not(.max-tools) #recBtn,
.sheet.max:not(.max-tools) #shareBtn,
.sheet.max:not(.max-tools) .dock { display: none; }
.sheet-lib select {
  min-height: 38px;
  padding: 6px 10px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  max-width: 240px;
}
.sheet-lib select:focus-visible { outline: none; box-shadow: var(--focus); }
.ctl-btn.sm2 { min-height: 38px; padding: 6px 12px; font-size: 13px; }

.midi-search,
.save-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.save-row svg { width: 16px; height: 16px; color: var(--accent); flex-shrink: 0; }
.save-row input {
  flex: 1;
  min-height: 38px;
  padding: 6px 12px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--accent-deep);
  border-radius: 10px;
}
.save-row input:focus-visible { outline: none; box-shadow: var(--focus); }
#saveOk { border-color: var(--accent-deep); }

.ctl-btn.danger { border-color: #dc2626; color: #fecaca; }
.midi-search svg { width: 16px; height: 16px; color: var(--text-dim); flex-shrink: 0; }
.midi-search input {
  flex: 1;
  min-height: 38px;
  padding: 6px 12px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.midi-search input:focus-visible { outline: none; box-shadow: var(--focus); }

.midi-results {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: min(220px, 45vh);   /* jamais plus haut que l'écran */
  overflow-y: auto;
  padding: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.midi-results .mr-item { min-height: 40px; } /* résultats bien tapables */
.midi-results .mr-info { margin: 4px 6px; font-size: 13px; color: var(--text-dim); }
.midi-results .mr-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
  text-align: left;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}
.midi-results .mr-item:hover { border-color: var(--accent-deep); background: var(--surface); }
.midi-results .mr-item:focus-visible { outline: none; box-shadow: var(--focus); }
.midi-results .mr-item[disabled], .midi-results .mr-play[disabled] { opacity: .5; cursor: wait; }
.midi-results .mr-item small { color: var(--text-dim); white-space: nowrap; }
.midi-results .mr-row { display: flex; align-items: stretch; gap: 6px; }
.midi-results .mr-row .mr-item { flex: 1; min-width: 0; }
.midi-results .mr-play {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  min-height: 40px;
  color: var(--accent-deep);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.midi-results .mr-play svg { width: 18px; height: 18px; }
.midi-results .mr-play:hover { border-color: var(--accent-deep); background: var(--surface); }
.midi-results .mr-play:focus-visible { outline: none; box-shadow: var(--focus); }

#recBtn svg { color: #ef4444; }
#recBtn.recording {
  border-color: #ef4444;
  color: #fecaca;
}
#recBtn.recording svg { animation: rec-pulse 1s ease-in-out infinite; }
@keyframes rec-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .25; }
}

/* Boutons de lecture au-dessus de la sélection de musique */
.sheet-actions { order: -2; }
.sheet-lib { order: -1; }

.mode-badge {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
}
.mode-badge b { color: var(--text-dim); font-weight: 600; }
.mode-badge.auto b { color: var(--accent); }

.sheet-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sheet-actions .ctl-btn[disabled] { opacity: .45; cursor: default; }

/* ===== Responsive du menu partition (portrait + paysage étroits) ===== */
.sheet > * { max-width: 100%; }
.sheet-lib, .sheet-actions, .save-row, .midi-search { min-width: 0; }
.sheet-lib select { flex: 1 1 140px; min-width: 0; }
.midi-search input { min-width: 0; }
@media (max-width: 600px) {
  .sheet { padding: 10px; gap: 8px; }
  .sheet-actions { gap: 6px; }
  .sheet-actions .ctl-btn { min-height: 40px; padding: 8px 10px; font-size: 13px; }
  .sheet-lib .ctl-btn.sm2, .midi-search .ctl-btn.sm2 { min-height: 36px; padding: 6px 9px; font-size: 12px; }
  .tempo { padding: 5px 8px; gap: 6px; }
  .tempo input[type="range"] { width: 72px; }
  .sheet-progress { flex-basis: 100%; }   /* le message passe sur sa propre ligne */
  .dock { margin-left: 0; }
}
/* Paysage court : le panneau garde une hauteur bornée et défile à l'intérieur */
@media (orientation: landscape) and (max-height: 560px) {
  .arena .sheet:not(.max) { max-height: 46vh; overflow-y: auto; }
}
.sheet-actions .ctl-btn svg { width: 16px; height: 16px; }
#autoStart svg { color: var(--accent); }

.tempo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 6px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.tempo svg { width: 16px; height: 16px; color: var(--text-dim); }
.tempo input[type="range"] { width: 90px; accent-color: var(--accent); cursor: pointer; }
.tempo .ctl-btn.tp {
  min-width: 30px;
  min-height: 30px;
  padding: 2px 8px;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  border-radius: 8px;
}
.tempo-val {
  min-width: 30px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  text-align: right;
}

.dock { display: flex; gap: 4px; margin-left: auto; }
.dock .ctl-btn.dk { min-width: 38px; min-height: 38px; padding: 6px; justify-content: center; }
.dock .ctl-btn.dk svg { width: 15px; height: 15px; }
.dock .ctl-btn.dk.active { border-color: var(--accent-deep); }
.dock .ctl-btn.dk.active svg { color: var(--accent); }
.sheet-progress { font-size: 13px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.sheet-progress.done { color: var(--accent); font-weight: 600; }

.hint {
  margin: 0;
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.6;
}
.hint kbd {
  padding: 2px 7px;
  font-family: inherit;
  font-size: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
}

/* ===== Fronton laqué + signature de marque ===== */
.piano-top {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: clamp(64px, 8.5vw, 104px);
  margin-bottom: 12px;
  border-radius: 12px 12px 5px 5px;
  background: linear-gradient(180deg, #23242b 0%, #0c0d11 50%, #131419 88%, #1a1b21 100%);
  border: 1px solid #3a2c1c;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .09),
    inset 0 -10px 22px rgba(0, 0, 0, .65),
    0 6px 16px rgba(0, 0, 0, .5);
  overflow: hidden;
}
/* reflet laqué en diagonale */
.piano-top::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg,
    transparent 28%, rgba(255, 255, 255, .05) 42%,
    rgba(255, 255, 255, .13) 50%,
    rgba(255, 255, 255, .05) 58%, transparent 72%);
  pointer-events: none;
}
/* liseré doré */
.piano-top::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 6px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(217, 164, 65, .8), transparent);
}
.brand-name {
  font-family: "Kunstler Script", "Edwardian Script ITC", "Palace Script MT",
    "Monotype Corsiva", "French Script MT", "Segoe Script", cursive;
  font-style: italic;
  font-weight: 700;
  font-size: clamp(40px, 5vw, 68px);
  letter-spacing: .05em;
  line-height: 1;
  padding-bottom: .12em;
  background: linear-gradient(180deg, #f3d68f 0%, #dfab48 55%, #a8762a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 1.1px rgba(222, 174, 74, .65);
  filter:
    drop-shadow(0 1px 1px rgba(0, 0, 0, .85))
    drop-shadow(0 0 14px rgba(217, 164, 65, .3));
}

/* ===== Écran de chargement ===== */
.loader {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(11, 13, 18, .92);
  backdrop-filter: blur(4px);
  z-index: 100;
  transition: opacity .35s;
}
.loader.hidden { opacity: 0; pointer-events: none; }

.loader-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 34px 44px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  color: var(--accent);
}
.loader-card p { margin: 0; color: var(--text); font-size: 15px; }

.progress {
  width: 240px; height: 6px;
  background: #2a2e3a;
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-deep), var(--accent));
  transition: width .2s;
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; }
}

/* Réglages visibles uniquement sur écrans tactiles (téléphone/tablette) */
@media (hover: hover) and (pointer: fine) {
  .mobile-only { display: none !important; }
  #btnOrient { display: none !important; } /* rotation inutile sur ordinateur */
}

/* Sur tactile : glisser verticalement sur le piano fait défiler la page
   (indispensable dans les navigateurs intégrés type Instagram où le piano
   couvre tout l'écran). Taper joue, glisser horizontalement = glissando. */
@media (pointer: coarse) {
  .piano { touch-action: pan-y; }
  body.keys-only .piano,
  body.css-landscape .piano { touch-action: none; } /* modes plein jeu : rien ne défile */
}

/* Bannière navigateur intégré (Instagram, Facebook…) */
.iab-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
  background: #2a2113;
  border-bottom: 1px solid var(--accent-deep);
}
.iab-banner svg { width: 18px; height: 18px; color: var(--accent); flex-shrink: 0; }
.iab-banner p { margin: 0; flex: 1; }
.iab-banner button {
  padding: 6px 10px;
  font: inherit;
  font-size: 12px;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

/* ===== Mode « touches seules » ===== */
body.keys-only .topbar,
body.keys-only .piano-top,
body.keys-only .sheet,
body.keys-only .hint { display: none !important; }
body.keys-only .stage { padding: 6px; justify-content: center; }
body.keys-only .piano-shell { width: 100%; padding: 6px 6px 8px; }
/* touches seules : le clavier prend la hauteur disponible × réglage hauteur */
body.keys-only .piano { height: calc((100dvh - 74px) * min(var(--key-h, 1), 1)); }
body.keys-only .piano-scroll { display: flex; align-items: flex-end; }
body.keys-only .piano { width: 100%; }
body.keys-only .pan-bar:not([hidden]) { margin-top: 6px; }
/* en rotation CSS, la hauteur disponible est la largeur physique de l'écran */
body.css-landscape.keys-only .piano { height: calc((100dvw - 74px) * min(var(--key-h, 1), 1)); }

/* Perfs Pleine touche : les touches étant énormes, on allège les effets
   flous (halos, ombre du meuble) très coûteux à redessiner sur mobile. */
body.keys-only .piano-shell {
  box-shadow: none;
  background: #0e0906;
}
body.keys-only .key.white.down {
  box-shadow: inset 0 -3px 5px -4px rgba(0, 0, 0, .5), 0 0 10px rgba(59, 130, 246, .8);
}
body.keys-only .key.black.down {
  box-shadow: 0 2px 3px rgba(0, 0, 0, .55), 0 0 10px rgba(59, 130, 246, .9);
}

/* ===== Ascenseur horizontal du clavier ===== */
.pan-bar {
  width: 100%;
  height: 24px;
  margin-top: 8px;
  accent-color: var(--accent);
  cursor: pointer;
  touch-action: none;
}
/* En Pleine touche seulement, on remplace l'ascenseur brut par le mini-piano.
   En horizontal/vertical normal, l'ascenseur classique reste. */
body.keys-only .pan-bar { display: none !important; }

/* Réglages inutiles en Pleine touche (panneau, effets, aide, signature) */
body.keys-only .pm-hide { display: none !important; }

/* L'indicateur de mode ne s'affiche pas en plein écran (Pleine touche) */
body.keys-only .mode-badge { display: none !important; }

/* Sur téléphone en plein jeu, on masque les lettres du clavier sur les touches
   (inutiles au doigt) pour un clavier épuré. */
@media (pointer: coarse) {
  body.keys-only .key .lbl,
  body.fs-active .key .lbl,
  body.css-landscape .key .lbl { display: none !important; }
}

/* Mini-piano : aperçu de tout le clavier ; la zone visible reste claire,
   le reste est assombri. Sert aussi d'ascenseur (tap/glisser). */
.minimap {
  display: none;
  position: relative;
  width: 100%;
  height: 26px;
  margin-top: 8px;
  border-radius: 6px;
  overflow: hidden;
  background: #05060a;
  touch-action: none;
  cursor: pointer;
}
.minimap canvas { display: block; width: 100%; height: 100%; }
/* fenêtre visible (partie non assombrie) */
.minimap .mm-window {
  position: absolute;
  top: 0;
  height: 100%;
  border: 1.5px solid var(--accent);
  border-radius: 4px;
  background: rgba(245, 158, 11, .1);
  box-shadow: 0 0 0 2000px rgba(4, 5, 9, .62); /* assombrit tout le reste */
  pointer-events: none;
}
.minimap.show { display: block; }

/* Petite croix pour masquer un overlay flottant (session — revient au rechargement) */
.ov-close {
  position: absolute;
  top: 2px;
  right: 4px;
  z-index: 5;
  width: 20px;
  height: 20px;
  padding: 0;
  font-size: 16px;
  line-height: 1;
  color: var(--text-dim);
  background: rgba(11, 13, 18, .6);
  border: none;
  border-radius: 50%;
  cursor: pointer;
}
.ov-close:hover { color: var(--accent); }
.minimap .ov-close { top: 3px; }
/* overlay masqué pour la session (revient au rechargement) */
.ov-dismissed { display: none !important; }

/* Mini-curseurs flottants largeur/hauteur — mode touches seules sur mobile */
.keys-size {
  display: none;
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 120;
  flex-direction: column;
  gap: 6px;
  padding: 8px 12px;
  background: rgba(26, 29, 38, .78);
  border: 1px solid var(--border);
  border-radius: 12px;
  backdrop-filter: blur(4px);
}
.keys-size label { display: flex; align-items: center; gap: 8px; }
.keys-size svg { width: 14px; height: 14px; color: var(--text-dim); flex-shrink: 0; }
.keys-size input[type="range"] { width: 130px; accent-color: var(--accent); }
.ks-step {
  flex-shrink: 0;
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 20px; line-height: 1; font-weight: 600;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 9px;
  cursor: pointer; touch-action: manipulation; user-select: none;
}
.ks-step:active { transform: scale(.94); border-color: var(--accent-deep); }
.ks-step:focus-visible { outline: none; box-shadow: var(--focus); }
/* Repli / dépli des jauges (plein écran mobile) */
.keys-size .ks-body { display: flex; flex-direction: column; gap: 6px; }
.keys-size.folded .ks-body { display: none; }
.ks-fold {
  align-self: flex-end;
  width: 34px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-dim); background: transparent;
  border: 1px solid transparent; border-radius: 8px;
  cursor: pointer; touch-action: manipulation;
}
.ks-fold:active { transform: scale(.94); }
.ks-fold:focus-visible { outline: none; box-shadow: var(--focus); }
.ks-fold svg { width: 18px; height: 18px; }
.ks-fold .i-expand { display: none; }
.keys-size.folded .ks-fold .i-fold { display: none; }
.keys-size.folded .ks-fold .i-expand { display: inline; }
/* Replié : l'overlay se réduit à une pastille tappable */
.keys-size.folded { padding: 0; background: transparent; border-color: transparent; backdrop-filter: none; }
.keys-size.folded .ks-fold {
  width: 44px; height: 44px; color: var(--accent);
  background: rgba(26, 29, 38, .9); border-color: var(--border);
  backdrop-filter: blur(4px);
}
@media (pointer: coarse) {
  body.keys-only .keys-size { display: flex; } /* uniquement en Pleine touche */
  /* Pouce et piste tactiles (le pouce natif est trop petit à saisir au doigt) */
  .keys-size input[type="range"] {
    -webkit-appearance: none; appearance: none;
    width: 130px; height: 34px; background: transparent;
  }
  .keys-size input[type="range"]::-webkit-slider-runnable-track {
    height: 8px; border-radius: 5px; background: var(--border);
  }
  .keys-size input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 28px; height: 28px; margin-top: -10px;
    border-radius: 50%; background: var(--accent); border: 2px solid #0b0d12;
  }
  .keys-size input[type="range"]::-moz-range-track {
    height: 8px; border-radius: 5px; background: var(--border);
  }
  .keys-size input[type="range"]::-moz-range-thumb {
    width: 28px; height: 28px; border: 2px solid #0b0d12;
    border-radius: 50%; background: var(--accent);
  }
}

/* Bouton flottant « Pleine touche » — mobile uniquement */
.keys-quick {
  display: none;
  position: fixed;
  bottom: 14px;
  right: 14px;
  z-index: 95;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: #0b0d12;
  background: linear-gradient(135deg, #fbbf24, #d97706);
  border: none;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .6), 0 0 14px rgba(245, 158, 11, .35);
  cursor: pointer;
}
.keys-quick svg { width: 17px; height: 17px; }
.keys-quick:active { transform: scale(.96); }
@media (pointer: coarse) {
  body:not(.keys-only) .keys-quick { display: inline-flex; }
}

/* Pastille flottante « Réglages » : déplaçable, apparaît en plein écran /
   Pleine touche / paysage. Position non mémorisée (revient au rechargement). */
.fab {
  display: none;
  position: fixed;
  z-index: 130;
  width: 46px;
  height: 46px;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  background: rgba(26, 29, 38, .85);
  border: 1px solid var(--border);
  border-radius: 50%;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .55);
  backdrop-filter: blur(4px);
  cursor: grab;
  touch-action: none;
}
.fab svg { width: 22px; height: 22px; }
.fab.show { display: inline-flex; }
.fab.dragging { cursor: grabbing; opacity: .85; }
.fab:active { transform: scale(.94); }

.keys-exit {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 120;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  color: var(--text-dim);
  background: rgba(26, 29, 38, .75);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  backdrop-filter: blur(4px);
}
.keys-exit:hover { color: var(--accent); border-color: var(--accent-deep); }
.keys-exit:focus-visible { outline: none; box-shadow: var(--focus); }
.keys-exit svg { width: 17px; height: 17px; }

/* Sur téléphone (peu importe l'orientation, rotation CSS comprise),
   le popover réglages devient une fenêtre centrée — toujours visible. */
@media (max-width: 900px), (max-height: 520px) {
  .settings-pop {
    position: fixed;
    left: 50%;
    top: 50%;
    right: auto;
    transform: translate(-50%, -50%);
    width: min(340px, 92%);
    max-height: 88%;
    overflow-y: auto;
    z-index: 200;
    gap: 7px;
    padding: 12px 16px 14px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, .85), 0 0 0 100vmax rgba(0, 0, 0, .45);
  }
  .settings-pop label { min-height: 24px; }
}

/* ===== Paysage forcé par rotation CSS (iPhone & verrouillage refusé) ===== */
body.css-landscape {
  position: fixed;
  top: 0;
  left: 100vw;
  width: 100dvh;
  height: 100dvw;
  min-height: 0; /* sans ça, le min-height:100dvh du body fausse la rotation */
  transform: rotate(90deg);
  transform-origin: left top;
  overflow: hidden; /* pas de défilement : en roté, les gestes ne suivent plus les axes */
}
body.css-landscape .fx { display: none; } /* le canvas ne suit pas la rotation */

/* En roté, tout doit tenir à l'écran sans défiler : on allège le décor,
   le piano remplit l'espace restant (flex) et le panneau partition se
   place À CÔTÉ du piano (l'écran roté est large). */
body.css-landscape .hint,
body.css-landscape .piano-top,
body.css-landscape .note-display,
body.css-landscape .brand h1 { display: none !important; }
body.css-landscape .topbar { padding: 5px 10px; gap: 8px; }
body.css-landscape .stage { padding: 8px; gap: 8px; min-height: 0; }
body.css-landscape .arena { flex: 1; min-height: 0; }
/* en roté : le panneau partition va TOUJOURS en bas (plus lisible) */
body.css-landscape .arena { flex-direction: column !important; }
body.css-landscape .piano-shell {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 8px;
}
body.css-landscape .piano-scroll { flex: 1; min-height: 0; }
body.css-landscape .piano { height: 100%; }
body.css-landscape .piano-shell { min-height: 210px; } /* les touches ne s'aplatissent jamais trop */
body.css-landscape .arena { align-items: stretch; }
/* panneau en bas : peut rétrécir, son contenu défile à l'intérieur */
body.css-landscape .arena .sheet:not([hidden]) {
  width: auto !important;
  min-width: 0;
  max-width: none;
  flex: 0 1 auto;
  max-height: 60%;          /* plus de place (recherche MIDI, résultats…) */
  min-height: 84px;
  resize: none;
  overflow-y: auto;
}
/* en paysage, la liste de résultats MIDI défile dans le panneau (pas de double
   défilement imbriqué qui l'écrasait) */
body.css-landscape .midi-results { max-height: none; overflow: visible; }
body.css-landscape .arena .sheet textarea { min-height: 60px; }

/* ===== Incitation à la rotation (téléphone en portrait) ===== */
.rotate-hint {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 110;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 18px 16px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--accent-deep);
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .7);
}
.rotate-hint svg { width: 40px; height: 40px; color: var(--accent); }
.rotate-hint p { margin: 0; font-size: 14px; line-height: 1.5; color: var(--text); }
.rh-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
#rotateFs { border-color: var(--accent-deep); }

@media (max-width: 700px) {
  .topbar { padding: 10px 14px; gap: 10px; }
  .note-display { order: 3; margin-left: auto; }
  .stage { padding: 14px 8px 20px; }
  .piano-shell { padding: 10px 10px 14px; }
  .hint { font-size: 12px; padding: 0 10px; }
}
