/* =========================================================
 * 音标小冒险 · 全局样式
 * 原则：动画全部使用 CSS transition / animation，不引第三方动画库
 * ========================================================= */

/* ---------- 基础 ---------- */
* {
  -webkit-tap-highlight-color: transparent; /* 去掉微信浏览器点击灰底 */
}

html, body {
  height: 100%;
  overscroll-behavior: none; /* 禁止下拉刷新，避免孩子误触 */
}

body {
  background: #BEE3F8;
  /* 电脑端看到的背景：柔和的卡通色块 */
  background-image:
    radial-gradient(circle at 15% 20%, rgba(255, 217, 61, 0.35) 0, transparent 32%),
    radial-gradient(circle at 85% 15%, rgba(255, 107, 107, 0.25) 0, transparent 30%),
    radial-gradient(circle at 80% 85%, rgba(107, 203, 119, 0.3) 0, transparent 32%),
    radial-gradient(circle at 10% 80%, rgba(77, 150, 255, 0.28) 0, transparent 30%);
  background-attachment: fixed;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- 整体容器 ---------- */
.app-shell {
  position: relative;
  max-width: 28rem;            /* 手机竖屏宽度 */
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  background: linear-gradient(180deg, #D8F3FF 0%, #FFF9EC 45%, #FFF9EC 100%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 电脑端：居中一张大卡片 */
@media (min-width: 768px) {
  .app-shell {
    margin: 1.25rem auto;
    min-height: calc(100vh - 2.5rem);
    border-radius: 2rem;
    box-shadow: 0 24px 60px rgba(58, 58, 90, 0.25);
  }
}

/* 老师投屏模式：更宽，方便教室投屏 */
body.teacher .app-shell {
  max-width: 46rem;
}

.page-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ---------- 通用积木按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border-radius: 1.25rem;
  font-weight: 700;
  padding: 0.9rem 1.6rem;
  box-shadow: 0 6px 0 rgba(58, 58, 90, 0.18);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.15s ease;
  cursor: pointer;
  border: none;
  line-height: 1.2;
}
.btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 rgba(58, 58, 90, 0.18);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: 0 6px 0 rgba(58, 58, 90, 0.18);
}
.btn-sun { background: #FFD93D; color: #5A4500; }
.btn-coral { background: #FF6B6B; color: #fff; }
.btn-sky { background: #4D96FF; color: #fff; }
.btn-grass { background: #6BCB77; color: #fff; }
.btn-grape { background: #9D4EDD; color: #fff; }
.btn-white { background: #fff; color: #3A3A5A; }

/* 圆形图标按钮（返回等） */
.btn-icon {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 9999px;
  background: #fff;
  box-shadow: 0 4px 0 rgba(58, 58, 90, 0.15);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  cursor: pointer;
  border: none;
}
.btn-icon:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(58, 58, 90, 0.15);
}

/* ---------- 底部导航 ---------- */
.nav-bar {
  position: sticky;
  bottom: 0;
  z-index: 30;
  display: flex;
  background: rgba(255, 255, 255, 0.96);
  border-top: 3px solid #EFE6D2;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0.55rem 0 0.45rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: #9A94A8;
  cursor: pointer;
  transition: color 0.15s ease, transform 0.15s ease;
}
.nav-item .nav-ico { font-size: 1.4rem; transition: transform 0.15s ease; }
.nav-item.active { color: #4D96FF; }
.nav-item.active .nav-ico { transform: translateY(-2px) scale(1.15); }
.nav-item:active .nav-ico { transform: scale(0.9); }

/* ---------- 卡片 ---------- */
.card {
  background: #fff;
  border-radius: 1.5rem;
  box-shadow: 0 4px 0 rgba(58, 58, 90, 0.1);
}

/* ---------- 音标大字 ---------- */
.phoneme-text {
  font-family: 'Times New Roman', 'Segoe UI', 'Arial Unicode MS', serif;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* ---------- 动画 ---------- */

/* 错误反馈：轻微左右抖动（柔和不刺眼） */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}
.animate-shake { animation: shake 0.4s ease; }

/* 入场：弹性放大 */
@keyframes pop-in {
  0% { transform: scale(0.5); opacity: 0; }
  70% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.animate-pop-in { animation: pop-in 0.35s ease both; }

/* 页面切换：淡入上移 */
@keyframes page-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
.page-enter { animation: page-in 0.28s ease both; }

/* 星星飞入/迸溅（正确反馈） */
@keyframes star-fly {
  0% { transform: translate(0, 0) scale(0.4) rotate(0deg); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1.3) rotate(40deg); opacity: 0; }
}
.star-fly {
  position: absolute;
  left: 50%;
  top: 40%;
  font-size: 1.6rem;
  pointer-events: none;
  animation: star-fly 0.9s ease-out forwards;
  z-index: 50;
}

/* 结果页大星星：依次弹入 */
@keyframes star-pop {
  0% { transform: scale(0) rotate(-40deg); opacity: 0; }
  70% { transform: scale(1.35) rotate(8deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}
.star-pop {
  display: inline-block;
  animation: star-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

/* 播放按钮呼吸光圈：提示孩子点这里 */
@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(77, 150, 255, 0.45); }
  100% { box-shadow: 0 0 0 18px rgba(77, 150, 255, 0); }
}
.pulse-hint { animation: pulse-ring 1.4s ease-out infinite; }

/* 漂浮装饰 */
@keyframes float-y {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
.animate-float { animation: float-y 3s ease-in-out infinite; }

/* 开心摇摆（答对时卡片） */
@keyframes wiggle {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-3deg); }
  75% { transform: rotate(3deg); }
}
.animate-wiggle { animation: wiggle 0.4s ease; }

/* 加载中旋转 */
@keyframes spin {
  to { transform: rotate(360deg); }
}
.animate-spin-slow { animation: spin 0.9s linear infinite; }

/* ---------- 轻提示 Toast ---------- */
#toast-root {
  position: fixed;
  left: 50%;
  bottom: 6.5rem;
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  pointer-events: none;
}
.toast {
  background: rgba(58, 58, 90, 0.92);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 0.6rem 1.2rem;
  border-radius: 9999px;
  animation: toast-in 0.25s ease both;
  white-space: nowrap;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px) scale(0.9); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.toast.out { transition: opacity 0.3s ease, transform 0.3s ease; opacity: 0; transform: translateY(-8px); }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(58, 58, 90, 0.45);
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  animation: fade-in 0.2s ease both;
}
.modal-card {
  background: #fff;
  border-radius: 1.75rem;
  padding: 1.75rem 1.5rem;
  width: 100%;
  max-width: 22rem;
  text-align: center;
  animation: pop-in 0.3s ease both;
  box-shadow: 0 20px 50px rgba(58, 58, 90, 0.3);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ---------- 音频加载失败提示 ---------- */
.audio-error {
  margin-top: 0.6rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: #FFF1F1;
  color: #C0392B;
  font-size: 0.8rem;
  font-weight: 700;
  border-radius: 9999px;
  padding: 0.4rem 0.9rem;
}

/* ---------- 设置页开关 ---------- */
.switch {
  position: relative;
  display: inline-block;
  width: 3.2rem;
  height: 1.9rem;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute;
  inset: 0;
  background: #E0DCEA;
  border-radius: 9999px;
  transition: background 0.2s ease;
  cursor: pointer;
}
.switch-slider::before {
  content: '';
  position: absolute;
  width: 1.45rem;
  height: 1.45rem;
  left: 0.22rem;
  top: 0.22rem;
  background: #fff;
  border-radius: 9999px;
  box-shadow: 0 2px 4px rgba(58, 58, 90, 0.25);
  transition: transform 0.2s ease;
}
.switch input:checked + .switch-slider { background: #6BCB77; }
.switch input:checked + .switch-slider::before { transform: translateX(1.3rem); }

/* ---------- 滚动条隐藏 ---------- */
.page-body::-webkit-scrollbar { width: 0; height: 0; }

/* ---------- 记忆翻牌 ---------- */
.match-card {
  perspective: 700px;
  aspect-ratio: 1;
  cursor: pointer;
}
.match-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.35s ease;
  transform-style: preserve-3d;
}
.match-inner.flipped { transform: rotateY(180deg); }
.match-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  border-radius: 1rem;
  box-shadow: 0 4px 0 rgba(58, 58, 90, 0.14);
  overflow: hidden;
}
.match-front {
  background: linear-gradient(145deg, #7FB5FF, #4D96FF);
  color: #fff;
  font-size: 1.5rem;
}
.match-back {
  transform: rotateY(180deg);
  background: #fff;
  font-size: 0.95rem;
  font-weight: 800;
  padding: 0.2rem;
  text-align: center;
  line-height: 1.15;
}
.match-back.is-phoneme { background: #FFF6D9; }
.match-card.matched { cursor: default; }
.match-card.matched .match-back { background: #EAF9EE; }
.match-card.matched .match-front { background: linear-gradient(145deg, #8FD694, #6BCB77); }
