/* ============================================================
   全能小卫士 v2.1 — 优化版样式
   核心：CSS 动画为主，GPU 加速，移动端优先
   
   优化点：
   - 所有动画只使用 transform + opacity（不触发 Layout）
   - will-change 仅在需要时添加
   - 新增 battleShake、monsterHit、comboPulse 等 keyframes
   - prefers-reduced-motion 支持
   ============================================================ */

/* ---- CSS 变量 ---- */
:root {
  --sky: #aee6fb;
  --sea: #7fd6f7;
  --sand: #ffe9a8;
  --leaf: #9be3a0;
  --coral: #ff9aa2;
  --ink: #3a4a5a;
  --card: #ffffffee;
  --gold: #ffd166;
  --radius: 1.1rem;
  --shadow: 0 6px 18px #2f6f8a22;
}

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky) 0 45%, var(--sea) 45% 70%, var(--sand) 70% 100%);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 760px;
  margin: 0 auto;
  background: transparent;
}

/* ---- Topbar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #fff8;
  border-bottom: 2px solid #fff6;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.logo {
  font-size: 1.15rem;
  font-weight: 800;
  padding: .6rem .8rem .2rem;
  color: #2f6f8a;
  text-align: center;
}
.tabs {
  display: flex;
  justify-content: center;
  gap: .3rem;
  padding: .3rem .4rem .5rem;
  flex-wrap: wrap;
}
.tabs button {
  flex: 1 1 auto;
  min-width: 64px;
  padding: .45rem .2rem;
  border: 0;
  border-radius: 999px;
  background: #ffffff55;
  color: var(--ink);
  font-size: .88rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, transform .1s, box-shadow .15s;
  will-change: transform;
}
.tabs button.active {
  background: var(--gold);
  color: #7a4a00;
  box-shadow: 0 3px 0 #e0a93a;
}
.tabs button:active {
  transform: scale(0.93);
}

/* ---- Main & View ---- */
main {
  flex: 1;
  padding: .7rem;
  padding-bottom: 5rem;
}
#view {
  display: flex;
  flex-direction: column;
  gap: .7rem;
}

/* 页面切换过渡 */
.view-enter {
  animation: viewEnter .2s ease-out;
  will-change: opacity, transform;
}
@keyframes viewEnter {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Footer Status Bar ---- */
footer.statusbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  justify-content: center;
  padding: .45rem .3rem;
  background: #3a4a5aee;
  color: var(--sand);
  font-size: .78rem;
  font-weight: 700;
  z-index: 6;
  border-top: 2px solid #fff6;
}

/* ---- Card ---- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: .9rem;
  box-shadow: var(--shadow);
  border: 2px solid #fff;
}
.card h2 { font-size: 1.05rem; margin-bottom: .5rem; color: #2f6f8a; }
.card h3 { font-size: .95rem; margin: .6rem 0 .3rem; color: #7a4a00; }

/* ---- Buttons ---- */
.btn {
  display: inline-block;
  padding: .55rem .9rem;
  border: 0;
  border-radius: 999px;
  background: var(--sea);
  color: #1f5c75;
  font-weight: 800;
  font-size: .95rem;
  cursor: pointer;
  transition: transform .08s, box-shadow .08s;
  will-change: transform;
  user-select: none;
}
.btn.coral { background: var(--coral); color: #7a2a32; box-shadow: 0 4px 0 #e07a84; }
.btn.gold  { background: var(--gold); color: #7a4a00; box-shadow: 0 4px 0 #e0a93a; }
.btn.leaf  { background: var(--leaf); color: #2f6a36; box-shadow: 0 4px 0 #6fbf78; }
.btn.ghost { background: #fff8; color: var(--ink); box-shadow: 0 3px 0 #ddd; }
.btn:active {
  transform: translateY(3px) scale(0.97);
  box-shadow: 0 1px 0 #4fb8dc;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:active:disabled { transform: none; }

/* ---- Layout Helpers ---- */
.row  { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.col  { display: flex; flex-direction: column; gap: .4rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .55rem; }

/* ---- Subject Cards ---- */
.subject {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  padding: .65rem;
  border-radius: .9rem;
  background: #fff;
  border: 2px solid #eee;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s, transform .1s;
}
.subject:active { transform: scale(0.97); border-color: var(--sea); }
.subject .emo  { font-size: 1.4rem; }
.subject .name { font-weight: 800; font-size: .95rem; }
.subject .desc { font-size: .72rem; color: #888; }
.tag {
  font-size: .68rem;
  padding: .15rem .45rem;
  border-radius: 999px;
  background: #eee;
  color: #666;
  width: fit-content;
}
.tag.en    { background: #e8f4ff; color: #2f6f8a; }
.tag.math  { background: #fff3e0; color: #a96a00; }
.tag.cn    { background: #fce8ec; color: #a63a4a; }
.tag.life  { background: #e8f8ee; color: #2f6a36; }

/* ---- Island / Pet ---- */
.island {
  position: relative;
  height: 200px;
  background:
    radial-gradient(circle at 50% 62%, #ffe9a8 0 42%, #ffd89a 42% 60%, transparent 60%),
    linear-gradient(180deg, #bfeafb 0 55%, #7fd6f7 55% 100%);
  border-radius: 1.2rem;
  overflow: hidden;
  border: 3px solid #fff;
  box-shadow: 0 8px 22px #2f6f8a33;
}
.pet {
  position: absolute;
  left: 50%;
  top: 52%;
  transform: translate(-50%, -50%);
  font-size: 4.2rem;
  text-align: center;
  transition: .4s;
  filter: drop-shadow(0 6px 0 #0002);
  animation: petBreathe 3s ease-in-out infinite;
  will-change: transform;
}
@keyframes petBreathe {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50%      { transform: translate(-50%, -52%) scale(1.04); }
}
.pet .say {
  display: block;
  font-size: .8rem;
  background: #fff;
  border-radius: 999px;
  padding: .2rem .6rem;
  margin-top: .4rem;
  color: #2f6f8a;
  font-weight: 700;
  white-space: nowrap;
}
.cloud {
  position: absolute;
  font-size: 2rem;
  opacity: .9;
  animation: cloudFloat 6s ease-in-out infinite;
  will-change: transform;
}
@keyframes cloudFloat {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}
.food {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.6rem;
}

/* ---- Evolve Animation ---- */
.evolve {
  animation: evolvePop .9s ease;
  will-change: transform, opacity;
}
@keyframes evolvePop {
  0%   { transform: translate(-50%, -50%) scale(.4); opacity: 0; }
  60%  { transform: translate(-50%, -50%) scale(1.25); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); }
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  left: 50%;
  top: 20%;
  transform: translateX(-50%) translateY(-20px);
  background: #3a4a5a;
  color: var(--sand);
  padding: .6rem 1rem;
  border-radius: 999px;
  font-weight: 700;
  z-index: 30;
  animation: toastSlide 2.4s ease forwards;
  pointer-events: none;
  will-change: transform, opacity;
}
@keyframes toastSlide {
  0%   { opacity: 0; transform: translateX(-50%) translateY(-20px); }
  15%  { opacity: 1; transform: translateX(-50%) translateY(0); }
  80%  { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-20px); }
}

/* ---- Choice Buttons (quiz) ---- */
.choice {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  justify-content: center;
  margin: .5rem 0;
}
.choice button {
  flex: 1 1 90px;
  padding: .7rem .4rem;
  border: 2px solid #eee;
  border-radius: .9rem;
  background: #fff;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform .1s, border-color .15s, background .15s;
}
.choice button:active { transform: scale(0.95); }
.choice button.correct { border-color: #6fbf78; background: #e8f8ee; animation: correctPulse .4s ease; }
.choice button.wrong   { border-color: #e07a84; background: #fce8ec; animation: wrongShake .4s ease; }

@keyframes correctPulse {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}
@keyframes wrongShake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-6px); }
  75%      { transform: translateX(6px); }
}

/* ---- Records ---- */
.record {
  font-size: .78rem;
  color: #666;
  max-height: 180px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: .25rem;
}
.record .r {
  display: flex;
  gap: .4rem;
  padding: .2rem .1rem;
  border-bottom: 1px dashed #eee;
}
.record .r b    { width: 52px; flex: none; }
.record .r .t   { color: #999; font-size: .68rem; margin-left: auto; }

.hidden { display: none; }

/* ---- Curriculum ---- */
.days { display: flex; flex-direction: column; gap: .5rem; margin-top: .3rem; }
.day {
  display: flex;
  flex-direction: column;
  gap: .2rem;
  padding: .6rem .7rem;
  border-radius: .9rem;
  background: #fff;
  border: 2px solid #eee;
  font-size: .82rem;
  color: #3a4a5a;
}
.day b    { font-size: .9rem; color: #2f6f8a; }
.day span { font-size: .78rem; color: #666; }
.day .ok  { color: #2f6a36; font-weight: 700; font-size: .82rem; }
.day.done { background: #f1faf3; border-color: #b7e3c2; opacity: .85; }
.day .mini {
  padding: .35rem .7rem;
  font-size: .8rem;
  margin-top: .25rem;
  align-self: flex-start;
  box-shadow: 0 3px 0 #e0a93a;
}
.curbtn.active {
  background: var(--gold);
  color: #7a4a00;
  box-shadow: 0 3px 0 #e0a93a;
}

/* ---- Evolution Fullscreen Confetti ---- */
@keyframes confettiFall {
  0%   { transform: translateY(0) rotate(0); opacity: 1; }
  100% { transform: translateY(105vh) rotate(720deg); opacity: 0.6; }
}
@keyframes evolveBigPop {
  0%   { transform: scale(.3) rotate(-20deg); opacity: 0; }
  50%  { transform: scale(1.3) rotate(10deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* ---- Daily Task Row ---- */
.task-row {
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: .6rem;
  border-radius: .8rem;
  transition: background .2s;
}
.task-row.done { background: #e8f8ee; }
.task-row.pending { background: #f5f5f5; }

/* ============================================================
   BATTLE — CSS 动画战斗场景（v2.1 优化）
   ============================================================ */

/* 战斗容器 */
#battle-wrap {
  position: relative;
  width: 100%;
  border-radius: 1.2rem;
  overflow: hidden;
  border: 3px solid #fff;
  box-shadow: 0 8px 22px #2f6f8a33;
}
#battle-scene {
  position: relative;
  width: 100%;
  height: 280px;
  background: linear-gradient(180deg, #bfeafb 0%, #7fd6f7 55%, #ffe9a8 100%);
  overflow: hidden;
}

/* 战斗场景地面 */
.battle-ground {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 22%;
  background: var(--leaf);
}
.battle-ground::before {
  content: '';
  position: absolute;
  top: -4px;
  left: 0;
  right: 0;
  height: 8px;
  background: repeating-linear-gradient(
    90deg,
    #7ccf85 0px, #7ccf85 2px,
    transparent 2px, transparent 18px
  );
}

/* 精灵（CSS 动画） */
.battle-pet {
  position: absolute;
  left: 16%;
  top: 42%;
  font-size: 3.5rem;
  transform: translate(-50%, -50%);
  animation: battlePetIdle 2s ease-in-out infinite;
  will-change: transform;
  z-index: 2;
  filter: drop-shadow(0 4px 0 #0002);
}
.battle-pet::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: radial-gradient(circle, #ffd16644 0%, transparent 70%);
  animation: haloGlow 2s ease-in-out infinite;
  z-index: -1;
  will-change: transform, opacity;
}
@keyframes battlePetIdle {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50%      { transform: translate(-50%, -54%) scale(1.03); }
}
@keyframes haloGlow {
  0%, 100% { opacity: 0.3; transform: translate(-50%, -50%) scale(1); }
  50%      { opacity: 0.6; transform: translate(-50%, -50%) scale(1.15); }
}

/* 怪物外层（CSS transform 移动 + transition 平滑） */
.battle-monster {
  position: absolute;
  will-change: transform;
  transition: transform 0.08s linear;
  z-index: 3;
}
.battle-monster.boss {
  font-size: 3.2rem;
}

/* 怪物内层（摇摆动画，避免与外层 transform 冲突） */
.monster-inner {
  font-size: 2.4rem;
  transform: translate(-50%, -50%);
  animation: monsterWobble 1.2s ease-in-out infinite;
  filter: drop-shadow(0 3px 0 #0003);
  will-change: transform;
}
@keyframes monsterWobble {
  0%, 100% { transform: translate(-50%, -50%) rotate(-3deg); }
  50%      { transform: translate(-50%, -56%) rotate(3deg); }
}

/* 怪物被击中闪烁（v2.1 新增） */
.monster-inner.hit {
  animation: monsterHit .3s ease;
  will-change: filter;
}
@keyframes monsterHit {
  0%, 100% { filter: brightness(1) drop-shadow(0 3px 0 #0003); }
  50%      { filter: brightness(2) drop-shadow(0 3px 0 #0003); }
}

/* Boss 血条（CSS transition 平滑） */
.monster-hp-bar {
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 5px;
  background: #333;
  border-radius: 3px;
  overflow: hidden;
}
.monster-hp-fill {
  height: 100%;
  background: #ff6b6b;
  transition: width .2s ease;
  border-radius: 3px;
  will-change: width;
}

/* 怪物类型标签 */
.monster-label {
  position: absolute;
  bottom: -16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: .65rem;
  color: #ff6b6b;
  font-weight: 700;
  white-space: nowrap;
}

/* 泡泡（CSS animation 飞行） */
.battle-bubble {
  position: absolute;
  left: 18%;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff8, #d4f1f9 60%);
  border: 1.5px solid #7fd6f7;
  will-change: transform, opacity;
  z-index: 4;
  animation: bubbleFly 2s linear forwards;
}
.battle-bubble::after {
  content: '';
  position: absolute;
  top: 20%;
  left: 22%;
  width: 25%;
  height: 25%;
  border-radius: 50%;
  background: #fffa;
}
@keyframes bubbleFly {
  from { transform: translateX(0); opacity: .8; }
  to   { transform: translateX(calc(100vw - 50px)); opacity: .3; }
}

/* 连击 HUD（v2.1 优化：comboPulse） */
#combo-hud {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--gold);
  text-shadow: 0 2px 6px #0006;
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
  z-index: 10;
  will-change: transform, opacity;
}
#combo-hud.show {
  opacity: 1;
  animation: comboPulse 1.2s ease;
}
@keyframes comboPulse {
  0%   { transform: translateX(-50%) scale(.6); }
  30%  { transform: translateX(-50%) scale(1.3); }
  60%  { transform: translateX(-50%) scale(1); }
  100% { transform: translateX(-50%) scale(1); }
}

/* 答题面板 */
#qpanel {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  border-radius: 1rem 1rem 0 0;
  padding: 1rem;
  box-shadow: 0 -4px 16px #0003;
  z-index: 5;
  animation: panelSlideUp .25s ease-out;
  will-change: transform;
}
@keyframes panelSlideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

/* 战斗粒子 Canvas（覆盖层，按需显示） */
#battle-particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 8;
  display: none;
}

/* 屏幕震动（v2.1 优化：GPU 加速） */
.battle-shake {
  animation: battleShake .4s ease;
  will-change: transform;
}
@keyframes battleShake {
  0%, 100% { transform: translate(0, 0); }
  20%      { transform: translate(-4px, 2px); }
  40%      { transform: translate(3px, -3px); }
  60%      { transform: translate(-2px, 1px); }
  80%      { transform: translate(2px, -1px); }
}

/* ---- Speak Button ---- */
#speak-btn, #speak-btn2 {
  transition: transform .1s;
  will-change: transform;
}
#speak-btn:active, #speak-btn2:active {
  transform: scale(.88);
}

/* ---- Misc ---- */
.modal {
  position: fixed;
  inset: 0;
  background: #0008;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 1rem;
}
.modal .box {
  background: #fff;
  border-radius: 1.2rem;
  padding: 1rem 1.1rem;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 30px #0005;
}
.modal h3 { margin-bottom: .5rem; }
.modal .actions {
  display: flex;
  gap: .5rem;
  justify-content: center;
  margin-top: .6rem;
  flex-wrap: wrap;
}

/* ---- Responsive ---- */
@media (max-width: 420px) {
  .pet { font-size: 3.4rem; }
  .island { height: 170px; }
  .tabs button { font-size: .8rem; padding: .4rem .15rem; }
  .battle-pet { font-size: 2.8rem; }
  #battle-scene { height: 240px; }
}

/* ---- Accessibility: Reduced Motion ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   ONBOARDING — 故事书引导（v2.2 新增）
   ============================================================ */

#onboarding-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, #bfeafb 0%, #7fd6f7 50%, #ffe9a8 100%);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.onboarding-page {
  max-width: 500px;
  width: 100%;
  text-align: center;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 1.5rem;
  padding: 2rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  animation: pageEnter 0.5s ease;
}

@keyframes pageEnter {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.onboarding-emoji {
  font-size: 5rem;
  margin-bottom: 1rem;
  animation: emojiBounce 2s ease infinite;
}

@keyframes emojiBounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-10px); }
}

.onboarding-page h2 {
  font-size: 1.5rem;
  color: #2f6f8a;
  margin-bottom: 1rem;
}

.onboarding-text {
  font-size: 1.1rem;
  line-height: 1.8;
  color: #3a4a5a;
  margin-bottom: 2rem;
}

.onboarding-controls {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

/* ============================================================
   HP SYSTEM — 宠物生命值（v2.3 新增）
   ============================================================ */

/* HP 条样式 */
.hp-bar-container {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-top: .8rem;
  padding: .6rem;
  background: #f5f5f5;
  border-radius: .8rem;
}

.hp-label {
  font-size: .9rem;
  font-weight: 700;
  min-width: 80px;
}

.hp-bar {
  flex: 1;
  height: 12px;
  background: #ddd;
  border-radius: 6px;
  overflow: hidden;
}

.hp-fill {
  height: 100%;
  transition: width .5s ease, background .5s ease;
  border-radius: 6px;
}

.hp-value {
  font-size: .9rem;
  font-weight: 700;
  min-width: 40px;
  text-align: right;
}

/* 宠物受伤状态 */
.pet.hurt {
  filter: grayscale(80%) brightness(0.7);
  animation: petHurt 2s ease-in-out infinite;
}

@keyframes petHurt {
  0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  50% { transform: translate(-50%, -52%) scale(0.95); opacity: 0.6; }
}

/* 宠物虚弱状态 */
.pet.weak {
  filter: grayscale(40%) brightness(0.85);
  animation: petWeak 3s ease-in-out infinite;
}

@keyframes petWeak {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -52%) scale(0.98); }
}

/* 紧急事件横幅 */
.emergency-banner {
  background: linear-gradient(90deg, #ff6b6b, #ff9aa2);
  color: white;
  text-align: center;
  padding: .8rem;
  font-weight: 900;
  font-size: 1rem;
  animation: emergencyPulse 1.5s ease-in-out infinite;
  margin-bottom: .5rem;
  border-radius: .8rem;
}

@keyframes emergencyPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.8; transform: scale(1.02); }
}
