/* Piano Lessons page (piano.html), on top of css/learn.css (shell, map)
   and css/piano-keys.css (the keyboard and its lane).

   Phone first at 375px with the shell's 16px gutters: nothing here is wider
   than its column, long rows wrap, and only the keyboard scrolls sideways
   (inside its own box). Every control is at least 44px; the big ones are
   56px+ for a five-year-old's whole-finger tap. Results always pair an icon
   and words with colour. */

.piano-visually {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.piano-heading {
  margin: 4px 0 12px;
  font-family: "Fredoka", system-ui, sans-serif;
  font-weight: 600;
  font-size: 1.4rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.piano-heading:focus { outline: none; }

.piano-loading { padding: 32px 0; text-align: center; font-weight: 800; }

/* ---------- buttons ---------- */

body.learn .piano-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  min-width: 44px;
  padding: 8px 14px;
  border: 3px solid transparent;
  border-radius: 16px;
  background: var(--learn-card, #fff);
  font-weight: 800;
  line-height: 1.15;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.1);
  transition: transform 0.1s ease;
  touch-action: manipulation;
}
.piano-btn:active { transform: translateY(2px); }
body.learn .piano-btn:disabled { opacity: 0.5; cursor: default; transform: none; }
body.learn .piano-big {
  min-height: 56px;
  padding: 10px 20px;
  font-size: 1.15rem;
  border-radius: 20px;
}
body.learn .piano-next, body.learn .piano-go {
  background: var(--learn-accent, #234e46);
  color: #fff !important;
}
body.learn .piano-retry { border-color: var(--learn-accent, #234e46); }
.piano-go { animation: piano-pulse 1.6s ease-in-out infinite; }
@keyframes piano-pulse {
  50% { box-shadow: 0 3px 0 rgba(0, 0, 0, 0.1), 0 0 0 6px var(--learn-sun, #f5c967); }
}

/* ---------- map extras ---------- */

.piano-maptop {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin-bottom: 14px;
}
body.learn .piano-tile {
  min-height: 64px;
  padding: 10px 22px;
  font-size: 1.2rem;
  border-color: var(--learn-accent, #234e46);
  border-radius: 22px;
}
.piano-tile-emoji { font-size: 1.7rem; margin-right: 8px; }
body.learn .piano-skip {
  margin-top: 12px;
  border-color: var(--learn-accent, #234e46);
}

/* ---------- lesson layout ---------- */

.piano-lessonbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}
.piano-lessonbar .piano-heading { flex: 1 1 160px; min-width: 0; margin: 0; }
.piano-steps { margin: 0; }
.piano-dots { display: inline-flex; gap: 6px; }
.piano-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid var(--learn-accent, #234e46);
  background: transparent;
}
.piano-dot-done { background: var(--learn-accent, #234e46); }
.piano-dot-now { background: var(--learn-sun, #f5c967); }

.piano-say {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 12px 0;
  padding: 14px 16px;
  border-radius: 20px;
  background: var(--learn-card, #fff);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.06);
}
.piano-say-text {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}
.piano-again { flex: none; font-size: 1.3rem; }

.piano-lyric {
  min-height: 1.4em;
  margin: 0 0 6px;
  text-align: center;
  font-family: "Fredoka", system-ui, sans-serif;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--learn-accent, #234e46);
}
.piano-lyric:empty { min-height: 0; }

.piano-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 100%;
}
.piano-score:empty { display: none; }
.piano-score > svg.staff {
  display: block;
  width: 100%;
  max-width: 560px;
  max-height: 170px;
  padding: 6px;
  border-radius: 14px;
  background: #fff;
}
.piano-prompt {
  margin: 0;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--learn-soft, #dcecd8);
  font-size: 1.2rem;
  font-weight: 800;
  text-align: center;
}

.piano-count {
  min-height: 0;
  text-align: center;
  font-family: "Fredoka", system-ui, sans-serif;
  font-size: 3rem;
  font-weight: 600;
  line-height: 1;
  color: var(--learn-accent, #234e46);
}
.piano-count:empty { display: none; }

.piano-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}
.piano-hint { margin: 0; font-weight: 800; font-size: 1.1rem; }

.piano-live {
  min-height: 1.5em;
  margin: 6px 0 10px;
  text-align: center;
  font-weight: 800;
  font-size: 1.1rem;
}

.piano-kbhost { margin: 6px 0 12px; max-width: 100%; }

/* ---------- settings row ---------- */

.piano-settings {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin: 10px 0 0;
}
.piano-seg { display: inline-flex; flex-wrap: wrap; gap: 4px; }
body.learn .piano-seg-btn { padding: 6px 12px; font-size: 0.95rem; box-shadow: none; border-color: var(--learn-soft, #dcecd8); }
body.learn .piano-seg-btn[aria-pressed="true"] {
  border-color: var(--learn-accent, #234e46);
  background: var(--learn-soft, #dcecd8);
}
.piano-seg-btn[aria-pressed="true"]::before { content: "✓ "; }

.piano-midi { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.piano-midi-status { font-weight: 700; font-size: 0.95rem; overflow-wrap: anywhere; }

/* ---------- play / rhythm results ---------- */

.piano-accuracy { margin: 0; text-align: center; font-weight: 700; }
.piano-accuracy strong { font-size: 1.8rem; margin-right: 4px; }
.piano-extras { margin: 4px 0 0; text-align: center; font-weight: 600; }
.piano-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  max-width: 100%;
}
.piano-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 44px;
  padding: 4px 10px;
  border: 2px solid transparent;
  border-radius: 12px;
  font-weight: 800;
}
.piano-chip-hit { background: #dcf5dc; border-color: #4caf50; }
.piano-chip-early, .piano-chip-late { background: #fff1d6; border-color: #e0a050; }
.piano-chip-miss { background: #eef0f2; border-color: #9aa3ab; border-style: dashed; }

/* ---------- rhythm ---------- */

.piano-rhythm {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.piano-beat {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: calc(40px * var(--dur, 1));
  max-width: 100%;
  height: 52px;
  border-radius: 12px;
  background: var(--learn-card, #fff);
  border: 3px solid var(--learn-soft, #dcecd8);
  font-size: 1.8rem;
}
.piano-rest { border-style: dashed; opacity: 0.8; }
.piano-beat-now {
  border-color: var(--learn-accent, #234e46);
  border-style: solid;
  background: var(--learn-sun, #f5c967);
}
body.learn .piano-pad {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: min(240px, 100%);
  aspect-ratio: 1;
  max-height: 40vh;
  border: 6px solid var(--learn-accent, #234e46);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #fff, var(--learn-soft, #dcecd8));
  font-size: 3.6rem;
  line-height: 1;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.piano-pad-word { font-size: 1.3rem; font-weight: 800; margin-top: 4px; }
.piano-pad-hit { animation: piano-thump 0.15s ease-out; }
@keyframes piano-thump { 50% { transform: scale(0.94); } }

/* ---------- note reading ---------- */

.piano-qcount { margin: 0; font-weight: 800; }
.piano-readstaff { width: min(260px, 100%); padding: 6px; border-radius: 14px; background: #fff; }
.piano-readstaff svg { display: block; width: 100%; height: auto; max-height: 180px; }
.piano-choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
body.learn .piano-choice { min-width: 64px; min-height: 56px; font-size: 1.4rem; border-color: var(--learn-soft, #dcecd8); }
body.learn.theme-bella .piano-choice.piano-pc-0  { background: #ffd9d9; }
body.learn.theme-bella .piano-choice.piano-pc-2  { background: #ffe4c7; }
body.learn.theme-bella .piano-choice.piano-pc-4  { background: #fff3b8; }
body.learn.theme-bella .piano-choice.piano-pc-5  { background: #d6f5cf; }
body.learn.theme-bella .piano-choice.piano-pc-7  { background: #cdeffa; }
body.learn.theme-bella .piano-choice.piano-pc-9  { background: #d9dcff; }
body.learn.theme-bella .piano-choice.piano-pc-11 { background: #ecd8fb; }

/* ---------- free play ---------- */

body.learn .piano-rec.piano-recording { border-color: #c0392b; }
.piano-rec.piano-recording::before { content: "●"; color: #c0392b; margin-right: 2px; }

/* ---------- celebration ---------- */

.piano-celebrate {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px 16px;
  border-radius: 28px;
  background: var(--learn-card, #fff);
  text-align: center;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.06);
}
.piano-celebrate p { margin: 0; overflow-wrap: anywhere; }
.piano-confetti { font-size: 2.2rem; letter-spacing: 6px; animation: piano-bounce 1.4s ease-in-out infinite; }
@keyframes piano-bounce { 50% { transform: translateY(-8px); } }
.piano-starrow { display: inline-flex; gap: 4px; font-size: 2.6rem; line-height: 1; }
.piano-best .piano-starrow { font-size: 1.3rem; vertical-align: middle; }
.piano-star { opacity: 0.4; }
.piano-star-on { opacity: 1; }
.piano-celebrate-lesson { font-weight: 800; font-size: 1.15rem; }

/* ---------- timing check ---------- */

.piano-cal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(20, 30, 32, 0.55);
  overflow-y: auto;
}
.piano-cal-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: min(460px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 18px 16px 20px;
  border-radius: 24px;
  background: var(--learn-bg, #eef6ee);
  color: var(--learn-ink, #253f44);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  text-align: center;
}
.piano-cal-title { margin: 0; font-size: 1.4rem; }
.piano-cal-title:focus { outline: none; }
.piano-cal .piano-say { width: 100%; }
.piano-cal-say { margin: 0; font-weight: 700; }
body.learn .piano-cal-drum {
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(220px, 60vw);
  aspect-ratio: 1;
  max-height: 36vh;
  border: 6px solid var(--learn-accent, #234e46);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #fff, var(--learn-soft, #dcecd8));
  font-size: 3.6rem;
  line-height: 1;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.piano-cal-beat { animation: piano-cal-pulse 0.32s ease-out; }
.piano-cal-hit { animation: piano-thump 0.15s ease-out; }
@keyframes piano-cal-pulse {
  0% { transform: scale(1.12); box-shadow: 0 0 0 14px var(--learn-sun, #f5c967); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 transparent; }
}
.piano-cal-dots { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.piano-cal-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--learn-accent, #234e46);
}
.piano-cal-dot-on { background: var(--learn-sun, #f5c967); }
.piano-cal-status { margin: 0; font-size: 0.9rem; opacity: 0.8; }
.piano-cal-controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
body.learn .piano-cal-reset { box-shadow: none; border-color: var(--learn-soft, #dcecd8); font-size: 0.95rem; }

@media (min-width: 640px) {
  .piano-heading { font-size: 1.7rem; }
}

@media (prefers-reduced-motion: reduce) {
  .piano-go, .piano-confetti, .piano-pad-hit, .piano-cal-hit { animation: none !important; }
  .piano-cal-beat { animation: none !important; outline: 8px solid var(--learn-sun, #f5c967); }
  .piano-btn { transition: none; }
}
