:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
  color: #17221e;
  background: #f4f0e7;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
.hosted-ear-training .mode-switch { display: none; }
.hosted-single-word .mode-switch,
.hosted-single-word #sentence-mode { display: none !important; }
button, input { font: inherit; }
.container { margin: 0 auto; padding: 12px 0; width: min(1180px, calc(100% - 24px)); }
header { margin-bottom: 18px; }
.eyebrow { color: #28705a; font-weight: 700; letter-spacing: .12em; margin: 0 0 10px; }
h1 { font-size: clamp(2.4rem, 8vw, 4.5rem); letter-spacing: -.055em; line-height: .98; margin: 0; }
.intro { color: #52615b; font-size: 1.08rem; line-height: 1.7; max-width: 630px; }
.mode-switch { background: rgba(255,255,255,.7); border: 1px solid #ded8cc; border-radius: 12px; display: grid; gap: 4px; grid-template-columns: repeat(5, 1fr); padding: 4px; }
.mode-button { background: transparent; border: 0; border-radius: 10px; color: #63706a; cursor: pointer; font-weight: 750; padding: 11px 16px; }
.mode-button.active { background: #28705a; box-shadow: 0 4px 14px rgba(40,112,90,.18); color: white; }
.card { background: rgba(255,255,255,.82); border: 1px solid #ded8cc; border-radius: 16px; box-shadow: 0 8px 24px rgba(50,43,30,.05); margin-top: 12px; padding: 16px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
.section-help { color: #69756f; font-size: .92rem; margin: 0 0 18px; }

#tone-mode { display: grid; gap: 12px; grid-template-columns: minmax(270px, 340px) minmax(0, 1fr); grid-template-rows: auto 1fr; }
#tone-mode[hidden] { display: none; }
#tone-mode > .card { margin-top: 0; }
.tone-controls-card { grid-column: 1; grid-row: 1; margin-top: 12px !important; }
.tone-record-card { grid-column: 1; grid-row: 2; }
.tone-analysis-card { grid-column: 2; grid-row: 1 / span 2; margin-top: 12px !important; }

.tone-selector { display: grid; gap: 8px; grid-template-columns: repeat(2, 1fr); }
.tone-option { cursor: pointer; position: relative; }
.tone-option input { opacity: 0; position: absolute; }
.tone-option span { background: #f5f6f3; border: 1px solid #dce1dc; border-radius: 10px; display: grid; gap: 3px; min-height: 58px; padding: 9px 10px; transition: .16s ease; }
.tone-option strong { font-size: .87rem; }
.tone-option small { color: #69756f; }
.tone-option input:checked + span { background: #e9f3ed; border-color: #28705a; box-shadow: 0 0 0 1px #28705a; }
.tone-option input:focus-visible + span { outline: 3px solid rgba(40,112,90,.25); }
.third-tone-practice { background: #f3f6f4; border-radius: 10px; margin-top: 10px; padding: 9px 10px; }
.third-tone-practice[hidden] { display: none; }
.practice-word-heading { align-items: center; display: flex; font-size: .78rem; justify-content: space-between; }
.reference-play { background: transparent; border: 0; color: #28705a; cursor: pointer; font-size: .76rem; font-weight: 750; padding: 4px 2px; }
.practice-word-selector { display: grid; gap: 6px; grid-template-columns: repeat(3, 1fr); margin-top: 7px; }
.practice-word-option { cursor: pointer; position: relative; }
.practice-word-option input { opacity: 0; position: absolute; }
.practice-word-option span { background: white; border: 1px solid #d7ded9; border-radius: 8px; display: block; font-size: .78rem; padding: 7px 5px; text-align: center; }
.practice-word-option input:checked + span { background: #e2f0e8; border-color: #28705a; color: #204f40; font-weight: 750; }
.practice-word-option input:focus-visible + span { outline: 3px solid rgba(40,112,90,.25); }
.target-description { background: #fbf2e7; border-left: 3px solid #d17b24; color: #75481e; font-size: .82rem; margin: 10px 0 0; padding: 8px 10px; }

.record-controls { display: flex; flex-wrap: wrap; gap: 10px; }
.button { border: 0; border-radius: 9px; cursor: pointer; font-weight: 700; padding: 10px 14px; }
.button:disabled { cursor: not-allowed; opacity: .45; }
.button.primary { background: #28705a; color: white; }
.button.danger { background: #9b3f36; color: white; }
.button.secondary { background: #e7ece9; color: #204f40; }
.status-line, .file-info { color: #69756f; font-size: .82rem; line-height: 1.4; margin: 9px 0 0; }
audio { height: 34px; margin-top: 10px; width: 100%; }

.section-heading { align-items: center; display: flex; justify-content: space-between; }
.section-heading h2 { margin-bottom: 0; }
.badge { background: #e5eee9; border-radius: 999px; color: #28705a; font-size: .75rem; font-weight: 700; padding: 6px 10px; }
.stats { display: grid; gap: 8px; grid-template-columns: repeat(4, 1fr); margin-top: 10px; }
.stats div { background: #f3f6f4; border-radius: 9px; padding: 8px 10px; }
.stats span { color: #69756f; display: block; font-size: .75rem; margin-bottom: 5px; }
.stats strong { font-size: .95rem; }
.legend { display: flex; flex-wrap: wrap; gap: 13px; margin-top: 10px; }
.legend > span { align-items: center; color: #69756f; display: flex; font-size: .78rem; gap: 7px; }
.legend-line { display: inline-block; height: 0; width: 24px; }
.legend-line.raw { border-top: 2px dashed #8c9792; }
.legend-line.smooth { border-top: 3px solid #28705a; }
.legend-line.target { border-top: 3px dashed #d17b24; }
.legend-line.song-reference { border-top: 3px solid #bd2448; }
.legend-line.song-user { border-top: 3px solid #d5a214; }
.relative-note { color: #69756f; font-size: .72rem; margin: 5px 0 0; }
.pitch-chart { background: linear-gradient(180deg, #f8faf8, #edf3ef); border-radius: 12px; height: clamp(245px, 38vh, 330px); margin-top: 8px; overflow: hidden; position: relative; }
.tone-analysis-card:has(#feedback:not([hidden])) .pitch-chart { height: clamp(190px, 29vh, 245px); }
#pitch-canvas, #sentence-pitch-canvas { display: block; height: 100%; width: 100%; }
#chart-message { background: rgba(248,250,248,.88); border-radius: 8px; color: #69756f; font-size: .88rem; left: 50%; margin: 0; padding: 8px 12px; position: absolute; text-align: center; top: 50%; transform: translate(-50%, -50%); width: min(82%, 430px); }

.feedback { background: #edf5f0; border-left: 4px solid #28705a; border-radius: 10px; margin-top: 10px; padding: 10px 12px; }
.feedback[data-status="needs-work"], .feedback[data-status="unstable"] { background: #fbf2e7; border-color: #d17b24; }
.feedback[data-status="insufficient"], .feedback[data-status="uncertain"] { background: #f2f2ef; border-color: #7b847f; }
.feedback-label { color: #28705a; font-size: .68rem; font-weight: 800; letter-spacing: .08em; margin: 0 0 4px; }
.feedback h3 { font-size: .98rem; margin: 0 0 4px; }
.feedback p:not(.feedback-label) { color: #4f5d57; font-size: .83rem; line-height: 1.4; margin: 0; }
.feedback small { display: none; }
details { border-top: 1px solid #e1e4df; margin-top: 9px; padding-top: 8px; }
.tone-analysis-card details { display: none; }
summary { color: #52615b; cursor: pointer; font-size: .88rem; font-weight: 700; }
.details-grid { display: grid; gap: 10px; grid-template-columns: repeat(3, 1fr); margin: 14px 0 0; }
.details-grid div { background: #f5f6f3; border-radius: 9px; padding: 11px; }
.details-grid dt { color: #69756f; font-size: .72rem; }
.details-grid dd { font-size: .9rem; font-weight: 700; margin: 5px 0 0; }

.select-label { color: #52615b; display: block; font-size: .78rem; font-weight: 750; margin-bottom: 7px; }
#sentence-select { appearance: none; background: #f5f6f3 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='m1 1 5 5 5-5' fill='none' stroke='%2352615b' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 14px center; border: 1px solid #cfd8d2; border-radius: 10px; color: #17221e; font-weight: 700; padding: 12px 38px 12px 13px; width: 100%; }
.sentence-prompt { align-items: flex-end; background: #f8f5ec; border-radius: 14px; display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; margin-top: 16px; min-height: 110px; padding: 20px 14px; }
.sentence-reference { align-items: center; background: #edf5f0; border-radius: 10px; display: flex; gap: 10px; margin-top: 10px; padding: 9px 10px; }
.sentence-reference[hidden] { display: none; }
.sentence-reference .button { flex: 0 0 auto; }
.sentence-reference span { color: #52615b; font-size: .78rem; }
.reference-prosody { background: #f8f5ec; border-radius: 10px; margin-top: 10px; padding: 10px; }
.reference-prosody[hidden] { display: none; }
.reference-prosody h3 { color: #75481e; font-size: .82rem; margin: 0 0 5px; }
.reference-prosody p { color: #52615b; font-size: .76rem; line-height: 1.4; margin: 0; }
.reference-prosody small { color: #77817c; display: block; font-size: .65rem; line-height: 1.35; margin-top: 7px; }
.reference-prosody-syllables { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.reference-prosody-chip { background: white; border: 1px solid #ded8cc; border-radius: 8px; display: grid; gap: 2px; min-width: 48px; padding: 5px 6px; text-align: center; }
.reference-prosody-chip strong { font-size: .88rem; }
.reference-prosody-chip span { color: #69756f; font-size: .61rem; }
.reference-prosody-chip.stressed { background: #fff1dc; border-color: #d9a25f; box-shadow: inset 0 -2px #d17b24; }
.prompt-syllable { align-items: center; display: inline-flex; flex-direction: column; min-width: 48px; }
.prompt-syllable small, .aligned-syllable small { color: #69756f; font-size: .75rem; margin-bottom: 4px; }
.prompt-syllable strong { font-size: 1.75rem; font-weight: 650; }
.privacy-note { color: #69756f; font-size: .82rem; line-height: 1.5; margin: 13px 0 0; }
.sentence-alignment { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; min-height: 92px; }
.empty-state { align-self: center; color: #69756f; font-size: .88rem; margin: auto; text-align: center; }
.error-state { color: #963d34; }
.aligned-syllable { align-items: center; background: #f3f5f3; border: 1px solid #d7ded9; border-radius: 10px; display: inline-flex; flex: 1 1 86px; flex-direction: column; min-width: 78px; padding: 10px 7px 8px; }
.aligned-syllable strong { font-size: 1.5rem; }
.aligned-syllable em { color: #77817c; font-size: .66rem; font-style: normal; margin-top: 5px; text-align: center; }
.aligned-syllable.recognized { border-color: #8db9aa; }
.aligned-syllable.estimated { background: #f5f1ea; border-style: dashed; }
.aligned-syllable.pitch-match { box-shadow: inset 0 -3px #28705a; }
.aligned-syllable.pitch-review { box-shadow: inset 0 -3px #d17b24; }
.aligned-syllable.pitch-unknown, .aligned-syllable.pitch-neutral { box-shadow: inset 0 -3px #aeb6b1; }
.transcript-panel { background: #f5f6f3; border-radius: 12px; display: grid; gap: 1px; grid-template-columns: 1fr 1fr 130px; margin-top: 16px; overflow: hidden; }
.transcript-panel[hidden] { display: none; }
.transcript-panel div { background: rgba(255,255,255,.55); padding: 11px 12px; }
.transcript-panel span { color: #69756f; display: block; font-size: .7rem; margin-bottom: 5px; }
.transcript-panel strong { font-size: .88rem; line-height: 1.4; }
.sentence-chart { height: 380px; }

#pitch-training-mode { display: grid; gap: 12px; grid-template-columns: minmax(290px, 380px) minmax(0, 1fr); }
#pitch-training-mode[hidden] { display: none; }
#pitch-training-mode > .card { margin-top: 12px; }
.training-levels { display: grid; gap: 7px; grid-template-columns: repeat(3, 1fr); }
.training-levels label { cursor: pointer; position: relative; }
.training-levels input { opacity: 0; position: absolute; }
.training-levels span { align-items: center; background: #f5f6f3; border: 1px solid #dce1dc; border-radius: 9px; display: flex; font-size: .8rem; font-weight: 750; justify-content: center; min-height: 48px; padding: 7px; text-align: center; }
.training-levels input:checked + span { background: #e9f3ed; border-color: #28705a; box-shadow: 0 0 0 1px #28705a; color: #204f40; }
.training-levels input:focus-visible + span { outline: 3px solid rgba(40,112,90,.25); }
.pitch-range-label { margin-top: 16px; }
#pitch-range { appearance: none; background: #f5f6f3; border: 1px solid #cfd8d2; border-radius: 9px; color: #17221e; padding: 10px 12px; width: 100%; }
.target-notes { background: #f8f5ec; border-radius: 12px; margin-top: 14px; padding: 12px; text-align: center; }
.target-notes > span { color: #69756f; display: block; font-size: .72rem; margin-bottom: 8px; }
#pitch-target-notes { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; }
.target-note { align-items: center; background: white; border: 1px solid #d8ded9; border-radius: 9px; color: #52615b; display: inline-flex; font-size: 1.08rem; font-weight: 800; height: 44px; justify-content: center; min-width: 52px; padding: 0 9px; }
.target-note.current { background: #28705a; border-color: #28705a; color: white; }
.target-note.passed { background: #dcebe3; border-color: #8db9aa; color: #205d4b; }
.pitch-training-actions { margin-top: 14px; }
#pitch-training-status { min-height: 3.5em; }
.live-pitch-readout { display: grid; gap: 8px; grid-template-columns: repeat(3, 1fr); margin-top: 14px; }
.live-pitch-readout > div { background: #f3f6f4; border-radius: 10px; padding: 11px; }
.live-pitch-readout span { color: #69756f; display: block; font-size: .72rem; margin-bottom: 5px; }
.live-pitch-readout strong { display: block; font-size: 1.1rem; min-height: 1.3em; white-space: nowrap; }
.tuning-meter { background: linear-gradient(90deg, #edf0ee, #e6eee9 37%, #cbe4d5 45%, #cbe4d5 55%, #e6eee9 63%, #edf0ee); border-radius: 999px; height: 46px; margin: 16px 4px 0; overflow: hidden; position: relative; }
.tuning-center { background: rgba(40,112,90,.55); height: 100%; left: 50%; position: absolute; top: 0; width: 2px; }
.tuning-zone { border-left: 1px dashed rgba(40,112,90,.5); border-right: 1px dashed rgba(40,112,90,.5); height: 100%; left: 41.25%; position: absolute; top: 0; width: 17.5%; }
.tuning-needle { background: #9b3f36; border-radius: 3px; box-shadow: 0 1px 4px rgba(0,0,0,.18); height: 30px; left: 50%; position: absolute; top: 8px; transform: translateX(-50%); width: 4px; }
.tuning-needle.in-tune { background: #28705a; }
.meter-low, .meter-high { color: #69756f; font-size: .68rem; position: absolute; top: 16px; }
.meter-low { left: 12px; }
.meter-high { right: 12px; }
.pitch-live-message { align-items: center; display: flex; font-size: 1rem; font-weight: 750; justify-content: center; line-height: 1.35; margin: 13px 0 0; min-height: 2.7em; text-align: center; }
.pitch-training-chart { background: #f7faf8; border-radius: 11px; height: 190px; margin-top: 12px; overflow: hidden; }
#pitch-training-canvas { display: block; height: 100%; width: 100%; }

#ear-training-mode { display: grid; gap: 12px; grid-template-columns: minmax(320px, 1.2fr) minmax(280px, .8fr); }
#ear-training-mode[hidden] { display: none; }
#ear-training-mode > .card { margin-top: 12px; }
.ear-stats { display: grid; gap: 8px; grid-template-columns: 1.5fr 1fr 1fr; }
.ear-stats > div { background: #f3f6f4; border-radius: 10px; padding: 10px; }
.ear-stats span { color: #69756f; display: block; font-size: .7rem; margin-bottom: 5px; }
.ear-stats strong { display: block; font-size: .9rem; }
.ear-learning { background: #f8f5ec; border: 1px solid #e9dfc9; border-radius: 13px; margin-top: 13px; padding: 11px 13px; }
.ear-learning summary { color: #704717; cursor: pointer; font-size: .92rem; font-weight: 800; }
.ear-learning > p { color: #68736e; font-size: .78rem; line-height: 1.45; margin: 8px 0; }
.ear-reference-directions { display: grid; gap: 7px; grid-template-columns: 1fr 1fr; margin: 9px 0; }
.ear-reference-directions label { cursor: pointer; }
.ear-reference-directions input { position: absolute; opacity: 0; pointer-events: none; }
.ear-reference-directions span { background: #fffdf8; border: 1px solid #d9d8cf; border-radius: 9px; display: block; font-size: .78rem; font-weight: 750; padding: 8px; text-align: center; }
.ear-reference-directions input:checked + span { background: #e4f0e9; border-color: #28705a; color: #205d4b; }
.ear-reference-grid { display: grid; gap: 7px; grid-template-columns: repeat(5, minmax(0, 1fr)); }
.ear-reference-button { background: #fffdf8; border: 1px solid #d9d8cf; border-radius: 9px; color: #304039; cursor: pointer; min-height: 58px; padding: 7px 5px; }
.ear-reference-button strong, .ear-reference-button span { display: block; }
.ear-reference-button strong { font-size: .78rem; }
.ear-reference-button span { color: #6d7872; font-size: .62rem; line-height: 1.3; margin-top: 3px; }
.ear-reference-button:hover:not(:disabled), .ear-reference-button:focus-visible { border-color: #28705a; }
.ear-reference-button.playing { background: #e4f0e9; border-color: #28705a; }
.ear-reference-button:disabled { cursor: default; opacity: .62; }
.ear-reference-status { min-height: 1.2em; }
.ear-question { align-items: center; background: #f8f5ec; border-radius: 13px; display: flex; gap: 12px; justify-content: space-between; margin-top: 14px; padding: 14px; }
.ear-question p { font-size: 1rem; font-weight: 750; line-height: 1.4; margin: 0; }
.ear-question .button { flex: 0 0 auto; }
.ear-answers { display: grid; gap: 9px; grid-template-columns: repeat(2, 1fr); margin-top: 12px; }
.ear-answer { background: #f5f6f3; border: 1px solid #d7ded9; border-radius: 10px; color: #26342e; cursor: pointer; font-weight: 750; min-height: 54px; padding: 10px; }
.ear-answer:hover:not(:disabled), .ear-answer:focus-visible { border-color: #28705a; }
.ear-answer.correct { background: #dcebe3; border-color: #28705a; color: #205d4b; }
.ear-answer.wrong { background: #f7e5e1; border-color: #9b3f36; color: #7e312b; }
.ear-answer:disabled { cursor: default; opacity: 1; }
.ear-feedback { color: #52615b; font-size: .9rem; line-height: 1.5; margin: 12px 0 0; min-height: 2.8em; }
.ear-melody-review { display: grid; gap: 7px; grid-template-columns: repeat(3, 1fr); margin-top: 9px; }
.ear-melody-review[hidden] { display: none; }
.ear-melody-review .button { font-size: .75rem; min-height: 44px; padding: 8px; }
.ear-summary { background: #edf5f0; border-left: 4px solid #28705a; border-radius: 10px; color: #204f40; font-weight: 750; line-height: 1.5; padding: 11px 12px; }
.ear-actions { margin-top: 10px; }
.ear-actions .button { flex: 1 1 44%; }
.ear-route { display: grid; gap: 10px; list-style: none; margin: 0; padding: 0; }
.ear-route-item { background: #f3f5f3; border: 1px solid #dce1dc; border-radius: 11px; color: #69756f; display: grid; gap: 4px; padding: 12px 13px; }
.ear-route-item strong { color: #52615b; font-size: .9rem; }
.ear-route-item span { font-size: .78rem; line-height: 1.45; }
.ear-route-item.active { background: #e9f3ed; border-color: #28705a; box-shadow: inset 3px 0 #28705a; }
.ear-route-item.active strong { color: #204f40; }
.ear-route-item.complete { background: #edf5f0; opacity: .78; }
.ear-tip { background: #fbf2e7; border-radius: 10px; color: #75481e; margin-top: 13px; padding: 11px 12px; }
.ear-tip strong { font-size: .82rem; }
.ear-tip p { font-size: .78rem; line-height: 1.5; margin: 5px 0 0; }

#song-mode { display: grid; gap: 12px; grid-template-columns: minmax(300px, 390px) minmax(0, 1fr); }
#song-mode[hidden] { display: none; }
#song-mode > .card { margin-top: 12px; }
.song-name { color: #75481e; font-size: 1.05rem; font-weight: 800; margin: 12px 0 5px; }
.song-segments { display: grid; gap: 6px; grid-template-columns: repeat(5, 1fr); }
.song-segment { background: #f5f6f3; border: 1px solid #d7ded9; border-radius: 8px; color: #52615b; cursor: pointer; font-size: .74rem; font-weight: 750; min-height: 38px; padding: 6px; }
.song-segment.active { background: #28705a; border-color: #28705a; color: white; }
.song-current-lyric { align-items: center; background: #f8f5ec; border-radius: 12px; display: flex; flex-wrap: wrap; font-size: 1.18rem; font-weight: 700; gap: 1px; justify-content: center; line-height: 1.8; margin-top: 10px; min-height: 78px; padding: 12px; }
.song-lyric-line { display: block; flex-basis: 100%; text-align: center; }
.song-current-lyric span { border-radius: 4px; padding: 0 1px; }
.song-current-lyric span.active { background: #f8d6a0; color: #7f3d16; }
.song-mixer { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; margin-top: 12px; }
.song-mixer label { color: #52615b; font-size: .74rem; font-weight: 700; }
.song-mixer span { display: block; margin-bottom: 5px; }
.song-mixer input { accent-color: #28705a; width: 100%; }
.song-playback-actions, .song-practice-actions { margin-top: 11px; }
.song-playback-actions .button { flex: 1 1 40%; }
.song-playback-actions .button.preferred { box-shadow: inset 0 0 0 2px #28705a; }
.song-practice-actions .button { flex: 1 1 45%; }
.song-user-recording { background: #f3f6f4; border-radius: 10px; margin-top: 10px; padding: 9px 10px 10px; }
.song-user-recording[hidden] { display: none; }
.song-user-recording strong { color: #204f40; display: block; font-size: .78rem; }
.song-user-recording small { color: #69756f; display: block; font-size: .7rem; margin-top: 9px; }
.song-user-recording audio { margin-top: 7px; }
.song-legend { margin-top: 14px; }
.song-pitch-chart { background: #111514; border-radius: 12px; height: clamp(360px, 58vh, 560px); margin-top: 8px; overflow: hidden; position: relative; }
.song-pitch-scroll { -webkit-overflow-scrolling: touch; height: 100%; overflow-x: auto; overflow-y: hidden; scrollbar-color: #63706a #202522; scrollbar-width: thin; }
.song-pitch-scroll.auto-follow { -webkit-overflow-scrolling: auto; overflow-anchor: none; }
#song-pitch-canvas { display: block; height: 100%; min-width: 100%; }
#song-pitch-axis { background: linear-gradient(90deg, #111514 78%, rgba(17,21,20,.12)); height: 100%; left: 0; pointer-events: none; position: absolute; top: 0; width: 48px; z-index: 2; }
#song-chart-message { background: rgba(17,21,20,.84); border-radius: 8px; color: #dce4df; left: 50%; margin: 0; padding: 9px 12px; position: absolute; text-align: center; top: 50%; transform: translate(-50%, -50%); width: min(82%, 430px); }

@media (max-width: 680px) {
  .mode-button { font-size: .82rem; padding: 10px 6px; }
  .tone-selector { grid-template-columns: repeat(2, 1fr); }
  .pitch-chart { height: 300px; }
  .sentence-chart { height: 350px; }
  .transcript-panel { grid-template-columns: 1fr 1fr; }
  .transcript-panel div:last-child { grid-column: 1 / -1; }
}

@media (max-width: 520px) {
  .container { padding: 10px 0; }
  .mode-switch { grid-template-columns: repeat(2, 1fr); }
  #tone-mode { display: block; }
  .tone-controls-card, .tone-record-card, .tone-analysis-card { margin-top: 12px !important; }
  .card { padding: 19px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .details-grid { grid-template-columns: 1fr; }
  .record-controls .button { flex: 1 1 44%; }
  .prompt-syllable { min-width: 40px; }
  .prompt-syllable strong { font-size: 1.5rem; }
  .aligned-syllable { flex-basis: 70px; min-width: 65px; }
  #pitch-training-mode { display: block; }
  #pitch-training-mode > .card { margin-top: 12px; }
  .training-levels { grid-template-columns: 1fr; }
  .training-levels span { min-height: 40px; }
  .pitch-training-actions .button { flex: 1 1 44%; }
  .live-pitch-readout { grid-template-columns: repeat(3, 1fr); }
  .live-pitch-readout strong { font-size: .9rem; }
  #ear-training-mode { display: block; }
  #ear-training-mode > .card { margin-top: 12px; }
  .ear-stats { grid-template-columns: 1fr 1fr; }
  .ear-stats > div:first-child { grid-column: 1 / -1; }
  .ear-reference-grid { grid-template-columns: repeat(2, 1fr); }
  .ear-reference-button:last-child { grid-column: 1 / -1; }
  .ear-question { align-items: stretch; flex-direction: column; }
  .ear-answers { grid-template-columns: 1fr 1fr; }
  .ear-melody-review { grid-template-columns: 1fr; }
  #song-mode { display: block; }
  #song-mode > .card { margin-top: 12px; }
  .song-segments { grid-template-columns: repeat(5, 1fr); }
  .song-current-lyric { font-size: 1.05rem; min-height: 72px; }
  .song-pitch-chart { height: 410px; }
}
