:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --ink: #23262b;
  --muted: #6b7280;
  --brand: #2f6fed;
  --brand-soft: #e8f0ff;
  --ok: #1f9d55;
  --bad: #d6453d;
  --line: #e4e7ee;
  --radius: 16px;
  --tap: 48px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.5;
}
.screen { min-height: 100vh; }
.hidden { display: none !important; }

/* ===== 登录 ===== */
#login { display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  background: var(--card); width: 100%; max-width: 420px;
  border-radius: 20px; padding: 28px 24px;
  box-shadow: 0 8px 30px rgba(30,40,80,.10);
}
.brand { font-size: 26px; font-weight: 800; text-align: center; }
.brand-sub { text-align: center; color: var(--muted); font-size: 14px; margin: 6px 0 18px; }
.login-card input {
  width: 100%; height: var(--tap); padding: 0 14px; margin-bottom: 14px;
  border: 1.5px solid var(--line); border-radius: 12px; font-size: 16px;
}
.hint { color: var(--muted); font-size: 14px; margin: 4px 0 10px; }
.role-grid { display: grid; gap: 12px; }
.role-btn {
  height: var(--tap); border: 1.5px solid var(--brand);
  background: var(--brand-soft); color: var(--brand);
  border-radius: 12px; font-size: 17px; font-weight: 600; cursor: pointer;
  transition: transform .05s ease;
}
.role-btn:active { transform: scale(.98); }
.msg { color: var(--bad); text-align: center; min-height: 20px; font-size: 14px; margin: 10px 0 0; }
.demo-tip { color: var(--muted); font-size: 12px; text-align: center; margin-top: 14px; }

/* ===== 顶栏 ===== */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; background: var(--card);
  border-bottom: 1px solid var(--line);
}
.identity { font-weight: 700; font-size: 17px; }
.child-switch {
  margin-left: 10px; height: 38px; border: 1px solid var(--line);
  border-radius: 10px; padding: 0 8px; font-size: 15px; background: #fff;
}
.sync-pill {
  margin-left: 10px; font-size: 12px; padding: 4px 10px; border-radius: 999px;
  white-space: nowrap; cursor: pointer; border: 1px solid transparent; max-width: 60vw;
  overflow: hidden; text-overflow: ellipsis;
}
.sync-pill.idle { background: #eef2fb; color: #4a5a86; }
.sync-pill.offline { background: #f1f1f3; color: #777; cursor: help; }
.sync-pill.syncing { background: #fff4e0; color: #b5791a; }
.sync-pill.ok { background: #e7f7ec; color: #1d8a44; }
.sync-pill.error { background: #fdeaea; color: #c0392b; }
.ghost-btn {
  height: 38px; padding: 0 16px; border: 1px solid var(--line);
  background: #fff; border-radius: 10px; font-size: 15px; cursor: pointer;
}

/* ===== 视图区 ===== */
.view { padding: 16px 16px 96px; max-width: 860px; margin: 0 auto; }
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; box-shadow: 0 2px 10px rgba(30,40,80,.05);
}
.card h2 { margin: 0 0 12px; font-size: 19px; }
.card h3 { margin: 0 0 8px; font-size: 16px; }
.muted { color: var(--muted); font-size: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.center { text-align: center; }

/* 科目 / 入口网格 */
.tile-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; min-height: 96px; border-radius: 14px; cursor: pointer;
  background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: 17px;
  border: 1.5px solid transparent;
}
.tile .emoji { font-size: 30px; }
.tile:active { border-color: var(--brand); }

/* 题目卡 */
.q {
  background: var(--card); border-radius: var(--radius); padding: 18px;
  margin-bottom: 16px; box-shadow: 0 2px 10px rgba(30,40,80,.05);
}
.q-meta { color: var(--brand); font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.q-stem { font-size: 18px; margin-bottom: 12px; white-space: pre-wrap; }
.q-img { width: 100%; max-width: 320px; border-radius: 12px; margin: 8px 0; display: block; }
.audio-btn {
  display: inline-flex; align-items: center; gap: 8px; height: var(--tap);
  padding: 0 18px; border: none; border-radius: 12px; background: var(--brand);
  color: #fff; font-size: 16px; cursor: pointer; margin: 8px 0;
}
.options { display: grid; gap: 10px; }
.opt {
  display: flex; align-items: center; gap: 12px; min-height: var(--tap);
  padding: 0 14px; border: 1.5px solid var(--line); border-radius: 12px;
  background: #fff; font-size: 16px; cursor: pointer;
}
.opt.sel { border-color: var(--brand); background: var(--brand-soft); }
.opt.correct { border-color: var(--ok); background: #eafaf0; }
.opt.wrong { border-color: var(--bad); background: #fdecea; }
.opt .tag { width: 26px; height: 26px; border-radius: 50%; background: #eef1f6; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; color: var(--muted); }

.primary-btn {
  width: 100%; height: var(--tap); border: none; border-radius: 12px;
  background: var(--brand); color: #fff; font-size: 17px; font-weight: 700; cursor: pointer;
  margin-top: 8px;
}
.primary-btn:disabled { opacity: .5; }

/* 填空题输入 */
.fill-wrap { margin: 10px 0; }
.fill-input {
  width: 100%; min-height: var(--tap); padding: 0 14px;
  border: 1.5px solid var(--line); border-radius: 12px; font-size: 18px;
  font-family: inherit;
}
.fill-input:focus { outline: none; border-color: var(--brand); }
.fill-input.fill-ok { border-color: var(--ok); background: #eafaf0; }
.fill-input.fill-bad { border-color: var(--bad); background: #fdecea; }
.feedback .norm-hint { margin-top: 6px; font-size: 13px; color: var(--muted); }
.feedback { margin-top: 12px; padding: 12px; border-radius: 12px; font-size: 15px; }
.feedback.ok { background: #eafaf0; color: #16653a; }
.feedback.bad { background: #fdecea; color: #922; }
.feedback .analysis { margin-top: 6px; color: var(--muted); font-size: 14px; }

/* 统计 */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; text-align: center; }
.stat { background: var(--brand-soft); border-radius: 14px; padding: 14px 8px; }
.stat .num { font-size: 26px; font-weight: 800; color: var(--brand); }
.stat .lbl { font-size: 13px; color: var(--muted); }

/* 列表项 */
.item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px; border: 1px solid var(--line); border-radius: 12px;
  margin-bottom: 10px; background: #fff;
}
.item .info { font-size: 15px; }
.item .sub { font-size: 12px; color: var(--muted); }
.pill { font-size: 12px; padding: 3px 10px; border-radius: 999px; background: #eef1f6; color: var(--muted); }
.pill.pending { background: #fff4e0; color: #b5741a; }
.pill.active { background: #eafaf0; color: #16653a; }

/* 底部导航 */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.nav-btn {
  flex: 1; border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; color: var(--muted); font-size: 12px;
}
.nav-btn .ico { font-size: 22px; }
.nav-btn.active { color: var(--brand); font-weight: 700; }

/* 表单 */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1.5px solid var(--line);
  border-radius: 12px; font-size: 16px; font-family: inherit;
}

/* 打印（PDF 错题） */
.print-only { display: none; }
@media print {
  body * { visibility: hidden; }
  #printArea, #printArea * { visibility: visible; }
  #printArea { display: block; position: absolute; inset: 0; padding: 16px; }
  .print-q { border-bottom: 1px dashed #999; padding: 10px 0; page-break-inside: avoid; }
  .print-q h3 { margin: 0 0 4px; }
}

/* 开放题（问答/应用/作文）输入与展示 */
.open-input {
  width: 100%; box-sizing: border-box; padding: 12px;
  font-size: 16px; line-height: 1.6; border: 1.5px solid var(--line);
  border-radius: 12px; resize: vertical; font-family: inherit;
}
.feedback .analysis { white-space: pre-wrap; margin-top: 6px; color: var(--muted); }
.comp-card .analysis { white-space: pre-wrap; }
.pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 600;
}
.pill.active { background: #e6f7ee; color: var(--ok); }
.pill.pending { background: #fff3e0; color: #c77700; }

/* ===== 掌握度复习计划 ===== */
:root { --warn: #c77700; --good: #1f9d55; }
.review-home { background: linear-gradient(135deg, #eef4ff, #ffffff); }
.stat { text-align: center; }
.stat .num { font-size: 30px; font-weight: 800; }
.stat .lbl { font-size: 13px; color: var(--muted); }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 12px 0; }
.mastery-bar { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; margin: 6px 0; }
.mastery-fill { height: 100%; background: linear-gradient(90deg, var(--brand), var(--good)); border-radius: 999px; }
.chip {
  display: inline-block; padding: 6px 14px; border-radius: 999px; border: 1.5px solid var(--line);
  background: #fff; font-size: 14px; cursor: pointer; color: var(--ink);
}
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.back-btn {
  display: inline-flex; align-items: center; gap: 4px; padding: 7px 14px;
  border: 1.5px solid var(--line); border-radius: 10px; background: #fff;
  font-size: 14px; font-weight: 600; color: var(--ink); cursor: pointer;
}
.back-btn:hover { background: #f2f4f7; }
.qp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.qp-prog { font-size: 14px; color: var(--muted); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filter-row { display: flex; align-items: center; gap: 12px; margin: 12px 0; flex-wrap: wrap; }
.filter-row > label { width: 76px; flex: none; font-weight: 600; color: var(--ink); }
.fsel { height: 38px; border: 1.5px solid var(--line); border-radius: 10px; padding: 0 10px; font-size: 15px; background: #fff; min-width: 160px; }

/* ============ 云宠物 ============ */
.pet-card {
  background: linear-gradient(160deg, #f4f9ff 0%, #eef6ff 60%, #eafbf2 100%);
  border: 1.5px solid #dbe9ff;
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 6px;
}
.pet-card-compact { padding: 12px 14px; }
.pet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.pet-badge {
  font-weight: 700; font-size: 15px; color: #2f6fed;
  background: #fff; border: 1.5px solid #cfe0ff; border-radius: 999px; padding: 3px 12px;
}
.pet-owner { font-size: 13px; color: var(--muted); }
.pet-scene { position: relative; display: flex; align-items: flex-end; gap: 12px; padding: 6px 0 2px; }
.pet-figure { position: relative; width: 96px; height: 96px; flex: none; animation: petFloat 3.2s ease-in-out infinite; transform-origin: center; }
.pet-card-compact .pet-figure { width: 72px; height: 72px; }
.pet-svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 6px 8px rgba(60,90,160,0.18)); }
.pet-shadow {
  position: absolute; left: 50%; bottom: -2px; transform: translateX(-50%);
  width: 56%; height: 9px; background: rgba(80,110,170,0.18); border-radius: 50%;
  filter: blur(2px); animation: petShadow 3.2s ease-in-out infinite;
}
.pet-bubble {
  flex: 1; background: #fff; border: 1.5px solid #e3ecff; border-radius: 14px;
  padding: 10px 12px; font-size: 14px; color: #3a4256; line-height: 1.45;
  position: relative; min-height: 44px;
}
.pet-bubble::before {
  content: ""; position: absolute; left: -8px; top: 16px; width: 0; height: 0;
  border-top: 7px solid transparent; border-bottom: 7px solid transparent; border-right: 8px solid #e3ecff;
}
.pet-actions { display: flex; align-items: center; gap: 8px; margin: 10px 0 8px; flex-wrap: wrap; }
.pet-name { font-weight: 700; color: #44506a; margin-right: auto; }
.pet-name::before { content: ""; }
.xp-bar { height: 12px; background: #e7eefc; border-radius: 999px; overflow: hidden; }
.xp-fill { height: 100%; background: linear-gradient(90deg, #56b6ff, #6fe0a8); border-radius: 999px; transition: width .5s ease; }
.xp-text { font-size: 13px; color: var(--muted); margin-top: 5px; }
.pet-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .pet-grid { grid-template-columns: 1fr; } }

/* 摸摸头动画 */
.pet-pat-anim { animation: petPat .6s ease; }
.pet-heart {
  position: absolute; bottom: 30px; font-size: 18px; pointer-events: none;
  animation: petHeart 1.2s ease-out forwards; opacity: 0;
}
@keyframes petFloat { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes petShadow { 0%,100% { transform: scale(1); opacity: .35; } 50% { transform: scale(.82); opacity: .22; } }
@keyframes petPat { 0% { transform: rotate(0); } 25% { transform: rotate(-8deg) scale(1.05); } 60% { transform: rotate(6deg) scale(1.05); } 100% { transform: rotate(0); } }
@keyframes petHeart { 0% { opacity: 0; transform: translateY(0) scale(.6); } 25% { opacity: 1; } 100% { opacity: 0; transform: translateY(-46px) scale(1.1); } }

/* 升级飘字 */
.pet-toast {
  position: fixed; left: 50%; top: 18%; transform: translateX(-50%) translateY(-12px);
  background: linear-gradient(90deg, #2f6fed, #6a5cff); color: #fff; font-weight: 700;
  padding: 12px 22px; border-radius: 999px; box-shadow: 0 10px 30px rgba(60,90,200,.35);
  opacity: 0; pointer-events: none; transition: opacity .3s, transform .3s; z-index: 999; font-size: 16px;
}
.pet-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============ 云宠物进化庆祝全屏动画 ============ */
.pet-celebrate {
  position: fixed; inset: 0; z-index: 9999; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: rgba(20, 28, 48, .55); backdrop-filter: blur(2px);
  animation: celebrateIn .3s ease;
}
.pet-celebrate.out { opacity: 0; transition: opacity .35s ease; }
@keyframes celebrateIn { from { opacity: 0; } to { opacity: 1; } }
.celebrate-card {
  position: relative; z-index: 2; background: #fff; border-radius: 22px;
  padding: 26px 36px; text-align: center; box-shadow: 0 24px 70px rgba(0,0,0,.35);
  animation: celebratePop .45s cubic-bezier(.2,1.5,.4,1); max-width: 86vw;
}
@keyframes celebratePop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.celebrate-card .pet-figure { width: 150px; margin: 0 auto; }
.celebrate-card .pet-svg { width: 150px; height: 150px; }
.pet-pop { animation: petPop 1s ease-in-out infinite alternate; }
@keyframes petPop { from { transform: translateY(0) rotate(-2deg); } to { transform: translateY(-12px) rotate(2deg); } }
.celebrate-card .big { font-size: 26px; font-weight: 800; margin-top: 10px; color: #e8590c; }
.pet-celebrate.legend .big { color: #b8860b; text-shadow: 0 0 12px rgba(255,215,0,.6); }
.confetti {
  position: absolute; top: -24px; border-radius: 2px; opacity: .95;
  animation-name: confettiFall; animation-timing-function: linear; animation-fill-mode: forwards;
  z-index: 1;
}
@keyframes confettiFall {
  0% { transform: translateY(-10px) rotate(0); opacity: 1; }
  100% { transform: translateY(105vh) rotate(720deg); opacity: .85; }
}

/* 课程标签删除按钮 */
.chip.sub-item { display: inline-flex; align-items: center; gap: 4px; padding-right: 6px; }
.sub-del {
  border: none; background: rgba(229,57,53,.12); color: #e53935; cursor: pointer;
  border-radius: 50%; width: 18px; height: 18px; line-height: 1; font-size: 13px; padding: 0;
}
.sub-del:hover { background: #e53935; color: #fff; }

/* ===== 考试成绩 ===== */
.inp {
  height: var(--tap); padding: 0 12px; border: 1.5px solid var(--line);
  border-radius: 12px; font-size: 15px; background: var(--card); color: var(--ink);
  max-width: 100%;
}
.inp:focus { outline: none; border-color: var(--brand); }
#exSub, #exType, #exChild, #exSubFilter { min-width: 96px; }
#examChart svg { background: var(--card); }
#examList .ex-del { color: var(--bad); border-color: var(--line); }
#examList .ex-edit { color: var(--brand); border-color: var(--line); }

