:root {
  --bg: #14161c;
  --panel: #1c1f27;
  --panel-2: #242833;
  --line: #2e3340;
  --text: #e6e8ee;
  --muted: #9aa1b2;
  --accent: #facc15;
  --right: #34d399;
  --left: #60a5fa;
  --accomp: #a78bfa;
  --wrong: #f87171;
  --paper: #f6f2e7;
  --ink: #1b1b1b;
  --radius: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* l'attribut hidden l'emporte sur les display des classes */
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Ubuntu, Cantarell, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
}
button, select, input { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- barres */
.topbar, .controls {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.controls { gap: 18px; background: #191c23; }
.brand { font-weight: 700; letter-spacing: .02em; display: flex; align-items: center; gap: 6px; }
.logo {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 6px;
  background: linear-gradient(135deg, var(--right), var(--left)); color: #0b0c10; font-size: 15px;
}
.song-title { flex: 1; min-width: 120px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.song-title.loaded { color: var(--text); }
.group { display: flex; align-items: center; gap: 6px; }
.glabel { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.transport { flex: 1 1 320px; }
.timeline { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 160px; }
.timeline input { flex: 1; }
.time { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; font-size: 13px; }
.speed { min-width: 48px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 12px; cursor: pointer; transition: background .12s, border-color .12s;
}
.btn:hover { background: #2c3140; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: #fde047; }
.btn.icon { padding: 6px; width: 34px; height: 34px; justify-content: center; }
.btn.small { padding: 3px 10px; min-width: 30px; height: 28px; justify-content: center; }
.btn.icon.small { width: 28px; }
.btn.active { border-color: var(--accent); color: var(--accent); }
.btn.big { padding: 12px 22px; font-size: 16px; }
.ico { width: 18px; height: 18px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg button { background: var(--panel-2); border: 0; padding: 5px 11px; cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button:hover { background: #2c3140; }
.seg button.on { background: var(--accent); color: #111; font-weight: 600; }
.seg button.hand-l.on { background: var(--left); }
.seg button.hand-r.on { background: var(--right); }

input[type=range] { accent-color: var(--accent); }

.midi-status { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; max-width: 260px; }
.midi-status .label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.midi-status .dot { width: 9px; height: 9px; border-radius: 50%; background: #52525b; flex: none; }
.midi-status.ok .dot { background: var(--right); box-shadow: 0 0 8px var(--right); }
.midi-status.flash .dot { background: var(--accent); box-shadow: 0 0 10px var(--accent); }

.dropdown { position: relative; }
.menu {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 30; min-width: 320px; max-width: 520px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px;
  box-shadow: 0 12px 32px rgba(0,0,0,.45);
}
.menu button, .recent-list button {
  display: block; width: 100%; text-align: left; background: transparent; border: 0; border-radius: 6px;
  padding: 7px 10px; cursor: pointer;
}
.menu button:hover, .recent-list button:hover { background: var(--panel-2); }
.menu .sub, .recent-list .sub { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu .empty { color: var(--muted); padding: 8px 10px; }

/* ---------------------------------------------------------------- scène */
.stage { flex: 1; position: relative; display: flex; flex-direction: column; min-height: 0; }
.sheet {
  position: relative; flex: none; overflow: hidden; background: var(--paper); color: var(--ink);
  border-bottom: 3px solid #0b0c10; cursor: pointer; height: 0;
  isolation: isolate;   /* ordre d'empilement propre à la bande */
}
.sheet-track { position: absolute; top: 0; left: 0; z-index: 1; will-change: transform; }
.sheet-track svg { display: block; }
.sheet-playhead {
  position: absolute; top: 0; bottom: 0; left: 28%; width: 3px; margin-left: -1.5px; z-index: 0;
  background: rgba(250, 204, 21, .9); box-shadow: 0 0 8px rgba(250, 204, 21, .8); pointer-events: none;
}   /* derrière la musique : notes et noms restent lisibles par-dessus */
/* clé, armure et mesure collées à gauche (lib/prologue.js) */
.sheet-prologue {
  position: absolute; top: 0; bottom: 0; left: 0; overflow: hidden; z-index: 2;
  background: var(--paper); pointer-events: none; will-change: transform;
}
.sheet-prologue.stuck { box-shadow: 5px 0 6px -4px rgba(0,0,0,.3); }
.sheet-prologue svg { display: block; }
.sheet-prologue path { stroke: currentColor; }
.sheet-zoom {
  position: absolute; top: 6px; right: 8px; z-index: 3; display: flex; gap: 4px;
  opacity: .45; transition: opacity .15s;
}
.sheet:hover .sheet-zoom { opacity: 1; }
.sheet-zoom button {
  width: 28px; height: 28px; padding: 0; border-radius: 6px; cursor: pointer;
  background: rgba(255,255,255,.85); color: var(--ink); border: 1px solid rgba(0,0,0,.25);
  font-size: 18px; line-height: 1;
}
.sheet-zoom button:hover { background: #fff; border-color: rgba(0,0,0,.5); }
/* noms des notes (couplets ajoutés, lib/musicxml.js) : se distinguent des notes ;
   avant les règles .hl-* pour prendre la couleur de la main quand la note sonne */
.sheet svg g.verse.note-name { fill: #6b5d4f; font-weight: 600; }
.sheet svg g.note.hl, .sheet svg g.note.hl * { transition: none; }
.sheet svg g.note.hl-R, .sheet svg g.note.hl-R * { fill: #059669; color: #059669; }
.sheet svg g.note.hl-L, .sheet svg g.note.hl-L * { fill: #2563eb; color: #2563eb; }
.sheet svg g.note.hl-A, .sheet svg g.note.hl-A * { fill: #7c3aed; color: #7c3aed; }
.board { flex: 1; min-height: 120px; position: relative; }
.board canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.welcome {
  position: absolute; inset: 0; display: grid; place-items: center; z-index: 10;
  background: radial-gradient(ellipse at top, rgba(52,211,153,.10), transparent 60%), rgba(15,17,23,.92);
}
.welcome[hidden] { display: none; }
.welcome-card { text-align: center; max-width: 620px; padding: 32px; }
.welcome h1 { font-size: 40px; margin: 0 0 8px; background: linear-gradient(90deg, var(--right), var(--left)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lead { color: var(--muted); font-size: 16px; margin: 0 0 24px; }
.hint { color: var(--muted); margin: 14px 0; }
.hint.small { font-size: 13px; }
.recent-list { margin: 18px auto 0; max-width: 520px; text-align: left; }
.recent-list h4 { margin: 0 0 6px; color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.stage.dragover .welcome, .stage.dragover::after {
  outline: 3px dashed var(--accent); outline-offset: -12px;
}

.loading {
  position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center; background: rgba(15,17,23,.82); font-size: 15px;
}
.loading[hidden] { display: none; }
.spinner { width: 38px; height: 38px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.banner {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 190px; z-index: 5;
  background: rgba(250,204,21,.14); color: var(--accent); border: 1px solid rgba(250,204,21,.4);
  padding: 4px 12px; border-radius: 999px; font-size: 13px; pointer-events: none;
}
.banner[hidden] { display: none; }

/* ---------------------------------------------------------------- réglages */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100vw); z-index: 40;
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: -16px 0 40px rgba(0,0,0,.4);
  display: flex; flex-direction: column; user-select: text;
}
.drawer[hidden] { display: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-size: 18px; }
.drawer-body { overflow: auto; padding: 4px 16px 24px; }
.drawer section { padding: 12px 0; border-bottom: 1px solid var(--line); }
.drawer h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0; }
.row select, .row input[type=range] { width: 58%; }
select { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; }
.check { display: flex; align-items: center; gap: 8px; margin: 8px 0; cursor: pointer; }
.note { color: var(--muted); font-size: 12.5px; margin: 6px 0; }
.tracks .track { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 0; }
.tracks .track span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tracks .track .swatch { flex: none; width: 10px; height: 10px; border-radius: 3px; }
.tracks select { width: 48%; }
.row input[type=text], .row input[type=password] { width: 58%; }
input[type=text], input[type=password], input[type=search] {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; outline: none;
}
input[type=text]:focus, input[type=password]:focus, input[type=search]:focus { border-color: var(--accent); }

/* ---------------------------------------------------------------- bibliothèque */
.welcome-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.library-card {
  width: min(1180px, calc(100vw - 48px)); height: calc(100vh - 64px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  display: flex; flex-direction: column; overflow: hidden;
}
.library-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.library-head h2 { margin: 0 8px 0 0; font-size: 18px; }
.library-head input[type=search] { flex: 1; min-width: 200px; font-size: 15px; }
.library-status { padding: 8px 16px; color: var(--muted); font-size: 13px; min-height: 34px; }
.library-status.error { color: #fecaca; }
.library-results {
  flex: 1; overflow: auto; padding: 4px 16px 16px; align-content: start;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px;
}
.lib-card {
  display: flex; flex-direction: column; gap: 2px; min-width: 0; text-align: left; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px;
}
.lib-card:hover { border-color: var(--accent); }
/* haut de la 1re page : titre et premiers systèmes, de quoi juger la difficulté */
.lib-card .thumb { aspect-ratio: 210 / 170; background: var(--paper); border-radius: 6px; overflow: hidden; margin-bottom: 6px; }
.lib-card .thumb img { width: 100%; display: block; }
.lib-card .t { font-weight: 600; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.lib-card .c, .lib-card .m { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-card .c { font-size: 12.5px; }
.lib-card .m { font-size: 12px; }
.library-foot { display: flex; justify-content: center; padding: 10px; border-top: 1px solid var(--line); }
.library-foot:has(#lib-more[hidden]) { display: none; }

/* ---------------------------------------------------------------- résultats */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(0,0,0,.55); }
.modal[hidden] { display: none; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px 32px; min-width: 380px; text-align: center; }
.modal-card h2 { margin: 0 0 6px; }
.score { font-size: 56px; font-weight: 800; color: var(--accent); }
.res-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 12px 0 20px; }
.res-grid b { display: block; font-size: 22px; }
.res-grid span { color: var(--muted); font-size: 12px; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; max-width: 80vw;
  background: #2b303c; border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px;
  box-shadow: 0 10px 28px rgba(0,0,0,.45);
}
.toast.error { border-color: var(--wrong); color: #fecaca; }
.toast[hidden] { display: none; }

/* piano.mypalace.ca */
.topbar a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.welcome-actions a.btn { text-decoration: none; }
