/* One quiet task fills the room; exit, progress and settings stay within reach. */
.lesson-shell { display: flex; flex-direction: column; width: 100%; max-width: 700px; height: calc(100dvh - 40px); min-height: 460px; margin: 0 auto; }
.lesson-topline { display: flex; align-items: center; flex: 0 0 44px; gap: 16px; margin-bottom: 20px; }
.lesson-progress-wrap { flex: 1; position: relative; min-width: 0; }
.lesson-progress { height: 12px; border-radius: 999px; background: #a5d8b916; overflow: hidden; }
.lesson-progress span { display: block; height: 100%; border-radius: inherit; background: var(--match); transition: width .5s cubic-bezier(.2,.7,.2,1); transform-origin: right center; }
.lesson-progress-success span { animation: lesson-progress-fill .5s cubic-bezier(.2,.7,.2,1), lesson-progress-settle .68s ease-out; }
.lesson-combo { position: absolute; top: -23px; right: 3px; color: var(--match); font-size: 9px; font-weight: 600; letter-spacing: .1em; line-height: 14px; }
.lesson-combo[hidden] { display: none; }
.lesson-combo-show { animation: lesson-combo-rise .4s ease both; }
.lesson-settings, .lesson-exit { display: flex; align-items: center; justify-content: center; flex: 0 0 44px; width: 44px; height: 44px; padding: 10px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; }
.lesson-settings svg, .lesson-exit svg { display: block; width: 23px; height: 23px; }
.lesson-settings:hover, .lesson-exit:hover { color: var(--paper); background: #a5d8b90a; }
/* Anchor the prompt independently of result-panel and activity heights. */
.lesson-task { display: flex; flex-direction: column; justify-content: flex-start; min-height: 0; flex: 1; width: 100%; max-width: 560px; margin: 0 auto; padding: clamp(0px, calc((100dvh - 660px) / 2), 96px) 0 0; }
.lesson-heading { text-align: center; margin-bottom: 29px; }
.lesson-heading h2, .lesson-complete-shell h2 { color: var(--paper); font: 400 clamp(27px, 4.5vw, 34px)/1.2 var(--serif); letter-spacing: -.035em; margin: 0; }
.lesson-heading h2:focus, .lesson-complete-shell h2:focus, .lesson-feedback:focus { outline: none; }
.lesson-stage { width: 100%; min-width: 0; padding: 0; background: none; border: 0; }
.lesson-keyboard, .lesson-write { position: relative; left: 50%; width: 100vw; margin-left: -50vw; }
.lesson-keyboard .piano { --piano-inset: 0px; --piano-gutters: 0px; width: 100%; height: clamp(180px, 29dvh, 320px); margin: 0; padding: 0 0 6px; border: 0; border-radius: 0; box-shadow: none; }
.lesson-keyboard .key.black { top: 0; }
.lesson-keyboard .key { touch-action: manipulation; }
.lesson-keyboard .key:focus-visible { z-index: 5; outline: 2px solid var(--gold); outline-offset: -3px; }
/* Read questions share the Write staff band: full bleed, same height, same scale. */
.lesson-notation { position: relative; left: 50%; width: 100vw; margin-left: -50vw; height: clamp(208px, 32dvh, 300px); background: var(--paper); overflow: hidden; }
.lesson-notation svg { display: block; width: 100%; height: 100%; }
@media (max-height: 620px) { .lesson-notation { height: 208px; } }
.lesson-choices { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 10px; margin-top: 25px; }
.lesson-choices:has(> :last-child:nth-child(2)) { grid-template-columns: repeat(2,minmax(0,1fr)); }
.lesson-choice { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; min-height: 76px; padding: 11px 8px; border: 1px solid #a5d8b939; border-radius: 10px; background: var(--panel); color: var(--paper); cursor: pointer; font-size: 14px; transition: border-color .16s, background .16s; }
.lesson-choice:not(:disabled):hover { background: #a5d8b918; border-color: #a5d8b970; }
.lesson-choice[aria-pressed="true"] { border-color: var(--gold); background: #dac18d0d; }
.lesson-choice-name { font: 400 28px/1 var(--serif); letter-spacing: -.035em; }
.lesson-choice-quality { color: var(--muted); font-size: 10px; }
.lesson-choice:disabled { cursor: default; opacity: .5; }
.lesson-choice.lesson-choice-correct { opacity: 1; background: #a5d8b91a; border-color: var(--match); }
.lesson-choice.lesson-choice-retry,
.lesson-choice.lesson-choice-retry:hover {
  border-color: #ed9191;
  background: #a52c2c40;
  box-shadow: inset 0 0 0 1px #ed919170;
  animation: lesson-choice-error .28s ease-in-out 2;
}
@keyframes lesson-choice-error {
  0%, 100% { background: #a52c2c40; }
  50% { background: #c0444470; box-shadow: inset 0 0 0 2px #ed9191; }
}
@media (prefers-reduced-motion: reduce) {
  .lesson-choice.lesson-choice-retry, .lesson-choice.lesson-choice-retry:hover { animation: none; }
}
.lesson-listening { display: flex; flex-direction: column; align-items: center; text-align: center; min-height: 148px; }
.lesson-sound-lines { display: flex; justify-content: center; align-items: center; gap: 6px; height: 45px; margin-bottom: 16px; color: var(--gold); }
.lesson-sound-lines i { width: 3px; height: 16px; background: currentColor; border-radius: 3px; opacity: .7; }
.lesson-sound-lines i:nth-child(2), .lesson-sound-lines i:nth-child(4) { height: 29px; }
.lesson-sound-lines i:nth-child(3) { height: 42px; }
.lesson-play { display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-height: 48px; padding: 12px 19px; border: 1px solid #a5d8b975; background: #a5d8b910; border-radius: 9px; color: var(--match); font-size: 13px; cursor: pointer; }
.lesson-play svg { width: 18px; height: 18px; }
.lesson-play:hover { background: #a5d8b921; }
.lesson-text-button { min-height: 44px; padding: 9px 3px; color: var(--muted); border: 0; background: none; font-size: 11px; text-decoration: underline; text-underline-offset: 4px; text-decoration-color: #aabbb160; cursor: pointer; }
.lesson-text-button:hover { color: var(--paper); text-decoration-color: var(--paper); }
.lesson-feedback-slot { display: grid; place-content: center; width: 100%; min-height: 98px; flex: 0 0 98px; }
.lesson-guidance { color: var(--muted); font-size: 11px; line-height: 1.7; margin: 0; text-align: center; }
.lesson-feedback:empty { display: none; }
.lesson-feedback.feedback-panel { margin: 0; padding: 0; border: 0; border-radius: 0; background: none; gap: 9px; font-size: 11px; line-height: 1.5; }
.lesson-feedback.feedback-panel[data-feedback] { background: none; border: 0; }
.lesson-feedback .feedback-symbol { flex-basis: 20px; width: 20px; height: 20px; margin-top: 0; }
.lesson-feedback .feedback-message { font-size: 12px; line-height: 1.5; }
.lesson-feedback .feedback-hint { margin-top: 3px; }
.lesson-bottom { display: flex; align-items: center; justify-content: center; width: 100%; }
.lesson-primary, .lesson-secondary { display: inline-flex; align-items: center; justify-content: center; gap: 16px; min-height: 48px; padding: 13px 19px; border: 1px solid var(--match); border-radius: 9px; background: var(--match); color: #103322; cursor: pointer; font-size: 12px; font-weight: 600; white-space: nowrap; transition: background .15s; }
.lesson-bottom .lesson-primary { width: 100%; max-width: 360px; }
.lesson-primary span { font-size: 16px; line-height: 1; }
.lesson-primary:hover:not(:disabled) { background: #b9e4c9; }
.lesson-primary:disabled { cursor: default; color: #9eaea4; background: #223c34; border-color: #65857957; }

.lesson-result-panel { position: relative; isolation: isolate; flex: 0 0 auto; padding: 20px 0 max(4px, env(safe-area-inset-bottom)); color: var(--match); animation: lesson-result-enter .22s ease-out; }
.lesson-result-panel::before { content: ''; position: absolute; z-index: -1; top: 0; bottom: -20px; left: 50%; width: 100vw; transform: translateX(-50%); background: #213e33; border-top: 1px solid #a5d8b924; }
.lesson-result-inner { width: 100%; max-width: 560px; margin-inline: auto; }
.lesson-result-heading { display: flex; align-items: center; gap: 12px; }
.lesson-result-heading svg { flex: 0 0 28px; width: 28px; height: 28px; }
.lesson-result-heading h3 { margin: 0; font: 600 23px/1.3 var(--sans); letter-spacing: -.02em; }
.lesson-answer-xp { margin-left: auto; color: var(--gold-2); font-size: 14px; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.lesson-result-status p { color: var(--muted); font-size: 12px; line-height: 1.5; margin: 6px 0 0; }
.lesson-result-revealed { color: var(--gold); }
.lesson-continue { width: 100%; min-height: 56px; margin-top: 18px; font-size: 14px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; box-shadow: 0 4px 0 #6c9e80; touch-action: manipulation; }
.lesson-continue:active { transform: translateY(3px); box-shadow: 0 1px 0 #6c9e80; }
.lesson-continue:focus-visible { outline: 2px solid var(--paper); outline-offset: 6px; }
.lesson-secondary { border-color: var(--line); background: none; color: var(--muted); font-weight: 400; }
.lesson-secondary:hover { color: var(--paper); background: #a5d8b909; }
.lesson-overline { color: var(--muted); font-size: 10px; line-height: 1.7; letter-spacing: .06em; margin: 0 0 9px; }
/* A single completion moment, with the action docked inside the live viewport. */
body[data-current-mode="complete"] .wrap { display: flex; flex-direction: column; min-height: 100dvh; padding: 16px 20px max(16px, env(safe-area-inset-bottom)); }
body[data-current-mode="complete"] .wrap > header { flex: 0 0 auto; padding-bottom: 12px; }
#lessonCompleteView:not([hidden]) { display: flex; flex: 1; }
.lesson-complete-shell { display: flex; flex-direction: column; width: 100%; max-width: 560px; margin: 0 auto; text-align: center; }
.lesson-complete-summary { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 24px 0; }
.lesson-complete-mark { margin-bottom: 14px; }
.lesson-complete-mark svg { width: 56px; height: 56px; stroke: var(--match); stroke-width: 4.5; stroke-linecap: round; stroke-linejoin: round; overflow: visible; animation: lesson-check-pulse 2.6s ease-in-out .55s infinite; }
.lesson-complete-mark path { stroke-dasharray: 1; stroke-dashoffset: 0; animation: lesson-check-draw .55s cubic-bezier(.22,.7,.3,1) both; }
@keyframes lesson-check-draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes lesson-check-pulse {
  0%, 100% { transform: scale(1); stroke: var(--match); filter: drop-shadow(0 0 2px #70efaa25); }
  50% { transform: scale(1.09); stroke: #72efa7; filter: drop-shadow(0 0 9px #70efaa70); }
}
.lesson-complete-summary > .lesson-overline { text-transform: uppercase; font-size: 9px; letter-spacing: .1em; }
.lesson-complete-shell h2 { font-size: clamp(30px, 5vw, 42px); }
.lesson-complete-copy { color: var(--muted); font-size: 12px; line-height: 1.6; margin: 12px auto 20px; max-width: 40ch; }
.lesson-result { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); padding: 20px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.lesson-result > div { display: flex; flex-direction: column; gap: 8px; align-items: center; padding: 0 8px; }
.lesson-result > div + div { border-left: 1px solid var(--line); }
.lesson-result strong { font: 400 35px/1.1 var(--serif); color: var(--paper); }
.lesson-result strong span { font-size: 21px; color: var(--muted); }
.lesson-result div > span { font-size: 10px; color: var(--muted); line-height: 1.6; }
.lesson-revisit-note { color: var(--muted); font-size: 11px; line-height: 1.5; margin: 12px 10px 0; }
.lesson-complete-footer { position: sticky; bottom: 0; padding-top: 12px; background: var(--bg); }
.lesson-complete-actions { display: flex; flex-direction: column; gap: 6px; width: 100%; max-width: 360px; margin: 0 auto; }
.lesson-complete-actions > button { width: 100%; min-height: 48px; }
.lesson-complete-actions .lesson-secondary { background: transparent; border-color: transparent; color: var(--muted); }
.lesson-saved-note { color: var(--muted); font-size: 10px; line-height: 1.5; margin: 6px 0 0; }
@media (max-height: 650px) {
  .lesson-complete-summary { padding: 12px 0; }
  .lesson-complete-shell h2 { font-size: 28px; }
  .lesson-complete-mark { margin-bottom: 8px; }
  .lesson-complete-mark svg { width: 40px; height: 40px; }
  .lesson-complete-copy { margin: 8px auto 14px; }
  .lesson-result { padding-block: 10px; }
}

@keyframes lesson-combo-rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes lesson-progress-fill { from { width: var(--lesson-progress-from); } to { width: var(--lesson-progress-to); } }
@keyframes lesson-progress-settle { 0% { filter: brightness(1); } 35% { filter: brightness(1.18); } 100% { filter: brightness(1); } }
@keyframes lesson-result-enter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@media (max-width: 479px) {
  .lesson-topline { margin-bottom: 16px; gap: 12px; }
  .lesson-heading { margin-bottom: 25px; }
  .lesson-keyboard .key.white { font-size: 9px; }
  .lesson-choices { gap: 8px; margin-top: 23px; }
  .lesson-choice { min-height: 74px; }
  .lesson-complete-actions { flex-direction: column; }
  .lesson-complete-actions > button { width: 100%; }
}
@media (max-height: 650px) {
  .lesson-task { padding-bottom: 0; }
  .lesson-topline { margin-bottom: 10px; }
  .lesson-heading { margin-bottom: 21px; }
  .lesson-choices { margin-top: 21px; }
  .lesson-choice { min-height: 68px; }
  .lesson-feedback-slot { min-height: 94px; flex-basis: 94px; }
  .lesson-result-panel { padding-top: 16px; }
  .lesson-continue { margin-top: 14px; }
}
@media (max-height: 499px) {
  .lesson-shell { height: auto; min-height: 460px; }
  .lesson-task { flex: none; padding-bottom: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .lesson-complete-mark svg, .lesson-complete-mark path { animation: none; filter: none; }
  .lesson-progress span, .lesson-choice, .lesson-primary, .lesson-combo-show, .lesson-result-panel { transition: none; animation: none; }
}


/* Retry information is announced without displaying explanatory tip panels. */
/* Preserve the same instrument-to-Submit gap before and after a retry. */
.lesson-feedback.lesson-feedback-quiet {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
