/* 打字练习 v2 · 键盘、文字与气球 */

.diff-list--four {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}
.diff-list--four .diff { min-height: 76px; padding: 7px 9px; gap: 8px; }
.diff-list--four .diff__mini { width: 30px; height: 30px; border-radius: 8px; }
.diff-list--four .diff__name { font-size: var(--fs-sm); }
.diff-list--four .diff__name small { font-size: 10px; }
.diff-list--four .diff__best { font-size: 10px; }
.diff__mini[data-diff-color="balloon"] { background: var(--sunny) !important; }
.diff[data-difficulty="balloon"] .diff__mini { background: var(--sunny) !important; }

.seg--four { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; }
.seg--four .seg__btn { font-size: var(--fs-xs); padding: 4px 3px; }

.typing-stage {
  width: min(100%, 620px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 1.5vh, 14px);
}
.typing-emoji {
  font-size: clamp(48px, 8vh, 72px);
  line-height: 1;
  filter: drop-shadow(0 4px 0 rgba(90, 74, 58, 0.12));
  transition: transform 0.28s var(--ease-bounce), opacity 0.28s;
}
.typing-emoji.is-fly { transform: translateY(-18px) scale(0.7); opacity: 0; }
.typing-word {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 2px 3px;
  min-height: 66px;
  font-family: var(--font-num);
  font-size: clamp(34px, 5.8vh, 52px);
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--ink);
}
.typing-char {
  display: inline-block;
  min-width: 0.48em;
  padding: 0 3px 2px;
  border-bottom: 4px solid transparent;
  border-radius: 4px;
  line-height: 1.15;
}
.typing-char--space { min-width: 0.75em; color: var(--ink-faint); }
.typing-char--done { color: #4A8A62; border-bottom-color: var(--mint); }
.typing-char--cur { background: var(--sunny); border-bottom-color: var(--ink); }
.typing-char--cur.shake { animation: typingShake 0.35s ease; }
@keyframes typingShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}
.typing-meaning {
  margin: 0;
  font-family: var(--font-hand);
  font-size: var(--fs-sm);
  color: var(--ink-soft);
}
.typing-progress {
  width: min(100%, 520px);
  height: 9px;
  padding: 1.5px;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
}
.typing-progress__bar { width: 0; height: 100%; background: var(--mint); border-radius: 999px; transition: width 0.25s; }

.typing-keyboard {
  width: min(100%, 600px);
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 2px;
}
.typing-kb-row { display: flex; justify-content: center; gap: 4px; }
.typing-key {
  flex: 0 1 46px;
  min-width: 0;
  height: clamp(30px, 4.2vh, 38px);
  padding: 0;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: var(--paper);
  box-shadow: 0 2px 0 var(--paper-deep), 0 3px 0 var(--ink);
  font-family: var(--font-num);
  font-size: clamp(11px, 1.5vh, 14px);
  font-weight: 700;
  color: var(--ink-soft);
  pointer-events: none;
}
.typing-key--space { flex-basis: 180px; }
.typing-key.is-active {
  background: var(--sunny);
  color: var(--ink);
  transform: translateY(1px);
  box-shadow: 0 1px 0 var(--paper-deep), 0 2px 0 var(--ink);
}
.typing-key.is-done { background: var(--mint); color: var(--ink); }

.typing-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-hand);
  font-size: var(--fs-sm);
  color: var(--ink-soft);
  cursor: pointer;
}
.typing-toggle input { width: 17px; height: 17px; accent-color: var(--pumpkin); }
.side-actions--single { grid-template-columns: 1fr !important; }

.balloon-area {
  width: min(100%, 560px);
  height: clamp(360px, 48vh, 460px);
  margin: 0 auto;
  border: 3px solid var(--ink);
  border-radius: var(--r-lg);
  background: linear-gradient(#FBF6EC, #EDF5F8);
  box-shadow: 0 6px 0 var(--paper-deep), 0 8px 0 var(--ink);
  overflow: hidden;
}
.balloon-sky { position: relative; width: 100%; height: 100%; overflow: hidden; }
.balloon {
  position: absolute;
  bottom: 0;
  width: 58px;
  height: 74px;
  will-change: transform;
}
.balloon__body {
  position: relative;
  width: 58px;
  height: 66px;
  border: 2.5px solid var(--ink);
  border-radius: 50% 50% 46% 46%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset -6px -6px 0 rgba(90, 74, 58, 0.08), 0 3px 0 rgba(90, 74, 58, 0.18);
}
.balloon__body::after {
  content: "";
  position: absolute;
  bottom: -7px;
  left: 50%;
  width: 9px;
  height: 8px;
  transform: translateX(-50%);
  background: inherit;
  border: 2px solid var(--ink);
  border-top: 0;
  border-radius: 0 0 5px 5px;
}
.balloon__letter {
  font-family: var(--font-num);
  font-size: 28px;
  font-weight: 800;
  color: var(--ink);
  line-height: 1;
}
.balloon.is-hit { animation: balloonPop 0.3s ease forwards; }
.balloon.is-missed { animation: balloonMiss 0.5s ease forwards; }
@keyframes balloonPop { to { transform: translateY(var(--y, 0)) scale(1.5); opacity: 0; } }
@keyframes balloonMiss { to { opacity: 0; } }

@media (min-width: 900px) {
  .screen--play .stage { justify-content: flex-start; padding-top: 32px; }
  .screen--play .stats { margin-top: 32px; }
}

@media (max-width: 859px) {
  .typing-stage { width: min(100%, 440px); gap: 7px; }
  .typing-emoji { font-size: 48px; }
  .typing-word { font-size: clamp(30px, 6.4vw, 42px); min-height: 54px; }
  .typing-keyboard { width: min(100%, 380px); gap: 4px; }
  .typing-kb-row { gap: 3px; }
  .typing-key { flex-basis: 32px; height: 31px; font-size: 10px; border-width: 1.8px; }
  .typing-key--space { flex-basis: 120px; }
  .balloon-area { width: min(100%, 380px); height: 380px; }
  .balloon { width: 50px; height: 66px; }
  .balloon__body { width: 50px; height: 58px; }
  .balloon__letter { font-size: 24px; }
}

@media (max-width: 380px) {
  .subtitle { display: none; }
  .diff-list--four .diff { min-height: 70px; padding: 6px; }
  .diff-list--four .diff__best { display: none; }
}

/* 气球模式标签：补上黄色填充 */
.seg__btn[data-difficulty="balloon"] { --diff: var(--sunny); }
.chip[data-difficulty="balloon"] { background: var(--sunny); }

/* 标准键盘布局：错位、Shift、空格 */
.typing-kb-row--home { padding: 0 4.2%; }
.typing-kb-row--shift { padding: 0 1%; }
.typing-key--mod {
  flex: 0 0 15%;
  background: var(--paper-warm);
  font-family: var(--font-hand);
  font-size: 9px;
  letter-spacing: 0.02em;
  color: var(--ink-faint);
}
.typing-key--mod.is-left { border-radius: 6px 6px 6px 3px; }
.typing-key--mod.is-right { border-radius: 6px 6px 3px 6px; }
.typing-key--space { flex-basis: 190px; }

/* 气球破碎 */
.balloon-frag {
  position: absolute;
  width: 9px;
  height: 9px;
  border: 1.5px solid var(--ink);
  border-radius: 2px;
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: balloonFrag 0.55s cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}
@keyframes balloonFrag {
  to {
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--rot)) scale(0.35);
    opacity: 0;
  }
}
.balloon-flash {
  position: absolute;
  width: 30px;
  height: 30px;
  border: 3px solid var(--sunny);
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: balloonFlash 0.38s ease-out forwards;
}
@keyframes balloonFlash {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(0.4); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(2.2); }
}
@media (max-width: 859px) {
  .typing-key--mod { flex-basis: 14%; font-size: 8px; }
  .typing-key--space { flex-basis: 130px; }
}

/* 标准键盘外框 + 网格化按键（空白补位统一灰色） */
.typing-keyboard {
  width: min(100%, 620px);
  padding: 9px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: var(--paper-warm);
  box-shadow: 0 4px 0 var(--paper-deep), 0 6px 0 var(--ink);
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.typing-kb-row {
  display: grid;
  grid-template-columns: repeat(22, minmax(0, 1fr));
  gap: 3px;
  width: 100%;
  padding: 0;
}
.typing-kb-row--home, .typing-kb-row--shift { padding: 0; }
.typing-key {
  grid-column: span 2;
  flex: none;
  min-width: 0;
  height: clamp(30px, 4vh, 36px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: var(--paper);
  box-shadow: 0 2px 0 var(--paper-deep), 0 3px 0 var(--ink);
  font-family: var(--font-num);
  font-size: clamp(10px, 1.4vh, 13px);
  font-weight: 700;
  color: var(--ink-soft);
  line-height: 1;
  pointer-events: none;
}
.typing-key--letter { color: var(--ink); }
.typing-key--blank {
  background: var(--paper-deep);
  border-color: transparent;
  box-shadow: none;
  opacity: 0.72;
}
.typing-key--space {
  grid-column: span 14;
  flex: none;
  font-family: var(--font-hand);
  font-size: var(--fs-sm);
  color: var(--ink-soft);
}
.typing-key.is-active {
  background: var(--sunny);
  color: var(--ink);
  border-color: var(--ink);
  box-shadow: 0 1px 0 var(--paper-deep), 0 2px 0 var(--ink);
  transform: translateY(1px);
}
.typing-key.is-done { background: var(--mint); color: var(--ink); }
.typing-key--blank.is-active { background: var(--paper-deep); box-shadow: none; transform: none; }

@media (max-width: 859px) {
  .typing-keyboard { width: min(100%, 390px); padding: 7px; gap: 4px; border-width: 2.5px; }
  .typing-kb-row { gap: 2px; }
  .typing-key { height: 29px; font-size: 10px; border-width: 1.6px; border-radius: 5px; }
  .typing-key--space { font-size: 11px; }
}

/* 极窄屏：压缩纵向间距，给左下角版本号腾出一行 */
@media (max-width: 380px) {
  .screen--start { padding-bottom: 26px; }
  .app-version { left: 8px; bottom: 5px; font-size: 9px; padding: 1px 5px; }
  .setup { gap: 3px; }
  .setup__block { padding: 6px; gap: 4px; }
  .diff-list { gap: 5px; }
  .diff { min-height: 40px; padding: 4px 8px; }
  .diff__name small, .setup__label-note { display: none; }
  .app-title { font-size: clamp(26px, 8vw, 32px); }
  .btn--lg { min-height: 52px; }
  .hero__card { width: min(150px, 44vw); padding: 7px; }
  .hero__caption, .hero__float { display: none; }
  .subtitle { display: none; }
}

/* 极窄屏：难度卡进一步压缩 */
@media (max-width: 340px) {
  .diff { min-height: 40px; padding: 4px 8px; gap: 8px; }
  .diff__mini { width: 26px; height: 26px; border-radius: 7px; }
  .diff__name { font-size: var(--fs-sm); }
  .diff__best { font-size: 10px; }
}
