:root {
  --primary: #FF9F43;
  --primary-dark: #FF7A18;
  --accent: #FF6B9D;
  --bg: #FFF0F5;
  --card: #FFFFFF;
  --text: #5C3A3A;
  --muted: #B08080;
  --success: #FF85A2;
  --error: #F5222D;
  --btn-gradient: linear-gradient(90deg, #FF9F43, #FF6B9D);
  --btn-shadow: rgba(255, 107, 157, 0.3);
  --chip-bg: #FFE4EC;
  --chip-active: #FF6B9D;
  --feedback-ok: #FF85A2;
  --feedback-no: #FFEBEE;
  --star: #FFD700;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 72px;
  min-height: 100vh;
  transition: background .3s, color .3s;
}

/* 顶栏 */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--card);
  box-shadow: 0 2px 10px rgba(0,0,0,.06);
}
.appbar-title { font-weight: 800; font-size: 18px; color: var(--primary-dark); }
.appbar-status { display: flex; align-items: center; gap: 8px; }
.pill {
  background: var(--chip-bg); color: var(--text);
  border-radius: 999px; padding: 4px 10px; font-size: 13px; font-weight: 700;
}
.icon-btn {
  border: none; background: var(--chip-bg); border-radius: 50%;
  width: 34px; height: 34px; font-size: 17px; cursor: pointer;
}

/* 视图通用 */
.view { padding: 16px; max-width: 680px; margin: 0 auto; }
.section-title { font-size: 16px; font-weight: 800; margin: 18px 4px 10px; color: var(--primary-dark); }
.muted { color: var(--muted); font-size: 13px; }

/* 卡片 */
.card {
  background: var(--card); border-radius: 16px; padding: 16px;
  box-shadow: 0 4px 14px rgba(0,0,0,.05); margin-bottom: 12px;
}

/* 年级选择 */
.grade-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.grade-chip {
  flex: 1 1 calc(25% - 10px); min-width: 64px;
  border: 2px solid transparent; background: var(--card);
  border-radius: 14px; padding: 12px 4px; text-align: center;
  font-weight: 700; cursor: pointer; box-shadow: 0 3px 10px rgba(0,0,0,.05);
  transition: transform .12s;
}
.grade-chip:active { transform: scale(.95); }
.grade-chip.active { border-color: var(--accent); background: var(--chip-bg); }
.grade-chip .g-emoji { font-size: 22px; display: block; }
.mix-chip { flex: 1 1 100%; background: var(--btn-gradient); color: #fff; border: none; }

/* 关卡 */
.level-group { margin-top: 6px; }
.level-row { display: flex; gap: 10px; flex-wrap: wrap; }
.level-card {
  flex: 1 1 calc(50% - 10px); min-width: 130px;
  background: var(--card); border-radius: 14px; padding: 14px;
  box-shadow: 0 3px 10px rgba(0,0,0,.05); cursor: pointer; position: relative;
  border: 2px solid transparent;
}
.level-card.locked { opacity: .5; cursor: not-allowed; }
.level-card:not(.locked):active { transform: scale(.97); }
.level-card .l-name { font-weight: 800; }
.level-card .l-desc { font-size: 12px; color: var(--muted); margin-top: 2px; }
.level-card .l-lock { position: absolute; top: 10px; right: 12px; font-size: 16px; }
.level-card .l-clear { position: absolute; top: 10px; right: 12px; font-size: 16px; color: var(--success); }

/* 按钮 */
.btn {
  display: block; width: 100%; border: none; border-radius: 14px;
  padding: 14px; font-size: 16px; font-weight: 800; color: #fff;
  background: var(--btn-gradient); box-shadow: 0 6px 16px var(--btn-shadow);
  cursor: pointer; transition: transform .12s;
}
.btn:active { transform: scale(.97); }
.btn-ghost {
  background: var(--chip-bg); color: var(--text); box-shadow: none;
  border-radius: 12px; padding: 10px 16px; font-weight: 700; cursor: pointer; border: none;
}
.btn-sm { display: inline-block; width: auto; padding: 8px 14px; font-size: 14px; border-radius: 10px; }

/* 答题 */
.quiz-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.quiz-progress { font-weight: 700; }
.combo-badge {
  background: var(--chip-bg); border-radius: 999px; padding: 4px 10px;
  font-weight: 800; color: var(--accent); transition: transform .15s;
}
.combo-badge.bump { transform: scale(1.25); }
.timer {
  height: 8px; background: var(--chip-bg); border-radius: 4px; overflow: hidden; margin: 10px 0;
}
.timer > i { display: block; height: 100%; background: var(--btn-gradient); width: 100%; transition: width 1s linear; }
.stem {
  font-size: 22px; font-weight: 800; line-height: 1.6; text-align: center;
  margin: 18px 0; letter-spacing: 1px;
}
.stem .blank { color: var(--accent); }

/* 字块拼词 */
.slots { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 10px 0; min-height: 44px; }
.slot {
  width: 38px; height: 44px; border: 2px dashed var(--muted); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 800;
  background: var(--chip-bg); color: var(--text);
}
.slot.filled { border-style: solid; border-color: var(--accent); background: #fff; }
.tray { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 12px 0; }
.tile {
  min-width: 38px; height: 44px; padding: 0 8px; border-radius: 8px;
  background: var(--btn-gradient); color: #fff; font-size: 20px; font-weight: 800;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  box-shadow: 0 3px 8px var(--btn-shadow);
}
.tile:active { transform: scale(.94); }
.tile.used { visibility: hidden; }

/* 选择题 */
.options { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.option {
  background: var(--card); border: 2px solid var(--chip-bg); border-radius: 12px;
  padding: 14px; font-size: 16px; font-weight: 600; cursor: pointer; text-align: left;
}
.option:active { transform: scale(.98); }
.option.correct { border-color: var(--success); background: var(--feedback-ok); color: #fff; }
.option.wrong { border-color: var(--error); background: var(--feedback-no); }
.option.disabled { pointer-events: none; }

/* 反馈横幅 */
.feedback {
  margin-top: 14px; padding: 12px; border-radius: 12px; text-align: center;
  font-weight: 700; font-size: 15px; opacity: 0; transform: translateY(8px);
  transition: opacity .2s, transform .2s;
}
.feedback.show { opacity: 1; transform: none; }
.feedback.ok { background: var(--feedback-ok); color: #fff; }
.feedback.no { background: var(--feedback-no); color: var(--error); }
.pet-talk {
  display: flex; align-items: center; gap: 10px; margin-top: 12px;
  background: var(--chip-bg); border-radius: 14px; padding: 10px 14px;
}
.pet-talk img { width: 56px; height: 56px; object-fit: contain; }
.pet-talk .say { font-size: 14px; font-weight: 600; }

/* 结算 */
.result-emoji { font-size: 56px; text-align: center; }
.result-title { text-align: center; font-size: 22px; font-weight: 800; margin: 6px 0; }
.result-stats { display: flex; justify-content: space-around; text-align: center; margin: 14px 0; }
.result-stats .rs-num { font-size: 24px; font-weight: 800; color: var(--accent); }
.result-stats .rs-lab { font-size: 12px; color: var(--muted); }
.result-pet { display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 10px 0; }
.result-pet img { width: 96px; height: 96px; object-fit: contain; }

/* 错题本 */
.wb-stats { display: flex; gap: 10px; }
.wb-stat { flex: 1; text-align: center; background: var(--card); border-radius: 12px; padding: 12px; box-shadow: 0 3px 10px rgba(0,0,0,.05); }
.wb-stat .n { font-size: 22px; font-weight: 800; color: var(--accent); }
.wb-stat .l { font-size: 12px; color: var(--muted); }
.wb-item { background: var(--card); border-radius: 12px; padding: 12px; margin-bottom: 10px; box-shadow: 0 2px 8px rgba(0,0,0,.04); }
.wb-item .q { font-weight: 700; }
.wb-item .a { color: var(--success); font-weight: 700; margin-top: 4px; }
.wb-item .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.wb-actions { display: flex; gap: 8px; margin-top: 8px; }

/* 成就 */
.ach-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.ach {
  background: var(--card); border-radius: 14px; padding: 12px; box-shadow: 0 3px 10px rgba(0,0,0,.05);
  position: relative; opacity: .55;
}
.ach.unlocked { opacity: 1; border: 2px solid var(--accent); }
.ach .a-icon { font-size: 26px; }
.ach .a-name { font-weight: 800; font-size: 14px; margin-top: 2px; }
.ach .a-desc { font-size: 11px; color: var(--muted); margin-top: 2px; }
.ach .a-bar { height: 6px; background: var(--chip-bg); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.ach .a-bar > i { display: block; height: 100%; background: var(--btn-gradient); }
.ach .a-pct { font-size: 11px; color: var(--muted); margin-top: 2px; text-align: right; }

/* 宠物 */
.pet-hero { text-align: center; }
.pet-hero img { width: 140px; height: 140px; object-fit: contain; }
.pet-hero .p-name { font-size: 20px; font-weight: 800; }
.pet-hero .p-stage { color: var(--muted); font-size: 13px; }
.exp-bar { height: 10px; background: var(--chip-bg); border-radius: 5px; overflow: hidden; margin: 10px 0; }
.exp-bar > i { display: block; height: 100%; background: var(--btn-gradient); }
.egg { font-size: 80px; text-align: center; cursor: pointer; user-select: none; }
.egg:active { transform: scale(.92); }
.shop-row { display: flex; align-items: center; justify-content: space-between; background: var(--card); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; box-shadow: 0 2px 8px rgba(0,0,0,.04); }
.shop-row .s-name { font-weight: 700; }
.shop-row .s-price { color: var(--accent); font-weight: 800; font-size: 13px; }

/* 底部导航 */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: var(--card); box-shadow: 0 -2px 12px rgba(0,0,0,.08);
  padding: 6px 0 env(safe-area-inset-bottom); max-width: 680px; margin: 0 auto;
}
.tab {
  flex: 1; border: none; background: none; cursor: pointer; padding: 6px 0;
  display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted);
}
.tab span { font-size: 22px; }
.tab small { font-size: 11px; }
.tab.active { color: var(--accent); font-weight: 800; }

/* 主题弹层 */
.sheet-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40;
  display: none;
}
.sheet-mask:not([hidden]) {
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--card); width: 100%; max-width: 680px; border-radius: 18px 18px 0 0;
  padding: 18px; animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-title { font-weight: 800; font-size: 16px; margin-bottom: 12px; }
.theme-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
.theme-opt {
  border: 2px solid var(--chip-bg); border-radius: 12px; padding: 12px;
  display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 700;
}
.theme-opt.active { border-color: var(--accent); }
.theme-opt .sw { width: 26px; height: 26px; border-radius: 50%; }

/* 轻提示 */
.toast {
  position: fixed; left: 50%; top: 20%; transform: translateX(-50%);
  background: rgba(0,0,0,.8); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 14px; z-index: 60; animation: fadeIn .2s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.empty { text-align: center; color: var(--muted); padding: 30px 0; }
