/* Apprenti Solfège — thème pastel, rond et joyeux. */

:root {
  --ink: #3b3355;
  --ink-soft: #736a93;
  --line: #ebe5f5;
  --card: #ffffff;
  --paper: #fffafc;
  --pink: #ff8fb1;
  --sky: #5cbdf0;
  --sun: #ffbe3d;
  --lav: #9d87ff;
  --mint: #3fcf9c;
  --peach: #ff9a62;
  --good: #2fc58a;
  --bad: #ff6b81;
  --radius: 24px;
  --shadow: 0 4px 0 rgba(84, 62, 150, 0.08), 0 14px 30px rgba(84, 62, 150, 0.1);
  --font: "M PLUS Rounded 1c", "Nunito", "Hiragino Maru Gothic ProN", "Arial Rounded MT Bold", "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--font);
  color: var(--ink);
  background: #fdf6fb;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  font-size: 17px;
  line-height: 1.4;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
:focus-visible { outline: 3px solid var(--lav); outline-offset: 3px; }
h1, h2, h3 { margin: 0; line-height: 1.15; }
[hidden] { display: none !important; }

/* ---------- Fond animé ---------- */
#bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background:
    radial-gradient(60vmax 50vmax at 0% 0%, #ffe3ef 0%, transparent 60%),
    radial-gradient(60vmax 50vmax at 100% 10%, #e3efff 0%, transparent 60%),
    radial-gradient(70vmax 60vmax at 50% 110%, #e2fbef 0%, transparent 60%),
    #fdf6fb;
}
#bg .float {
  position: absolute;
  top: -10vh;
  opacity: 0.35;
  animation: drift var(--d, 30s) linear var(--delay, 0s) infinite;
  will-change: transform;
}
@keyframes drift {
  from { transform: translate(0, 0) rotate(0deg); }
  to { transform: translate(var(--dx, 10vw), 125vh) rotate(var(--rot, 360deg)); }
}

/* ---------- Structure ---------- */
#app {
  min-height: 100dvh;
  max-width: 1180px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 2px solid var(--line);
}

.section-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--ink-soft);
  margin: 6px 4px 0;
}

/* ---------- Boutons ---------- */
.btn {
  --c: var(--lav);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 10px 22px;
  border: 0;
  border-radius: 18px;
  background: var(--c);
  color: #fff;
  font-weight: 800;
  font-size: 1.05rem;
  box-shadow: 0 5px 0 color-mix(in srgb, var(--c) 70%, #2a1f4d);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
  user-select: none;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.05); }
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 color-mix(in srgb, var(--c) 70%, #2a1f4d); }
.btn.good { --c: var(--good); }
.btn.pink { --c: var(--pink); }
.btn.sky { --c: var(--sky); }
.btn.danger { --c: #f25c74; }
.btn.ghost {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 4px 0 #e2dcef;
  border: 2px solid var(--line);
}
.btn.ghost:active:not(:disabled) { box-shadow: 0 1px 0 #e2dcef; }
.btn.big { min-height: 64px; font-size: 1.25rem; padding: 12px 30px; border-radius: 22px; }
.btn.small { min-height: 42px; padding: 6px 14px; font-size: 0.95rem; border-radius: 14px; }

.icon-btn {
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  border-radius: 18px;
  border: 2px solid var(--line);
  background: #fff;
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  box-shadow: 0 4px 0 #e2dcef;
  transition: transform 0.08s, box-shadow 0.08s;
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #e2dcef; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  background: #fff;
  border: 2px solid var(--line);
  font-weight: 800;
  white-space: nowrap;
}

/* ---------- Écran d'accueil / profils ---------- */
.hero { text-align: center; padding: 18px 0 6px; }
.logo {
  font-size: clamp(2.1rem, 6vw, 3.4rem);
  font-weight: 800;
  letter-spacing: -0.01em;
  background: linear-gradient(90deg, #ff7aa8, #ffae4d 35%, #4fcf9a 65%, #6f8cff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 rgba(84, 62, 150, 0.12));
}
.logo .note { -webkit-text-fill-color: initial; color: var(--pink); display: inline-block; animation: bob 2.4s ease-in-out infinite; }
.subtitle { color: var(--ink-soft); font-weight: 700; margin: 6px 0 0; font-size: 1.1rem; }
.subtitle .ja { color: var(--pink); }

.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 18px;
  padding: 8px 0;
}
.profile-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 12px 16px;
  border-radius: var(--radius);
  border: 2px solid var(--line);
  background: #fff;
  box-shadow: var(--shadow);
  transition: transform 0.15s;
}
.profile-card:hover { transform: translateY(-4px) rotate(-1deg); }
.profile-card:active { transform: scale(0.97); }
.profile-name { font-weight: 800; font-size: 1.3rem; }
.profile-medals { display: flex; gap: 2px; min-height: 30px; align-items: center; }
.profile-card.add { border: 3px dashed #d9cff0; background: rgba(255, 255, 255, 0.6); box-shadow: none; justify-content: center; }
.profile-card.add .plus {
  width: 110px; height: 110px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 3.4rem; font-weight: 800; color: var(--lav);
  background: #f3efff;
}
.avatar-photo { border-radius: 50%; object-fit: cover; border: 4px solid #fff; box-shadow: 0 4px 14px rgba(84, 62, 150, 0.2); display: block; }

/* ---------- Barre du haut ---------- */
.topbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar .spacer { flex: 1; }
.player-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 16px 4px 4px;
  border-radius: 999px;
  background: #fff;
  border: 2px solid var(--line);
  box-shadow: 0 4px 0 #e2dcef;
  font-weight: 800;
  font-size: 1.1rem;
}
.player-chip svg, .player-chip img { width: 46px; height: 46px; }
.chip.notes { color: #b5651d; background: #fff6e0; border-color: #ffe4a8; }
.chip.streak { color: #e8590c; background: #fff0e6; border-color: #ffd8bf; }

/* ---------- Accueil ---------- */
.home-hero {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 8px 4px;
}
.home-hero .companion { width: clamp(120px, 20vw, 170px); flex: 0 0 auto; cursor: pointer; }
.home-hero .companion svg { width: 100%; height: auto; }
.bubble {
  position: relative;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 22px;
  padding: 14px 18px;
  font-weight: 700;
  font-size: 1.1rem;
  box-shadow: var(--shadow);
  max-width: 560px;
}
.bubble::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 50%;
  width: 20px; height: 20px;
  background: #fff;
  border-left: 2px solid var(--line);
  border-bottom: 2px solid var(--line);
  transform: translateY(-50%) rotate(45deg);
  border-radius: 0 0 0 5px;
}
.bubble.pop, .pop-in { animation: pop 0.35s cubic-bezier(.3, 1.6, .5, 1); }
.bubble .ja { color: var(--pink); }

.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 18px;
}
.cat-card {
  --c: var(--lav);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
  text-align: left;
  border-radius: var(--radius);
  border: 2px solid color-mix(in srgb, var(--c) 30%, white);
  background:
    radial-gradient(120px 120px at 100% 0%, color-mix(in srgb, var(--c) 22%, white) 0%, transparent 70%),
    #fff;
  box-shadow: 0 5px 0 color-mix(in srgb, var(--c) 35%, white), 0 14px 30px rgba(84, 62, 150, 0.1);
  transition: transform 0.15s;
  min-height: 190px;
}
.cat-card:hover { transform: translateY(-4px); }
.cat-card:active { transform: translateY(2px) scale(0.99); }
.cat-icon {
  width: 60px; height: 60px; border-radius: 20px;
  display: grid; place-items: center;
  background: var(--c);
  color: #fff;
  box-shadow: 0 4px 0 color-mix(in srgb, var(--c) 70%, #2a1f4d);
}
.cat-icon svg { width: 38px; height: 38px; }
.cat-title { font-size: 1.35rem; font-weight: 800; }
.cat-sub { color: var(--ink-soft); font-weight: 700; font-size: 0.98rem; }
.cat-card .medal-slot { position: absolute; top: 12px; right: 14px; text-align: center; font-size: 0.75rem; font-weight: 800; color: var(--ink-soft); }
.cat-card .medal-slot svg { display: block; margin: 0 auto; }
.cat-card .badge {
  position: absolute; top: -10px; left: 18px;
  background: var(--sun); color: #fff; font-weight: 800; font-size: 0.85rem;
  padding: 3px 12px; border-radius: 999px; box-shadow: 0 3px 0 #e49d12;
  animation: bob 2s ease-in-out infinite;
}
.cat-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }
.cat-level { font-size: 0.9rem; font-weight: 800; color: color-mix(in srgb, var(--c) 70%, var(--ink)); }

.progress { height: 14px; border-radius: 999px; background: #f1edf8; overflow: hidden; border: 2px solid #ebe5f5; }
.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--c, var(--lav)) 70%, white), var(--c, var(--lav)));
  transition: width 0.6s cubic-bezier(.3, 1.3, .5, 1);
}

/* ---------- Médailles ---------- */
.medal { filter: drop-shadow(0 3px 3px rgba(84, 62, 150, 0.2)); overflow: visible; }
.medal.tier-5 { animation: shimmer 2.6s ease-in-out infinite; }
@keyframes shimmer { 50% { filter: drop-shadow(0 0 8px rgba(255, 210, 90, 0.9)) drop-shadow(0 3px 3px rgba(84, 62, 150, 0.2)); } }

/* ---------- Formulaires ---------- */
.form { display: flex; flex-direction: column; gap: 18px; }
.form-section { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.form-section h3 { font-size: 1.2rem; }
.text-input {
  width: 100%;
  font-size: 1.4rem;
  font-weight: 800;
  padding: 14px 18px;
  border-radius: 18px;
  border: 3px solid var(--line);
  background: var(--paper);
  outline: none;
}
.text-input:focus { border-color: var(--lav); background: #fff; }

.creature-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.creature-choice {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px 10px;
  border-radius: 20px;
  border: 3px solid transparent;
  background: var(--paper);
  font-weight: 800;
  transition: transform 0.12s, border-color 0.12s;
}
.creature-choice svg { width: 84px; height: 84px; }
.creature-choice:hover { transform: translateY(-3px); }
.creature-choice.selected { border-color: var(--lav); background: #f3efff; }
.creature-choice.selected svg { animation: bob 1.2s ease-in-out infinite; }
.creature-choice.locked { opacity: 0.55; }
.creature-choice .need { font-size: 0.78rem; color: var(--ink-soft); }

.edit-preview { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.edit-preview .big-avatar svg, .edit-preview .big-avatar img { width: 130px; height: 130px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.segmented { display: flex; flex-wrap: wrap; gap: 8px; }
.segmented button {
  padding: 10px 16px; min-height: 48px;
  border-radius: 14px; border: 2px solid var(--line); background: #fff;
  font-weight: 800;
}
.segmented button.on { background: var(--lav); color: #fff; border-color: var(--lav); }

.switch { display: flex; align-items: center; gap: 12px; font-weight: 700; cursor: pointer; }
.switch input { width: 26px; height: 26px; accent-color: var(--lav); }
input[type="range"] { accent-color: var(--lav); width: min(320px, 100%); height: 28px; }
.muted { color: var(--ink-soft); font-size: 0.95rem; }

/* ---------- Écran d'exercice ---------- */
.ex { --c: var(--lav); display: flex; flex-direction: column; gap: 14px; flex: 1; }
.ex-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ex-title { flex: 1; min-width: 150px; }
.ex-title h2 { font-size: 1.35rem; }
.ex-level { color: color-mix(in srgb, var(--c) 70%, var(--ink)); font-weight: 800; font-size: 0.95rem; }
.dots { display: flex; gap: 6px; }
.dots span {
  width: 14px; height: 14px; border-radius: 50%;
  background: #ece6f6; border: 2px solid #e0d8f0;
  transition: background 0.2s, transform 0.2s;
}
.dots span.current { border-color: var(--c); transform: scale(1.25); background: #fff; }
.dots span.good { background: var(--good); border-color: var(--good); }
.dots span.bad { background: var(--bad); border-color: var(--bad); }
.ex-medal { display: flex; align-items: center; }

.ex-main {
  display: grid;
  grid-template-columns: minmax(150px, 210px) 1fr;
  gap: 18px;
  align-items: start;
  flex: 1;
}
.ex-mascot { display: flex; flex-direction: column; align-items: center; gap: 14px; position: sticky; top: 12px; }
.ex-mascot .bubble { font-size: 1rem; padding: 12px 14px; text-align: center; width: 100%; }
.ex-mascot .bubble::before { left: 50%; top: auto; bottom: -12px; transform: translateX(-50%) rotate(-45deg); }
.mascot-svg { width: 100%; max-width: 190px; aspect-ratio: 1; }
.mascot-svg svg { width: 100%; height: 100%; }
.ex-play { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.ex-stage {
  min-height: 230px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  position: relative;
}
.ex-tools { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.ex-tools:empty { display: none; }
.ex-answers { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 12px; }
.ex-answers.wide { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.ex-answers.chromatic { grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); }
.ex-footer { display: flex; justify-content: center; min-height: 64px; align-items: center; }

@media (max-width: 760px) {
  .ex-main { grid-template-columns: 1fr; }
  .ex-mascot { flex-direction: row-reverse; position: static; }
  .mascot-svg { width: 96px; flex: 0 0 96px; }
  .ex-mascot .bubble { text-align: left; }
  .ex-mascot .bubble::before { left: -12px; top: 50%; bottom: auto; transform: translateY(-50%) rotate(45deg); }
  .dots { order: 5; width: 100%; justify-content: center; }
}

.staff-box { width: min(100%, 460px); }
.staff-box .staff { width: 100%; height: auto; display: block; overflow: visible; }
.staff-box.small { width: min(100%, 300px); }
.big-name { font-size: 2.6rem; font-weight: 800; line-height: 1; }
.big-name small { display: block; font-size: 1rem; color: var(--ink-soft); text-align: center; margin-top: 4px; }

/* Boutons de réponse */
.answer {
  --c: var(--lav);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 74px;
  padding: 10px 8px;
  border-radius: 20px;
  border: 3px solid color-mix(in srgb, var(--c) 55%, white);
  background: color-mix(in srgb, var(--c) 18%, white);
  box-shadow: 0 5px 0 color-mix(in srgb, var(--c) 60%, white);
  font-weight: 800;
  transition: transform 0.08s, box-shadow 0.08s, background 0.2s;
  user-select: none;
}
.answer:hover { background: color-mix(in srgb, var(--c) 28%, white); }
.answer:active { transform: translateY(4px); box-shadow: 0 1px 0 color-mix(in srgb, var(--c) 60%, white); }
.answer-label { font-size: 1.45rem; line-height: 1.1; }
.answer-sub { font-size: 0.85rem; color: var(--ink-soft); font-weight: 700; }
.answer .kbd {
  position: absolute; top: 5px; left: 8px;
  font-size: 0.72rem; font-weight: 800;
  color: color-mix(in srgb, var(--c) 70%, var(--ink));
  opacity: 0.7;
}
@media (hover: none) { .answer .kbd, .kbd-hint { display: none; } }
.answer.good { background: var(--good); border-color: var(--good); color: #fff; box-shadow: 0 5px 0 #1f9c6b; animation: pop 0.35s; }
.answer.good .answer-sub, .answer.good .kbd { color: #e8fff5; }
.answer.bad { background: var(--bad); border-color: var(--bad); color: #fff; box-shadow: 0 5px 0 #d84a60; animation: shake 0.4s; }
.answer.bad .answer-sub, .answer.bad .kbd { color: #ffe9ed; }
.answer.reveal { border-color: var(--good); box-shadow: 0 0 0 4px rgba(47, 197, 138, 0.35), 0 5px 0 #8fdcbc; animation: pulse 1s ease-in-out 2; }
.answers-locked .answer:not(.good):not(.bad):not(.reveal) { opacity: 0.55; }
.answer.sharp { --c: #8e8aa6; }

/* Zone mystère (écoute) */
.listen-orb {
  width: 150px; height: 150px; border-radius: 50%;
  display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #fff, color-mix(in srgb, var(--c) 35%, white));
  border: 4px solid color-mix(in srgb, var(--c) 45%, white);
  font-size: 3.6rem; font-weight: 800;
  color: color-mix(in srgb, var(--c) 80%, var(--ink));
  position: relative;
  cursor: pointer;
}
.listen-orb.playing::before, .listen-orb.playing::after {
  content: ""; position: absolute; inset: -6px; border-radius: 50%;
  border: 4px solid color-mix(in srgb, var(--c) 50%, white);
  animation: ripple 1.2s ease-out infinite;
}
.listen-orb.playing::after { animation-delay: 0.6s; }
@keyframes ripple { from { transform: scale(1); opacity: 0.8; } to { transform: scale(1.5); opacity: 0; } }
.reveal-text { font-weight: 800; font-size: 1.2rem; text-align: center; }
.reveal-text .hint { display: block; font-size: 0.98rem; color: var(--ink-soft); margin-top: 6px; font-weight: 700; }

/* Chant */
.sing-wrap { display: grid; grid-template-columns: 1fr auto; gap: 18px; align-items: center; width: 100%; }
.sing-target { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.meter {
  position: relative;
  width: 112px;
  height: 260px;
  border-radius: 22px;
  background: linear-gradient(#fff4f7, #f4f8ff);
  border: 3px solid var(--line);
  overflow: hidden;
}
.meter .row { position: absolute; left: 0; right: 0; height: calc(100% / 13); display: flex; align-items: center; padding-left: 10px; font-size: 0.78rem; font-weight: 800; color: #b9b1cf; border-top: 1px dashed #eee8f6; }
.meter .row.target { color: var(--ink); font-size: 0.95rem; }
.meter .band { position: absolute; left: 0; right: 0; background: rgba(47, 197, 138, 0.18); border-top: 2px solid rgba(47, 197, 138, 0.5); border-bottom: 2px solid rgba(47, 197, 138, 0.5); }
.meter .ball {
  position: absolute; right: 12px; width: 30px; height: 30px; margin-top: -15px;
  border-radius: 50%; background: var(--bad); border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: top 0.08s linear, background 0.15s, opacity 0.2s;
  opacity: 0;
}
.meter .ball.on { opacity: 1; }
.meter .ball.close { background: var(--sun); }
.meter .ball.ok { background: var(--good); }
.sing-status { font-weight: 800; font-size: 1.2rem; text-align: center; min-height: 1.6em; }
.ring { width: 92px; height: 92px; }
.ring circle { fill: none; stroke-width: 10; }
.ring .track { stroke: #efe9f8; }
.ring .fill { stroke: var(--good); stroke-linecap: round; transition: stroke-dashoffset 0.1s linear; transform: rotate(-90deg); transform-origin: center; }
.sing-panel { display: flex; align-items: center; justify-content: center; gap: 18px; flex-wrap: wrap; }
@media (max-width: 520px) { .sing-wrap { grid-template-columns: 1fr; justify-items: center; } .meter { width: 100%; max-width: 300px; height: 200px; } }

/* Piano */
.piano {
  position: relative;
  width: 100%;
  height: clamp(150px, 26vh, 230px);
  user-select: none;
  touch-action: none;
  -webkit-user-select: none;
}
.mini-piano { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.piano.mini { height: 130px; }
.piano.mini .key { cursor: pointer; }
.mini-piano-hint { text-align: center; font-size: 0.85rem; font-weight: 700; color: var(--ink-soft); }
.key { position: absolute; top: 0; padding: 0; border: 0; touch-action: none; }
.key.white {
  height: 100%;
  background: linear-gradient(#fff 80%, #f6f2fb);
  border: 2px solid #ddd5ec;
  border-radius: 0 0 14px 14px;
  box-shadow: inset 0 -6px 0 #ece6f6;
  z-index: 1;
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: 12px;
}
.key.black {
  height: 60%;
  background: linear-gradient(#4b4268, #2f2846);
  border-radius: 0 0 10px 10px;
  box-shadow: inset 0 -5px 0 #1d1830, 0 3px 4px rgba(0, 0, 0, 0.2);
  z-index: 2;
}
.key-label { display: flex; flex-direction: column; align-items: center; font-weight: 800; font-size: clamp(0.8rem, 1.6vw, 1.05rem); color: color-mix(in srgb, var(--kc) 75%, var(--ink)); pointer-events: none; line-height: 1.1; }
.key-label small { font-size: 0.72em; color: var(--ink-soft); font-weight: 700; }
.key.white.pressed, .key.white.lit { background: linear-gradient(color-mix(in srgb, var(--kc) 30%, white), color-mix(in srgb, var(--kc) 50%, white)); box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--kc) 60%, white); }
.key.black.pressed, .key.black.lit { background: linear-gradient(#8a7fd0, #6a5fb5); box-shadow: inset 0 -2px 0 #4a3f8f; }
.key.good { background: linear-gradient(#c9f5e2, #8de6c1) !important; }
.key.good.pressed { filter: brightness(0.88); }
.key.black.good { background: linear-gradient(#3fcf9c, #23a576) !important; }
.piano.mini .key-label { font-size: 0.75rem; }

/* Découverte (piano libre) */
.discover-stage { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 18px; padding: 16px; }
.discover-stage .companion { width: clamp(90px, 14vw, 150px); }
.discover-stage .companion svg { width: 100%; height: auto; }
.discover-name { text-align: center; min-width: 110px; }
@media (max-width: 700px) { .discover-stage { grid-template-columns: 1fr 1fr; } .discover-stage .staff-box { grid-column: 1 / -1; order: 3; } }

/* Résumé de partie */
.summary { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 26px 18px; text-align: center; max-width: 640px; margin: 0 auto; width: 100%; }
.summary .mascot-svg { max-width: 170px; }
.summary-score { font-size: 3rem; font-weight: 800; line-height: 1; }
.summary-score small { font-size: 1.4rem; color: var(--ink-soft); }
.stars { font-size: 3.2rem; letter-spacing: 6px; }
.star { color: #e6e0f0; display: inline-block; }
.star.on { color: #ffc93c; text-shadow: 0 3px 0 #e6a700; animation: starIn 0.5s cubic-bezier(.3, 1.8, .5, 1) both; animation-delay: calc(var(--i) * 0.18s + 0.2s); }
@keyframes starIn { from { transform: scale(0) rotate(-90deg); } to { transform: scale(1) rotate(0); } }
.summary-row { display: flex; gap: 12px; align-items: center; justify-content: center; flex-wrap: wrap; }
.unlock { background: #fff6e0; border: 2px dashed #ffd27a; border-radius: 18px; padding: 10px 16px; font-weight: 800; display: flex; align-items: center; gap: 10px; }
.unlock svg { width: 64px; height: 64px; }

/* Progrès */
.progress-cat { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.progress-head { display: flex; align-items: center; gap: 12px; }
.progress-head h3 { flex: 1; }
.item-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.item-chip { padding: 4px 10px; border-radius: 999px; font-weight: 800; font-size: 0.88rem; background: #f1edf8; color: #9a92b5; }
.item-chip.lv1 { background: #ffe3e8; color: #d6455d; }
.item-chip.lv2 { background: #fff0d6; color: #c77700; }
.item-chip.lv3 { background: #d9f7ea; color: #1b9466; }
.history { display: flex; align-items: flex-end; gap: 3px; height: 46px; }
.history span { flex: 1; max-width: 14px; background: color-mix(in srgb, var(--c) 60%, white); border-radius: 4px 4px 0 0; min-height: 3px; }

/* ---------- Salle de concert ---------- */
.library-tabs button { font-size: 1.02rem; }
.library-content { display: flex; flex-direction: column; gap: 18px; }
.composer { display: flex; flex-direction: column; gap: 10px; }
.composer-name { font-size: 1.3rem; }
.composer-name .muted { font-size: 0.95rem; font-weight: 700; }
.piece-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.piece-card {
  display: flex; flex-direction: column; gap: 6px;
  padding: 14px 16px;
  text-align: left;
  border-radius: 20px;
  border: 2px solid #f3d5ec;
  background: radial-gradient(140px 90px at 100% 0%, #fde8f6 0%, transparent 70%), #fff;
  box-shadow: 0 4px 0 #f3d5ec, 0 10px 24px rgba(84, 62, 150, 0.08);
  transition: transform 0.15s;
}
.piece-card:hover { transform: translateY(-3px); }
.piece-card:active { transform: translateY(1px); }
.piece-head { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; }
.piece-title { font-weight: 800; font-size: 1.12rem; }
.piece-level { color: #ffb52e; font-size: 1rem; white-space: nowrap; letter-spacing: 1px; }
.piece-meta { font-size: 0.88rem; font-weight: 700; color: #c2549f; }
.piece-desc { font-size: 0.92rem; color: var(--ink-soft); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.piece-card.mine { flex-direction: row; align-items: center; }
.piece-card.mine:hover { transform: none; }
.piece-open { flex: 1; background: none; border: 0; text-align: left; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.small-del { width: 44px; height: 44px; font-size: 1.1rem; }
.mine-intro { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.empty-mine { padding: 18px; font-weight: 700; color: var(--ink-soft); }

.score-title h1 { font-size: 1.5rem; }
.score-about { padding: 14px 16px; display: flex; gap: 14px; align-items: center; }
.score-about .chip { white-space: normal; margin-top: 6px; }
.score-companion { width: 74px; flex: 0 0 74px; }
.score-companion svg { width: 100%; height: auto; }
.score-controls {
  position: sticky; top: 8px; z-index: 5;
  padding: 10px 14px;
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
}
.play-btn { min-width: 170px; }
.tempo { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.tempo input[type="range"] { width: 140px; }
.tempo-label { font-size: 0.9rem; color: var(--ink-soft); font-weight: 800; min-width: 92px; }
.seek-wrap { flex: 1; min-width: 220px; }
.seek-wrap input[type="range"] { width: 100%; }
.note-info { font-size: 0.95rem; }
.score { padding: 12px; overflow: hidden; }
.score-loading { text-align: center; padding: 30px; }
.score-paper svg { display: block; }
.score .abcjs-note, .score .abcjs-rest { cursor: pointer; }
.score .playing, .score .playing path { fill: #ff4f8b !important; color: #ff4f8b; }
.score .abcjs-note_selected, .score .abcjs-note_selected path { fill: #ff7eaa; }

.fall-stage { padding: 12px; display: flex; flex-direction: column; gap: 0; }
.fall-canvas { display: block; background: linear-gradient(#f8f4ff, #fff6fb); border-radius: 16px 16px 0 0; }
.fall-piano .piano { height: clamp(120px, 20vh, 190px); }

/* ---------- Caméra ---------- */
.cam { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.cam-view { position: relative; width: min(72vw, 340px); aspect-ratio: 1; border-radius: 50%; overflow: hidden; background: #2f2846; border: 6px solid #fff; box-shadow: var(--shadow); }
.cam-view video, .cam-view img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-view video { transform: scaleX(-1); }
.cam-count { position: absolute; inset: 0; display: grid; place-items: center; font-size: 6rem; font-weight: 800; color: #fff; text-shadow: 0 4px 12px rgba(0, 0, 0, 0.4); pointer-events: none; }
.cam-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.cam-flash.go { animation: flash 0.5s ease-out; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }

/* ---------- Modales, toasts, confettis ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(59, 51, 85, 0.35);
  backdrop-filter: blur(4px);
  display: grid; place-items: center;
  padding: 16px;
  animation: fadeIn 0.2s;
}
.modal-back.closing { animation: fadeOut 0.2s forwards; }
.modal {
  background: #fff;
  border-radius: 28px;
  padding: 26px 22px 22px;
  width: min(520px, 100%);
  max-height: 90dvh;
  overflow: auto;
  text-align: center;
  box-shadow: 0 20px 60px rgba(59, 51, 85, 0.3);
  animation: pop 0.4s cubic-bezier(.3, 1.6, .5, 1);
  display: flex; flex-direction: column; gap: 14px; align-items: center;
}
.modal-title { font-size: 1.7rem; }
.modal p { margin: 0; font-weight: 600; }
.modal-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 6px; }
.modal .big-medal svg { width: 110px; height: auto; animation: medalIn 0.8s cubic-bezier(.3, 1.6, .5, 1) both; }
@keyframes medalIn { from { transform: scale(0) rotate(-200deg); } to { transform: scale(1) rotate(0); } }

#fx-root { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.confetti {
  position: absolute; top: -20px; left: var(--x);
  width: 10px; height: 14px; border-radius: 3px;
  animation: fall var(--d) cubic-bezier(.25, .6, .45, 1) var(--delay) forwards;
}
.confetti.round { border-radius: 50%; width: 11px; height: 11px; }
.confetti.long { width: 6px; height: 18px; }
@keyframes fall { to { transform: translate(var(--dx), 110vh) rotate(var(--r)); } }
.toast {
  position: absolute; left: 50%; top: max(16px, env(safe-area-inset-top));
  transform: translateX(-50%);
  background: #fff; border: 2px solid var(--line); border-radius: 18px;
  padding: 12px 20px; font-weight: 800; box-shadow: var(--shadow);
  animation: slideDown 0.35s cubic-bezier(.3, 1.5, .5, 1);
  max-width: calc(100vw - 32px);
}
.toast.out { animation: fadeOut 0.4s forwards; }

/* ---------- Animations des créatures ---------- */
.creature .eyes { animation: blink 4.5s infinite; transform-box: fill-box; transform-origin: center; }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 96% { transform: scaleY(0.12); } }
.idle-bob svg, .idle-bob { animation: bob 2.8s ease-in-out infinite; }
.anim-jump { animation: jump 0.6s cubic-bezier(.3, 1.6, .5, 1); }
.anim-shake { animation: wobble 0.6s; }
.anim-sing { animation: sing 0.5s ease-in-out infinite alternate; }

@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes jump { 0% { transform: translateY(0) scale(1); } 30% { transform: translateY(-22px) scale(1.05, 0.95); } 60% { transform: translateY(0) scale(1.08, 0.92); } 100% { transform: none; } }
@keyframes wobble { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(-8deg); } 40% { transform: rotate(7deg); } 60% { transform: rotate(-5deg); } 80% { transform: rotate(3deg); } }
@keyframes sing { from { transform: scale(1); } to { transform: scale(1.04, 0.97) translateY(2px); } }
@keyframes pop { 0% { transform: scale(0.85); } 60% { transform: scale(1.05); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-7px); } 50% { transform: translateX(6px); } 75% { transform: translateX(-4px); } }
@keyframes pulse { 50% { transform: scale(1.05); } }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes fadeOut { to { opacity: 0; } }
@keyframes slideDown { from { transform: translate(-50%, -30px); opacity: 0; } }

.floating-note {
  position: absolute; font-size: 1.8rem; font-weight: 800; pointer-events: none;
  animation: floatUp 1.4s ease-out forwards;
}
@keyframes floatUp { from { transform: translate(0, 0) scale(0.6); opacity: 1; } to { transform: translate(var(--fx, 20px), -90px) scale(1.2); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  #bg .float { display: none; }
}

/* ---------- Défi chrono ---------- */
.chrono-chips { display: flex; gap: 8px; }
.chrono-score { color: color-mix(in srgb, var(--good) 75%, var(--ink)); border-color: color-mix(in srgb, var(--good) 35%, white); }
.chrono-timer { flex-basis: 100%; display: flex; align-items: center; gap: 12px; }
.chrono-bar { flex: 1; height: 16px; border-radius: 999px; background: #f1edf8; border: 2px solid var(--line); overflow: hidden; }
.chrono-bar span { display: block; height: 100%; width: 100%; border-radius: inherit; background: var(--c); transition: width 0.1s linear, background 0.4s; }
.chrono-bar.low span { background: var(--peach); }
.chrono-time { min-width: 2.6ch; text-align: right; font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.chrono-count { font-size: clamp(3rem, 12vw, 5.5rem); font-weight: 800; color: var(--c); line-height: 1; }

.chrono-intro { display: flex; align-items: center; gap: 16px; padding: 16px 18px; }
.chrono-intro .mascot-svg { width: 92px; flex: 0 0 92px; }
.chrono-levels { display: grid; gap: 10px; }
.chrono-level {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px; min-height: 64px; text-align: left;
  border-radius: 18px; border: 2px solid color-mix(in srgb, var(--c) 30%, white); background: #fff;
  box-shadow: 0 4px 0 color-mix(in srgb, var(--c) 30%, white);
  transition: transform 0.08s;
}
.chrono-level:not(:disabled):active { transform: translateY(3px); box-shadow: 0 1px 0 color-mix(in srgb, var(--c) 30%, white); }
.chrono-level.locked { box-shadow: none; border-style: dashed; }
.chrono-level-num {
  width: 38px; height: 38px; flex: 0 0 38px; border-radius: 12px;
  display: grid; place-items: center; font-weight: 800; color: #fff; background: var(--c);
}
.chrono-level.locked .chrono-level-num { background: #d9d2e8; }
.chrono-level-name { flex: 1; font-weight: 800; display: flex; flex-direction: column; }
.chrono-level-name small { font-weight: 700; color: var(--ink-soft); font-size: 0.85rem; }
.chrono-level-best { font-weight: 800; color: var(--ink-soft); text-align: right; }
@media (max-width: 520px) {
  .chrono-intro { padding: 12px 14px; gap: 12px; }
  .chrono-intro .mascot-svg { width: 60px; flex-basis: 60px; }
  .chrono-level { gap: 10px; padding: 10px 12px; }
  .chrono-level-best { font-size: 0.85rem; max-width: 38%; }
}
