.bba .sentence,
.bba .translation { font-size: .72em; }
.bba .translation { opacity: 0; transition: opacity .14s ease; }
.bba .translation.shown { opacity: 1; }
.sync-word {
  display: inline-block;
  transform-origin: center bottom;
  transition: transform .16s ease-out, color .16s ease-out;
  will-change: transform;
}
.sync-word.word-pop,
.pron-spell span.word-pop {
  color: #ffdf24;
  animation: wordRise .32s ease-out forwards;
  text-shadow: 0 3px 10px rgba(255,184,0,.45);
}
@keyframes wordRise {
  0% { transform: scale(1) translateY(0); }
  52% { transform: scale(1.32) translateY(-5px); }
  100% { transform: scale(1.18) translateY(-2px); }
}
@media (max-width: 700px) {
  .bba .sentence,
  .bba .translation { font-size: 25px; }
}

.scene.pretest-scene {
  background: radial-gradient(circle at 50% 25%, #f8fbff 0, #edf4ff 48%, #e5efff 100%);
  color: #26334a;
}
.pretest-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 6px 15px;
  border: 1px solid rgba(65,118,220,.24);
  border-radius: 999px;
  background: #fff;
  color: #3971d5;
  box-shadow: 0 4px 16px rgba(45,93,180,.1);
  font-size: 14px;
  font-weight: 700;
}
.pretest-gate h1 { margin: 18px 0 7px; font-size: clamp(30px, 4vw, 48px); }
.pretest-gate > p { margin: 0 0 18px; color: #63718a; font-size: clamp(16px, 1.8vw, 21px); }
.pretest-route {
  display: flex;
  width: min(620px, 92vw);
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 12px auto 22px;
  padding: 12px 18px;
  border-radius: 14px;
  background: rgba(255,255,255,.72);
  color: #8a94a7;
  box-shadow: 0 7px 24px rgba(45,82,150,.08);
}
.pretest-route b { color: #3971d5; }
.pretest-route i { color: #a9b4c7; font-style: normal; }
.pretest-mini-card {
  display: grid;
  width: min(300px, 82vw);
  min-height: 130px;
  margin: 0 auto 20px;
  place-items: center;
  align-content: center;
  gap: 7px;
  overflow: hidden;
  border: 2px solid #bdd1f6;
  border-radius: 17px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(46,89,170,.12);
}
.pretest-mini-card img { width: 100%; height: 105px; object-fit: cover; }
.pretest-mini-card b { font-size: clamp(24px, 3vw, 36px); }
.pretest-mini-card img + b { padding-top: 4px; font-size: 18px; }
.pretest-mini-card span { padding: 0 10px 10px; color: #8490a5; font-size: 12px; }
.pretest-start {
  min-width: 190px;
  padding: 14px 28px;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(135deg,#5389ea,#366bcf);
  color: #fff;
  box-shadow: 0 8px 20px rgba(54,107,207,.25);
  font-weight: 700;
}
.pretest-result-icon {
  display: grid;
  width: 74px;
  height: 74px;
  margin: 22px auto 10px;
  place-items: center;
  border-radius: 50%;
  background: #fff2df;
  color: #ff9818;
  box-shadow: 0 7px 22px rgba(255,152,24,.18);
  font-size: 42px;
  font-weight: 800;
}
.pretest-result h1 { margin: 8px 0; color: #ff8c11; }
.pretest-result > p { color: #59677d; font-size: 19px; }
.pretest-added { display: block; margin: 15px 0 7px; color: #ff8c11; font-size: 20px; }
.pretest-result small { display: block; color: #8b96a8; }
.result-route b { color: #ff8c11; }
.pretest-question .sound-word { margin-top: 16px; color: #26334a; }
.pretest-pron { color: #26334a; }
.pretest-pron .pretest-word { margin: 28px 0; color: #26334a; text-shadow: none; }
.pretest-pron .pron-tools button { background: rgba(57,113,213,.13); color: #3971d5; }
.pretest-pron .note { color: #6e7d95; }
.pretest-choices { gap: 9px; margin-top: 15px; }
.pretest-choices .choice { height: 52px; }
.pretest-choices .none-choice { border-color: #7ea7ee; color: #3971d5; font-weight: 700; }
.pretest-anti-guess { margin-top: -8px; color: #7a879c; font-size: 12px; }
.pretest-picture {
  width: 120px;
  height: 80px;
  margin: 10px auto 0;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,.55);
  border-radius: 12px;
}
.pretest-picture img { width: 100%; height: 100%; object-fit: cover; }
.pretest-canvas { border-top: 3px solid #79a4ef; }
@media (max-width: 700px) {
  .pretest-route { gap: 6px; padding: 9px 8px; font-size: 11px; }
  .pretest-mini-card { min-height: 105px; margin-bottom: 12px; }
  .pretest-mini-card img { height: 74px; }
  .pretest-gate h1 { margin: 10px 0 4px; }
  .pretest-gate > p { margin-bottom: 10px; font-size: 14px; }
  .pretest-result-icon { width: 58px; height: 58px; margin-top: 14px; font-size: 32px; }
  .pretest-result > p { font-size: 15px; }
  .pretest-picture { width: 96px; height: 62px; margin-top: 5px; }
  .pretest-pron .pretest-word { margin: 22px 0; }
  .pretest-choices { gap: 6px; margin-top: 8px; }
  .pretest-choices .choice { height: 43px; }
  .pretest-anti-guess { margin-top: -3px; font-size: 10px; }
}

.speaking-deck-content { width: min(1040px, 96vw); }
.deck-table {
  display: grid;
  grid-template-columns: repeat(5,minmax(0,1fr));
  gap: clamp(10px,1.6vw,22px);
  margin: 22px auto 18px;
  perspective: 1000px;
}
.speech-card {
  display: grid;
  min-width: 0;
  height: clamp(135px,24vh,220px);
  grid-template-rows: 1fr auto;
  overflow: hidden;
  border: 2px solid #ddd;
  border-radius: 15px;
  background: #fff;
  box-shadow: 0 6px 0 #d0d0d0,0 10px 22px rgba(0,0,0,.08);
  opacity: 0;
  transform: translate(-45vw,-25vh) rotate(-18deg) scale(.55);
  animation: dealSpeechCard .46s cubic-bezier(.2,.8,.25,1) var(--deal) forwards;
  transition: border-color .22s,box-shadow .22s,transform .22s,opacity .22s;
}
.speech-card img { width: 100%; height: 100%; min-height: 0; object-fit: cover; }
.speech-card span {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  padding: 7px 5px;
  color: #333;
  font-size: clamp(12px,1.35vw,18px);
  line-height: 1.25;
}
.speech-card.current-card {
  border-color: #ff9e18;
  box-shadow: 0 6px 0 #ff9e18,0 0 22px rgba(255,158,24,.3);
  transform: translateY(-8px) scale(1.04);
}
.speech-card.card-done { border-color: #82d718; box-shadow: 0 5px 0 #82d718; opacity: .58; }
@keyframes dealSpeechCard { to { opacity: 1; transform: translate(0,0) rotate(0) scale(1); } }
.speech-control { min-height: 125px; display: grid; place-items: center; }
.speech-control .score { color: #655785; }
.speech-control .speech-zone { margin-top: 0; width: min(390px,82vw); }
.auto-pass {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  border-radius: 999px;
  background: #eefae5;
  color: #5caa1e;
  animation: comboPop .35s ease;
}
.auto-pass b { font-size: 20px; }
.deck-shuffle {
  position: absolute;
  z-index: 70;
  inset: 0;
  display: grid;
  place-content: center;
  background: rgba(30,24,45,.58);
  color: #fff;
  text-align: center;
  backdrop-filter: blur(4px);
}
.deck-shuffle div { font-size: clamp(50px,9vw,96px); font-weight: 900; animation: comboPop .6s ease; }
.deck-shuffle span { margin-top: 8px; font-size: 20px; }
@media (max-width:700px) {
  .speaking-deck-content { width: 100%; }
  .deck-table { gap: 5px; margin: 12px auto 10px; }
  .speech-card { height: clamp(102px,18vh,140px); border-radius: 9px; border-width: 1.5px; box-shadow: 0 3px 0 #d0d0d0; }
  .speech-card span { min-height: 39px; padding: 4px 2px; font-size: clamp(9px,2.7vw,12px); }
  .speech-card.current-card { box-shadow: 0 3px 0 #ff9e18,0 0 14px rgba(255,158,24,.28); transform: translateY(-4px) scale(1.03); }
  .speech-control { min-height: 105px; }
  .speaking-deck-content .note { font-size: 10px; }
}

.hud .bar { position: relative; overflow: visible; }
.hud .bar > i { position: relative; z-index: 1; }
.stage-points { position: absolute; z-index: 3; inset: 0; pointer-events: none; }
.stage-point {
  position: absolute;
  top: 50%;
  left: var(--point);
  width: 18px;
  height: 18px;
  transform: translate(-50%,-50%);
  border: 3px solid #c8c8c8;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.12);
  transition: border-color .25s,background .25s,box-shadow .25s,transform .25s;
}
.stage-point em {
  position: absolute;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  color: #8c8c8c;
  font-size: 11px;
  font-style: normal;
  font-weight: 600;
  white-space: nowrap;
}
.stage-point b {
  position: absolute;
  inset: -3px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font-size: 12px;
  opacity: 0;
}
.stage-point.current {
  border-color: var(--accent,var(--orange));
  box-shadow: 0 0 0 5px color-mix(in srgb,var(--accent,var(--orange)) 18%,transparent),0 2px 7px rgba(0,0,0,.12);
}
.stage-point.current em { color: #625777; }
.stage-point.done { border-color: #74ce20; background: #74ce20; }
.stage-point.done em { color: #55a412; }
.stage-point.done b { opacity: 1; }
.stage-point.completing { animation: stagePointLift .75s cubic-bezier(.2,.85,.25,1); }
.stage-point.completing b { animation: stageCheckRise .72s cubic-bezier(.2,.85,.25,1); }
.stage-point.completing:after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 5px;
  height: 5px;
  transform: translate(-50%,-50%);
  border-radius: 50%;
  animation: stageBurst .72s ease-out;
}
@keyframes stagePointLift { 0%,100%{transform:translate(-50%,-50%)} 42%{transform:translate(-50%,-145%) scale(1.28)} }
@keyframes stageCheckRise { 0%{opacity:0;transform:translateY(14px) scale(.3)} 48%{opacity:1;transform:translateY(-5px) scale(1.35)} 100%{opacity:1;transform:none} }
@keyframes stageBurst {
  0% { box-shadow: 0 0 #ffcc26,0 0 #74ce20,0 0 #ff8f1f,0 0 #74ce20; opacity:1; }
  100% { box-shadow: -24px -18px #ffcc2600,24px -17px #74ce2000,-22px 19px #ff8f1f00,23px 20px #74ce2000; opacity:0; }
}
@media(max-width:700px){
  .stage-point { width: 15px; height: 15px; border-width: 2px; }
  .stage-point em { display: none; }
  .stage-point b { inset: -2px; font-size: 10px; }
}

.match-content { width: min(1120px, 96vw); }
.match-instruction {
  margin: 4px 0 22px;
  color: #555;
  font-size: 16px;
}
.match-instruction small {
  display: block;
  margin-top: 5px;
  color: #999;
  font-size: 11px;
}
.match-board { position: relative; width: 100%; }
.match-row {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: clamp(10px, 1.7vw, 24px);
}
.meaning-row { margin-top: clamp(58px, 8vh, 88px); }
.match-card {
  min-width: 0;
  overflow: hidden;
  border: 2px solid #d6d6d6;
  border-radius: 15px;
  background: #fff;
  color: #2d2d2d;
  box-shadow: 0 5px 0 #d0d0d0;
  transition: border-color .25s ease, box-shadow .25s ease, transform .25s ease, opacity .25s ease;
}
.sound-card,
.word-match-card {
  display: flex;
  height: clamp(78px, 14vh, 145px);
  align-items: center;
  justify-content: center;
}
.sound-card:disabled { cursor: default; opacity: 1; }
.sound-card span { color: #ffa515; font-size: clamp(30px, 4vw, 52px); filter: saturate(1.2); }
.word-match-card strong { font-size: clamp(18px, 2.1vw, 31px); }
.match-card.target-source {
  border-color: #ff9e18;
  box-shadow: 0 5px 0 #ff9e18, 0 0 0 3px rgba(255,158,24,.1);
}
.meaning-card {
  display: grid;
  height: clamp(130px, 24vh, 220px);
  grid-template-rows: 1fr auto;
  padding: 0;
}
.meaning-card img { width: 100%; height: 100%; min-height: 0; object-fit: cover; }
.meaning-card span {
  display: flex;
  min-height: 45px;
  align-items: center;
  justify-content: center;
  padding: 7px 5px;
  background: #fff;
  font-size: clamp(12px, 1.35vw, 18px);
  line-height: 1.25;
}
.match-card.paired {
  border-color: #78d323;
  box-shadow: 0 5px 0 #78d323, 0 0 18px rgba(120,211,35,.22);
  transform: translateY(-3px);
}
.match-card.match-wrong { animation: letterReject .32s ease; border-color: #ff6864; }
.match-lines {
  position: absolute;
  z-index: 1;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}
.match-line {
  stroke: #82d718;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 1000;
  stroke-dashoffset: 1000;
  filter: drop-shadow(0 2px 3px rgba(80,160,10,.2));
  animation: matchLineDraw .5s ease forwards;
}
@keyframes matchLineDraw { to { stroke-dashoffset: 0; } }
@media (max-width: 700px) {
  .match-content { width: 100%; }
  .match-content .title { margin-bottom: 3px; }
  .match-instruction { margin: 2px 0 12px; font-size: 13px; }
  .match-row { gap: 6px; }
  .meaning-row { margin-top: clamp(38px, 6vh, 54px); }
  .match-card { border-radius: 9px; border-width: 1.5px; box-shadow: 0 3px 0 #d0d0d0; }
  .sound-card, .word-match-card { height: clamp(58px, 9.5vh, 78px); }
  .sound-card span { font-size: 27px; }
  .word-match-card strong { font-size: clamp(11px, 3.4vw, 15px); }
  .meaning-card { height: clamp(105px, 18vh, 145px); }
  .meaning-card span { min-height: 38px; padding: 4px 2px; font-size: clamp(9px, 2.7vw, 12px); }
  .match-card.paired { box-shadow: 0 3px 0 #78d323; transform: translateY(-2px); }
  .match-line { stroke-width: 3; }
}

.speech-zone {
  width: min(410px, 86vw);
  margin: 18px auto 6px;
}
.zone-labels {
  display: grid;
  grid-template-columns: 60% 40%;
  color: #999;
  font-size: 14px;
  font-weight: 700;
}
.timed-mic {
  position: relative;
  width: 100%;
  height: 82px;
  padding: 0;
  overflow: hidden;
  border: 3px solid #8065dc;
  border-radius: 14px;
  background: transparent;
  box-shadow: 0 8px 22px rgba(0,0,0,.14);
}
.yellow-zone,.green-zone {
  position: absolute;
  inset-block: 0;
}
.yellow-zone { left: 0; width: 60%; background: linear-gradient(90deg,#ffe68c,#ffd43b); }
.green-zone { right: 0; width: 40%; background: linear-gradient(90deg,#9cdf28,#6fcf16); }
.time-cursor {
  position: absolute;
  z-index: 3;
  top: 0;
  bottom: 0;
  left: 0;
  width: 5px;
  border-radius: 5px;
  background: #fff;
  box-shadow: 0 0 13px 4px rgba(255,255,255,.9);
}
.wave-bars {
  position: relative;
  z-index: 2;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.wave-bars i {
  display: block;
  width: 7px;
  height: 18px;
  border-radius: 8px;
  background: #fff;
  animation: speechWave .42s infinite alternate;
}
.wave-bars i:nth-child(2n) { animation-delay: .14s; }
.wave-bars i:nth-child(3n) { animation-delay: .28s; }
@keyframes speechWave { to { height: 52px; } }
.combo-effect {
  position: absolute;
  z-index: 70;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  color: #ffbe16;
  font-size: clamp(48px, 8vw, 106px);
  font-weight: 1000;
  font-style: italic;
  text-shadow: 0 5px 0 #fff,0 9px 25px rgba(255,153,0,.75);
  animation: comboPop .85s both;
}
.combo-effect b { color: #ff7d17; }
@keyframes comboPop {
  0% { opacity: 0; transform: scale(.25) rotate(-7deg); }
  40% { opacity: 1; transform: scale(1.2) rotate(2deg); }
  70% { transform: scale(.96); }
  100% { opacity: 0; transform: scale(1.04); }
}
.combo-3 { animation-duration: 1.9s; }
.screen-flash {
  position: absolute;
  inset: 0;
  background: #fff;
  animation: flashBurst .7s ease-out both;
}
@keyframes flashBurst { 0%,18%{opacity:.95} 9%,30%{opacity:.1} 100%{opacity:0} }
.lightning {
  position: absolute;
  z-index: -1;
  inset: 2% 0 3%;
  width: 100%;
  height: 95%;
  filter: drop-shadow(0 0 12px #fff) drop-shadow(0 0 24px #ffd22e);
}
.lightning path {
  fill: none;
  stroke: #fff72c;
  stroke-width: 25;
  stroke-linejoin: bevel;
  stroke-dasharray: 1100;
  stroke-dashoffset: 1100;
  animation: lightningDraw .34s .08s ease-out forwards;
}
@keyframes lightningDraw { to { stroke-dashoffset: 0; } }
.thunder-shake { animation: thunderShake .55s linear; }
@keyframes thunderShake {
  0%,100%{transform:translate(0)} 15%{transform:translate(-8px,5px)} 30%{transform:translate(7px,-5px)} 45%{transform:translate(-5px,-3px)} 60%{transform:translate(5px,4px)} 80%{transform:translate(-3px,2px)}
}
@media (max-width: 700px) {
  .timed-mic { height: 66px; }
}

.companion-btn {
  display: block;
  margin: 22px auto 8px;
  padding: 15px 30px;
  border: 0;
  border-radius: 9px;
  background: #8b67ef;
  color: #fff;
  font-size: clamp(16px, 1.8vw, 23px);
  font-weight: 700;
  box-shadow: 0 8px 22px rgba(36, 20, 94, .28);
}
.companion-btn:disabled { opacity: .82; }
.sound-word {
  border: 0;
  background: transparent;
  color: #242424;
  font-size: clamp(46px, 7vw, 84px);
  font-weight: 800;
}
.sound-word span { font-size: .45em; color: #aaa; }
.context-help {
  min-height: 76px;
  margin: 12px auto;
  opacity: 0;
  font-size: clamp(19px, 2.2vw, 28px);
  line-height: 1.5;
  transition: opacity .2s ease;
}
.context-help.show { opacity: 1; }
.context-help b { color: #ff9e18; }
.tip-btn {
  position: absolute;
  z-index: 10;
  right: 28px;
  bottom: 24px;
  padding: 12px 20px;
  border: 1px solid #ddd;
  border-radius: 12px;
  background: #fff;
  color: #555;
  box-shadow: 0 5px 18px rgba(0,0,0,.1);
}
.pron-page { color: #fff; }
.pron-page .spellword { margin-bottom: 14px; }
.pron-spell span { display: inline-block; transform-origin: center bottom; }
.pron-spell.whole-pop {
  animation: wholeWordRise .72s cubic-bezier(.2,.82,.25,1);
  transform-origin: center bottom;
}
@keyframes wholeWordRise {
  0%,100% { transform: translateY(0) scale(1); }
  24%,68% { transform: translateY(-12px) scale(1.11); color: #ffdf24; text-shadow: 0 5px 18px rgba(255,223,36,.38); }
}
.pron-tools { display: flex; justify-content: center; margin: 28px 0; }
.pron-tools button {
  width: 68px;
  height: 68px;
  border: 0;
  background: rgba(255,255,255,.18);
  color: #fff;
  font-size: 28px;
}
.pron-tools button:first-child { border-radius: 14px 0 0 14px; }
.pron-tools button:last-child { border-radius: 0 14px 14px 0; }
.pron-start {
  min-width: 360px;
  padding: 17px 34px;
  border: 0;
  border-radius: 10px;
  background: #9a79ef;
  color: #fff;
  font-size: 22px;
}
@media (max-width: 700px) {
  .tip-btn { right: 14px; bottom: 14px; }
  .pron-start { min-width: min(82vw, 360px); }
  .context-help { min-height: 62px; }
}

.inline-speaker {
  border: 0;
  background: rgba(255,255,255,.18);
  color: inherit;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  font-size: 25px;
  vertical-align: middle;
}
.syllable-slots {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 30px;
  margin: 28px auto 12px;
}
.syllable-slots .syll {
  display: inline-flex;
  align-items: flex-end;
  justify-content: center;
  min-width: 180px;
  height: 72px;
  margin: 0;
  padding: 0 10px 5px;
  border: 0;
  border-bottom: 4px solid rgba(255,255,255,.72);
  color: #fff;
  transition: border-color .2s, box-shadow .2s, color .2s;
}
.syllable-slots .active-syll {
  border-bottom-color: #ffdc32;
  box-shadow: 0 8px 8px -7px #ffdc32;
}
.syllable-slots .done-syll {
  border-bottom-color: #76dd22;
  color: #8af02b;
}
.syllable-slots .whole-syll { min-width: 390px; }
.letter-wrong { animation: letterReject .32s ease; background: #ff7772 !important; color: #fff; }
@keyframes letterReject { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-9px)} 55%{transform:translateX(9px)} 80%{transform:translateX(-4px)} }
.writing-head { align-self: flex-start; margin-top: 2vh; }
.canvastray canvas {
  background-color: #fff;
  background-image:
    linear-gradient(#9da2aa,#9da2aa),
    linear-gradient(#c1c5cb,#c1c5cb),
    linear-gradient(#c1c5cb,#c1c5cb),
    linear-gradient(#9da2aa,#9da2aa);
  background-repeat: no-repeat;
  background-size: 100% 2px,100% 2px,100% 2px,100% 2px;
  background-position: 0 0,0 33.333%,0 66.666%,0 100%;
}
.canvastray.write-success {
  box-shadow: 0 -5px 26px rgba(118,221,34,.48);
  outline: 3px solid rgba(118,221,34,.75);
  outline-offset: -3px;
  transition: box-shadow .18s ease, outline-color .18s ease;
}
.canvastray.write-error {
  animation: writingReject .34s ease;
  box-shadow: 0 -5px 24px rgba(255,91,88,.42);
  outline: 3px solid rgba(255,91,88,.72);
  outline-offset: -3px;
}
@keyframes writingReject {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  55% { transform: translateX(7px); }
  80% { transform: translateX(-3px); }
}
.handwriting-note { margin-right: auto; align-self: center; color: #8b8f96; font-size: 12px; }
@media (max-width: 700px) {
  .syllable-slots { gap: 16px; }
  .syllable-slots .syll { min-width: 120px; height: 56px; }
  .syllable-slots .whole-syll { min-width: 270px; }
  .handwriting-note { display: none; }
}

/* Phone portrait: retain the desktop composition while fitting every control
   inside the visual viewport (including Safari's changing address bar). */
@media (max-width: 700px) {
  html, body, #app, .app { height: 100%; height: 100dvh; min-height: 0; }
  .hud {
    left: 12px;
    right: 12px;
    top: max(8px, env(safe-area-inset-top));
    height: 38px;
  }
  .scene {
    min-height: 0;
    padding: calc(54px + env(safe-area-inset-top)) 14px calc(12px + env(safe-area-inset-bottom));
  }
  .content { width: 100%; max-height: 100%; }
  .title { margin: 4px 0 8px; font-size: clamp(19px, 5.5vw, 25px); }
  .zh { font-size: clamp(18px, 5.6vw, 25px); line-height: 1.3; }
  .cards { margin: 14px auto; }
  .wordcard { width: min(138px, 39vw); border-width: 3px; }
  .wordcard img { height: min(94px, 14vh); }
  .wordcard div { padding: 8px 5px; font-size: 14px; }
  .stars { font-size: 40px; }

  .bba { font-size: clamp(27px, 9.2vw, 36px); line-height: 1.3; }
  .bba .sentence { font-size: .66em; }
  .companion-btn { margin-top: 12px; max-width: 94vw; }
  .score { height: 27px; font-size: 17px; }
  .note { max-width: 94vw; margin-inline: auto; line-height: 1.35; }

  .meaning-screen .title { margin-bottom: 2px; }
  .sound-word { font-size: clamp(38px, 13vw, 54px); }
  .context-help { min-height: 50px; margin: 4px auto; font-size: 16px; line-height: 1.35; }
  .choices { gap: 8px; width: min(94vw, 500px); margin: 8px auto 42px; }
  .choice { height: 48px; font-size: 16px; }
  .tip-btn { padding: 9px 14px; }

  .pron-page .spellword { margin-bottom: 6px; }
  .pron-tools { margin: 15px 0; }
  .pron-tools button { width: 58px; height: 54px; }
  .pron-start { padding: 13px 18px; font-size: 17px; }

  .speech-zone { margin-top: 8px; }
  .timed-mic { max-width: 94vw; }

  .syllable-slots {
    width: min(92vw, 430px);
    gap: clamp(12px, 4vw, 20px);
    margin: 16px auto 8px;
  }
  .syllable-slots .syll {
    flex: 1 1 0;
    min-width: 0;
    max-width: 190px;
    height: 50px;
    margin: 0;
    padding-inline: 4px;
  }
  .syllable-slots .whole-syll { min-width: 0; max-width: min(82vw, 390px); }
  .letters {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 58px));
    justify-content: center;
    gap: 12px;
    margin-top: 20px;
  }
  .letter { width: 58px; height: 54px; font-size: 27px; border-radius: 11px; }

  .writing-head { align-self: stretch; margin-top: 0; transform: translateY(-3px); }
  .writing-head .syllable-slots { margin-top: 8px; }
  .canvastray {
    height: min(46dvh, 365px);
    min-height: 238px;
    padding: 12px 12px calc(8px + env(safe-area-inset-bottom));
  }
  .canvastray canvas { height: calc(100% - 50px); }
  .canvastray canvas { height: calc(100% - 76px); }
  .canvasactions {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    padding: 6px 0 0;
    gap: 5px 8px;
  }
  .handwriting-note {
    display: block;
    grid-column: 1 / -1;
    width: 100%;
    margin: 0;
    text-align: left;
    font-size: 11px;
    line-height: 1.25;
    color: #777d86;
  }
  .canvasactions .tinybtn:first-of-type { grid-column: 2; }
  .canvasactions .tinybtn:last-of-type { grid-column: 3; }
  .tinybtn { min-height: 38px; padding: 7px 20px; }
}

/* Small/short phones, and a desktop browser window reduced to phone height. */
@media (max-width: 700px) and (max-height: 690px) {
  .scene { padding-top: calc(48px + env(safe-area-inset-top)); }
  .prepare h2 { margin: 4px 0; }
  .cards { margin: 8px auto; }
  .wordcard img { height: 72px; }
  .bba { font-size: clamp(24px, 8.4vw, 31px); line-height: 1.2; }
  .companion-btn { margin-top: 7px; padding-block: 10px; }
  .context-help { min-height: 43px; font-size: 14px; }
  .choices { gap: 6px; margin-top: 5px; }
  .choice { height: 42px; }
  .syllable-slots { margin-top: 8px; }
  .letters { gap: 9px 12px; margin-top: 12px; }
  .letter { height: 48px; }
  .canvastray { height: 47dvh; min-height: 238px; }
}

/* Short landscape windows: keep the handwriting area usable without covering
   the current syllable line. */
@media (orientation: landscape) and (max-height: 560px) {
  .scene { padding-top: 54px; padding-bottom: 8px; }
  .writing-head { margin-top: 0; transform: translateY(-8px); }
  .writing-head .title { margin: 0; font-size: 19px; }
  .writing-head .zh { font-size: 19px; }
  .writing-head .syllable-slots { margin: 3px auto; }
  .canvastray { height: 50%; min-height: 180px; padding: 10px 14px 6px; }
  .canvastray canvas { height: calc(100% - 72px); }
  .letters { margin-top: 14px; }
}

.action-counter {
  position: absolute;
  top: 48px;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 7px;
  transform: translateX(-50%);
  padding: 5px 9px;
  border: 1px solid rgba(120,120,120,.16);
  border-radius: 999px;
  background: rgba(255,255,255,.78);
  box-shadow: 0 3px 12px rgba(0,0,0,.06);
  color: #747474;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}
.action-counter > span { color: #999; font-weight: 500; }
.action-counter b {
  min-width: 38px;
  padding: 4px 6px;
  border-radius: 999px;
  background: rgba(139,103,239,.08);
  color: #67549f;
  text-align: center;
  font-weight: 600;
}
.action-counter b.action-pop { animation: actionCountPop .38s ease; }
#spelling-count {
  display: inline-block;
  min-width: 38px;
  color: #ffdf24;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.action-counter b.active-time {
  min-width: 82px;
  background: rgba(80,80,80,.07);
  color: #60656d;
  font-variant-numeric: tabular-nums;
}
@keyframes actionCountPop {
  0%,100% { transform: scale(1); background: rgba(139,103,239,.08); }
  45% { transform: scale(1.2); background: rgba(255,210,44,.42); color: #7f6200; }
}
@media (max-width: 700px) {
  .action-counter {
    top: 40px;
    gap: 4px;
    padding: 4px 6px;
    font-size: 10px;
  }
  .action-counter > span { display: none; }
  .action-counter b { min-width: 34px; padding: 4px 5px; }
  .action-counter b.active-time { min-width: 70px; }
}
