:root {
  --bg: #f6f3ee; --surface: #ffffff; --surface-2: #ece7df; --ink: #1d1b18; --muted: #6b655c; --line: #ddd6cb;
  --accent: #d2502d; --accent-ink: #fff; --attendu: #2f7fb8; --juste: #2f8f5b; --faux: #c0392b;
  --clavier-h: 168px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #141311; --surface: #1e1c19; --surface-2: #2a2723; --ink: #f2eee8; --muted: #a39b8f; --line: #3a3631;
    --accent: #ff7a50; --accent-ink: #1a0f0a; --attendu: #4ea3e0; --juste: #5cc48a; --faux: #ff6b5a; color-scheme: dark; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
button, select, input[type=number] { font: inherit; color: var(--ink); background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 7px 12px; min-height: 38px; cursor: pointer; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
button.principal { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 700; min-width: 130px; }
button.discret { background: transparent; color: var(--muted); }
button:disabled { opacity: .45; cursor: default; }

.barre { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface); flex-wrap: wrap; }
.barre h1 { font-size: 19px; margin: 0 8px 0 0; }
.barre select { min-width: 220px; max-width: 46vw; }
.retour { text-decoration: none; font-size: 22px; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; background: var(--surface-2); color: inherit; }
.puce { margin-left: auto; font-size: 13px; padding: 5px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.puce.ok { background: color-mix(in srgb, var(--juste) 18%, transparent); color: var(--juste); font-weight: 600; }
.puce.ko { background: color-mix(in srgb, var(--faux) 15%, transparent); color: var(--faux); }

.commandes { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.groupe { display: inline-flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.groupe button { border: 0; border-radius: 0; background: var(--surface); }
.groupe button + button { border-left: 1px solid var(--line); }
.groupe button[aria-pressed=true] { background: var(--ink); color: var(--bg); font-weight: 600; }
.tempo { display: inline-flex; align-items: center; gap: 8px; }
.tempo input { width: 140px; accent-color: var(--accent); }
.tempo output { min-width: 9ch; font-variant-numeric: tabular-nums; color: var(--muted); }
.case { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.case input { width: 18px; height: 18px; accent-color: var(--accent); }
.boucle-plage input[type=number] { width: 4.2em; padding: 5px 6px; min-height: 32px; }
.boucle-plage { color: var(--muted); }
#jouer { margin-left: auto; }

.etat { display: flex; gap: 18px; padding: 6px 16px; font-size: 14px; color: var(--muted); min-height: 30px; align-items: center; }
#position { font-weight: 600; color: var(--ink); }
#message { margin-left: auto; font-weight: 600; color: var(--accent); }

/* La partition reste sur fond clair pour la lisibilité, même en thème sombre. */
#zone-partition { flex: 1; overflow: auto; background: #fffdf9; color: #111; margin: 0 16px; border-radius: 14px 14px 0 0; border: 1px solid var(--line); border-bottom: 0; }
#partition-svg { padding: 8px 12px 24px; min-height: 100%; }
#partition-svg .vide { color: #6b655c; padding: 40px; text-align: center; }

/* Clavier à l'écran : meuble sombre, bande de feutre, touches en relief */
#clavier { position: relative; height: var(--clavier-h); flex: none; user-select: none; padding: 14px 14px 12px;
  background: linear-gradient(180deg, #23201d 0%, #121110 55%, #0a0909 100%);
  box-shadow: inset 0 10px 18px rgba(0,0,0,.65), 0 -1px 0 rgba(255,255,255,.04); }
#clavier::before { content: ''; position: absolute; left: 14px; right: 14px; top: 8px; height: 6px; border-radius: 3px; z-index: 3;
  background: linear-gradient(180deg, #8f2a22, #5c1712); box-shadow: 0 2px 4px rgba(0,0,0,.6); }
.clavier-int { position: relative; display: flex; height: 100%; }
.touche { position: relative; flex: 1; margin-right: 2px; border-radius: 0 0 8px 8px;
  background: linear-gradient(180deg, #e7e2d8 0%, #fdfcf9 9%, #ffffff 55%, #f3f0ea 88%, #e2ddd2 100%);
  box-shadow: inset 0 -7px 0 #d6cfc1, inset 0 1px 0 #fff, 0 4px 5px rgba(0,0,0,.55);
  transition: transform .07s ease, box-shadow .07s ease, background .18s ease; }
.touche:last-child { margin-right: 0; }
.touche.noire { position: absolute; top: 0; width: calc(var(--w) * .6); height: 61%; margin: 0; z-index: 2; border-radius: 0 0 6px 6px;
  background: linear-gradient(180deg, #3b3a3e 0%, #1b1b1e 45%, #0b0b0c 92%, #000 100%);
  box-shadow: inset 0 -5px 0 #000, inset 1px 0 0 rgba(255,255,255,.10), inset -1px 0 0 rgba(255,255,255,.05), 0 5px 7px rgba(0,0,0,.65); }
.touche .nom { position: absolute; bottom: 12px; left: 0; right: 0; text-align: center; font-size: 10.5px; font-weight: 600; color: #a39b8f; letter-spacing: .02em; }

/* Touche à jouer : halo bleu */
.touche.attendu { background: linear-gradient(180deg, #d6e9f8 0%, #9fcdf0 45%, #5aa6dd 100%);
  box-shadow: inset 0 -7px 0 #3d8ccb, 0 0 18px rgba(78,163,224,.75), 0 4px 5px rgba(0,0,0,.5); }
.touche.noire.attendu { background: linear-gradient(180deg, #6fb6ea 0%, #3a8fd0 55%, #1f6aa6 100%);
  box-shadow: inset 0 -5px 0 #154f7d, 0 0 16px rgba(78,163,224,.85); }
/* Touche enfoncée : elle descend, verte si juste, rouge si fausse */
.touche.appuye { transform: translateY(2px); background: linear-gradient(180deg, #d4f0de 0%, #8fd7a8 50%, #45b26f 100%) !important;
  box-shadow: inset 0 -3px 0 #2f8f5b, 0 0 14px rgba(92,196,138,.6), 0 2px 3px rgba(0,0,0,.5) !important; }
.touche.noire.appuye { background: linear-gradient(180deg, #6fd39a 0%, #2f9f60 70%, #1f7a46 100%) !important; }
.touche.faux { transform: translateY(2px); background: linear-gradient(180deg, #fbd9d5 0%, #f08b80 50%, #d9473a 100%) !important;
  box-shadow: inset 0 -3px 0 #a8342a, 0 0 14px rgba(255,107,90,.65) !important; }
.touche.noire.faux { background: linear-gradient(180deg, #f07c70 0%, #c0392b 80%) !important; }

.reglages { display: inline-flex; gap: 12px; align-items: center; color: var(--muted); }
.reglages select { padding: 5px 8px; min-height: 32px; }
/* Numéro de doigt : pastille sur la touche à jouer */
.touche .doigt { position: absolute; left: 50%; transform: translateX(-50%); bottom: 36px; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center; background: #fff; color: #1f6aa6; font-weight: 800; font-size: 13px; box-shadow: 0 1px 3px rgba(0,0,0,.35); }
.touche.noire .doigt { bottom: 10px; width: 20px; height: 20px; font-size: 11.5px; }

/* Ligne continue : la partition défile horizontalement */
body.ligne #zone-partition { overflow-x: auto; overflow-y: hidden; display: flex; align-items: center; }
body.ligne #partition-svg { min-width: max-content; min-height: auto; padding: 8px 40vw 8px 24px; }

/* Jouer sans regarder */
body.cache-partition #partition-svg svg { filter: blur(9px); transition: filter .25s; }
body.cache-partition.indice #partition-svg svg { filter: none; }
body.cache-clavier .touche.attendu:not(.indice-on) { background: linear-gradient(180deg, #e7e2d8 0%, #fdfcf9 9%, #ffffff 55%, #f3f0ea 88%, #e2ddd2 100%);
  box-shadow: inset 0 -7px 0 #d6cfc1, inset 0 1px 0 #fff, 0 4px 5px rgba(0,0,0,.55); }
body.cache-clavier .touche.noire.attendu:not(.indice-on) { background: linear-gradient(180deg, #3b3a3e 0%, #1b1b1e 45%, #0b0b0c 92%, #000 100%);
  box-shadow: inset 0 -5px 0 #000, 0 5px 7px rgba(0,0,0,.65); }
body.cache-clavier .touche .doigt { display: none; }

/* Progression */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(760px, 94vw); max-height: 88dvh; background: var(--bg); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.5); }
.dlg-tete { display: flex; align-items: center; padding: 16px 18px 6px; position: sticky; top: 0; background: var(--bg); }
.dlg-tete h2 { margin: 0; font-size: 19px; flex: 1; }
#prog-contenu { padding: 0 18px 18px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 8px 0 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.kpi b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 12.5px; color: var(--muted); }
.graph { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px; margin-bottom: 14px; }
.graph svg { width: 100%; height: auto; display: block; }
.histo { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.histo th, .histo td { text-align: left; padding: 6px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.histo th { color: var(--muted); font-weight: 600; font-size: 12.5px; }
.prog-vide { color: var(--muted); padding: 20px 0; }

@media (max-width: 900px) { .tempo input { width: 100px; } #jouer { margin-left: 0; } :root { --clavier-h: 128px; } }
.credits { position: absolute; right: 18px; bottom: calc(var(--clavier-h) + 4px); font-size: 11px; color: #8a847a; pointer-events: auto; }
.credits a { color: inherit; }
