* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #5D78F6;
  --primary-dark: #4659c9;
  --bg1: #eaf1ff;
  --bg2: #fff7e6;
  --card: #ffffff;
  --text: #2b2f3a;
  --muted: #8a90a3;
  --good: #2fb344;
  --bad: #f05353;
  --gold: #f5a623;
}
html, body { height: 100%; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, var(--bg1), var(--bg2));
  background-attachment: fixed;
  min-height: 100%;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input { font-family: inherit; }

.container { max-width: 720px; margin: 0 auto; padding: 16px 16px 48px; }
.view { min-height: 100vh; }
.msg { min-height: 20px; margin-top: 10px; font-size: 14px; color: var(--bad); text-align: center; }

/* 登录 */
#view-auth { display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card {
  background: var(--card); width: 100%; max-width: 400px;
  border-radius: 24px; padding: 32px 28px; text-align: center;
  box-shadow: 0 12px 40px rgba(93, 120, 246, .18);
}
.mascot { font-size: 64px; animation: float 3s ease-in-out infinite; }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
.brand { font-size: 26px; margin: 8px 0 4px; }
.brand-sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.tabs { display: flex; background: #eef2ff; border-radius: 14px; padding: 4px; margin-bottom: 18px; }
.tab { flex: 1; padding: 10px 0; border-radius: 11px; font-size: 15px; color: var(--muted); transition: all .2s; }
.tab.active { background: var(--primary); color: #fff; font-weight: bold; }
#form-auth { display: flex; flex-direction: column; gap: 12px; }
#form-auth input[type="text"], #form-auth input[type="password"], #form-auth input:not([type]) {
  padding: 13px 16px; border: 2px solid #e3e7f5; border-radius: 14px; font-size: 15px; outline: none;
}
#form-auth input:focus { border-color: var(--primary); }
.role-opt { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: #f6f8ff;
  border-radius: 14px; font-size: 14px; cursor: pointer; border: 2px solid transparent; }
.role-opt:has(input:checked) { border-color: var(--primary); background: #eef2ff; }
.role-opt input { accent-color: var(--primary); }

.btn-primary {
  background: var(--primary); color: #fff; padding: 13px 22px; border-radius: 16px;
  font-size: 16px; font-weight: bold; box-shadow: 0 6px 16px rgba(93,120,246,.35);
  transition: transform .1s, background .2s;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: scale(.97); }
.btn-primary:disabled { background: #c3cbee; box-shadow: none; cursor: not-allowed; }
.btn-secondary {
  flex: 1; background: var(--card); padding: 14px 10px; border-radius: 16px; font-size: 15px;
  box-shadow: 0 4px 14px rgba(43,47,58,.08); transition: transform .1s;
}
.btn-secondary:hover { transform: translateY(-2px); }
.btn-icon { font-size: 20px; padding: 8px 10px; border-radius: 12px; background: var(--card);
  box-shadow: 0 3px 10px rgba(43,47,58,.08); }
.btn-icon:active { transform: scale(.93); }

/* 顶栏 */
.topbar { display: flex; align-items: center; gap: 10px; padding: 14px 16px;
  background: rgba(255,255,255,.85); backdrop-filter: blur(6px); position: sticky; top: 0; z-index: 5; }
.topbar-title { flex: 1; font-size: 18px; }
.user-chip { font-weight: bold; font-size: 15px; padding: 6px 12px; background: #eef2ff;
  border-radius: 999px; color: var(--primary-dark); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-chips { display: flex; gap: 8px; }
.chip { padding: 6px 12px; border-radius: 999px; font-size: 13px; background: #fff; box-shadow: 0 2px 8px rgba(43,47,58,.08); white-space: nowrap; }
.chip-points { color: var(--gold); font-weight: bold; }
.chip-streak { color: #ff7a1a; }

/* 主页 */
.hero { display: flex; align-items: center; gap: 16px; background: linear-gradient(120deg, var(--primary), #8fa3ff);
  color: #fff; border-radius: 22px; padding: 20px; margin: 16px 0 24px; box-shadow: 0 10px 26px rgba(93,120,246,.3); }
.hero-emoji { font-size: 52px; animation: float 3s ease-in-out infinite; }
.hero-text h2 { font-size: 20px; margin-bottom: 4px; }
.hero-text p { font-size: 13px; opacity: .9; }
.section-title { font-size: 16px; margin: 18px 0 10px; color: #4a5168; }
.subject-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.subject-card { background: var(--card); border-radius: 18px; padding: 18px 14px; text-align: center;
  cursor: pointer; border: 3px solid transparent; box-shadow: 0 4px 14px rgba(43,47,58,.07); transition: all .15s; }
.subject-card .subject-emoji { display: block; font-size: 40px; margin-bottom: 6px; }
.subject-card b { font-size: 17px; display: block; margin-bottom: 4px; }
.subject-card small { color: var(--muted); font-size: 11px; }
.subject-card.selected { border-color: var(--primary); background: #f2f5ff; transform: translateY(-2px); }
.level-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.level-card { background: var(--card); border-radius: 18px; padding: 18px 10px; text-align: center;
  cursor: pointer; position: relative; box-shadow: 0 4px 14px rgba(43,47,58,.07); transition: all .15s; }
.level-card .lv-emoji { font-size: 34px; display: block; margin-bottom: 6px; }
.level-card b { font-size: 15px; display: block; margin-bottom: 3px; }
.level-card small { color: var(--muted); font-size: 11px; }
.level-card:hover { transform: translateY(-3px); }
.level-card.locked { filter: grayscale(1); opacity: .55; cursor: not-allowed; }
.level-card .lock { position: absolute; top: 8px; right: 10px; font-size: 16px; }
.level-card .need { color: var(--gold); font-size: 11px; display: block; margin-top: 4px; }
.home-btns { display: flex; gap: 12px; margin-top: 26px; }

/* 答题 */
.quiz-bar { display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  background: rgba(255,255,255,.85); position: sticky; top: 0; z-index: 5; }
.quiz-progress { flex: 1; height: 12px; background: #e3e8f7; border-radius: 999px; overflow: hidden; }
.quiz-progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), #8fa3ff); border-radius: 999px; transition: width .3s; }
.quiz-count { font-size: 13px; color: var(--muted); white-space: nowrap; }
.quiz-wrap { display: flex; flex-direction: column; gap: 14px; }
.quiz-tags { display: flex; gap: 8px; flex-wrap: wrap; }
.tag { padding: 5px 12px; border-radius: 999px; font-size: 12px; background: #eef2ff; color: var(--primary-dark); }
.tag-streak { background: #fff3e0; color: #ff7a1a; display: inline-flex; align-items: center; gap: 4px; }
.q-card { background: var(--card); border-radius: 22px; padding: 22px 18px; box-shadow: 0 8px 24px rgba(43,47,58,.08); }
.q-type { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.q-text { font-size: 18px; line-height: 1.6; margin-bottom: 16px; }
.q-options { display: flex; flex-direction: column; gap: 10px; }
.q-opt { display: flex; align-items: center; gap: 10px; padding: 13px 14px; border-radius: 14px;
  background: #f6f8ff; border: 2px solid transparent; font-size: 15px; text-align: left;
  transition: all .12s; }
.q-opt:hover { border-color: var(--primary); }
.q-opt.selected { border-color: var(--primary); background: #eef2ff; font-weight: bold; }
.q-opt .opt-letter { width: 26px; height: 26px; border-radius: 50%; background: var(--primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 13px; flex-shrink: 0; }
.q-opt.correct { background: #e9f9ec; border-color: var(--good); }
.q-opt.wrong { background: #fdeaea; border-color: var(--bad); }
.q-fill input { width: 100%; padding: 13px 16px; border: 2px solid #e3e7f5; border-radius: 14px;
  font-size: 16px; outline: none; }
.q-fill input:focus { border-color: var(--primary); }
#btn-submit { width: 100%; margin-top: 14px; }

/* 反馈 */
.feedback { background: var(--card); border-radius: 22px; padding: 22px 18px; text-align: center;
  box-shadow: 0 8px 24px rgba(43,47,58,.08); }
.face { font-size: 74px; line-height: 1.1; }
.face.pop { animation: facePop .6s cubic-bezier(.34,1.56,.64,1); }
@keyframes facePop { 0% { transform: scale(0) rotate(-30deg); } 100% { transform: scale(1) rotate(0); } }
.face.shake { animation: shake .5s; }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.fb-points { font-size: 26px; font-weight: bold; color: var(--gold); margin: 6px 0; }
.fb-points.float-up { animation: floatUp 1s ease-out; }
@keyframes floatUp { 0% { transform: translateY(0); opacity: 1; } 100% { transform: translateY(-26px); opacity: 0; } }
.fb-title { font-size: 19px; font-weight: bold; margin-bottom: 6px; }
.fb-correct { color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.fb-explain { background: #fff8e6; border-left: 4px solid var(--gold); padding: 12px 14px;
  border-radius: 10px; font-size: 14px; text-align: left; line-height: 1.7; margin-bottom: 14px; }
.fb-explain b { color: var(--gold); }
#btn-next { width: 100%; }

/* 结算 */
.summary { background: var(--card); border-radius: 22px; padding: 28px 20px; text-align: center;
  box-shadow: 0 8px 24px rgba(43,47,58,.08); }
.face.big { font-size: 90px; }
.summary h2 { margin: 10px 0 6px; }
.summary p { color: var(--muted); font-size: 14px; margin-bottom: 18px; }
.sum-stats { display: flex; gap: 10px; justify-content: center; margin-bottom: 16px; }
.sum-stat { background: #f6f8ff; border-radius: 14px; padding: 12px 18px; min-width: 84px; }
.sum-stat b { display: block; font-size: 22px; color: var(--primary); }
.sum-stat small { color: var(--muted); font-size: 11px; }
.sum-badges { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 16px; }
.sum-badge { background: linear-gradient(120deg, #fff6d8, #ffe9a8); border-radius: 12px; padding: 8px 12px;
  font-size: 13px; animation: facePop .5s; }

/* 勋章 */
.badge-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.badge-card { background: var(--card); border-radius: 18px; padding: 16px 10px; text-align: center;
  box-shadow: 0 4px 14px rgba(43,47,58,.07); }
.badge-card .b-emoji { font-size: 38px; display: block; margin-bottom: 6px; }
.badge-card b { font-size: 13px; display: block; margin-bottom: 4px; }
.badge-card small { color: var(--muted); font-size: 10px; line-height: 1.4; display: block; }
.badge-card.locked { filter: grayscale(1); opacity: .45; }

/* 排行榜 */
.rank-list { display: flex; flex-direction: column; gap: 10px; }
.rank-item { display: flex; align-items: center; gap: 12px; background: var(--card);
  border-radius: 16px; padding: 13px 16px; box-shadow: 0 4px 12px rgba(43,47,58,.06); }
.rank-medal { font-size: 24px; width: 34px; text-align: center; }
.rank-name { flex: 1; font-weight: bold; }
.rank-points { color: var(--gold); font-weight: bold; }
.rank-correct { color: var(--muted); font-size: 12px; margin-left: 6px; }
.rank-item.me { border: 2px solid var(--primary); background: #f2f5ff; }

/* 家长后台 */
.student-list { display: flex; flex-direction: column; gap: 12px; }
.student-card { background: var(--card); border-radius: 18px; padding: 16px;
  box-shadow: 0 4px 14px rgba(43,47,58,.07); cursor: pointer; }
.student-card .s-top { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.student-card .s-avatar { font-size: 32px; }
.student-card .s-name { flex: 1; font-weight: bold; font-size: 16px; }
.student-card .s-points { color: var(--gold); font-weight: bold; }
.student-card .s-meta { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.student-card .s-meta b { color: var(--text); }
.empty-hint { text-align: center; color: var(--muted); padding: 40px 0; font-size: 14px; }

.detail-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.dstat { background: var(--card); border-radius: 14px; padding: 14px 8px; text-align: center; box-shadow: 0 3px 10px rgba(43,47,58,.06); }
.dstat b { display: block; font-size: 20px; color: var(--primary); }
.dstat small { color: var(--muted); font-size: 11px; }
.detail-levels { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dlevel { background: var(--card); border-radius: 14px; padding: 12px 14px; box-shadow: 0 3px 10px rgba(43,47,58,.06); }
.dlevel .dl-title { font-size: 13px; font-weight: bold; margin-bottom: 6px; }
.dlevel .dl-bar { height: 8px; background: #e3e8f7; border-radius: 999px; overflow: hidden; margin-bottom: 5px; }
.dlevel .dl-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--primary), #8fa3ff); }
.dlevel .dl-num { font-size: 11px; color: var(--muted); }
.detail-badges { display: flex; flex-wrap: wrap; gap: 8px; }
.db { background: linear-gradient(120deg, #fff6d8, #ffe9a8); border-radius: 12px; padding: 7px 12px; font-size: 13px; }
.detail-recent { display: flex; flex-direction: column; gap: 8px; }
.recent-item { background: var(--card); border-radius: 12px; padding: 10px 12px; font-size: 13px;
  box-shadow: 0 2px 8px rgba(43,47,58,.05); line-height: 1.6; }
.recent-item .r-text { margin-bottom: 2px; }
.recent-item .r-meta { color: var(--muted); font-size: 11px; }
.recent-item.ok { border-left: 4px solid var(--good); }
.recent-item.no { border-left: 4px solid var(--bad); }

/* 错题本 */
.home-btns { flex-wrap: wrap; }
.home-btns .btn-secondary { min-width: 40%; position: relative; }
.home-btns .btn-wrong { background: linear-gradient(120deg, #fff0f0, #ffe1e1); }
.count-dot { display: inline-block; min-width: 20px; padding: 1px 6px; margin-left: 4px; border-radius: 999px;
  background: var(--bad); color: #fff; font-size: 12px; font-weight: bold; }
.wrong-hero { display: flex; align-items: center; gap: 14px; background: linear-gradient(120deg, #ff8a8a, #ffb36b);
  color: #fff; border-radius: 20px; padding: 16px 18px; margin: 16px 0; box-shadow: 0 8px 22px rgba(240,83,83,.25); }
.wrong-hero-emoji { font-size: 44px; animation: float 3s ease-in-out infinite; }
.wrong-hero b { font-size: 17px; }
.wrong-hero p { font-size: 13px; opacity: .92; margin-top: 3px; }
.wrong-tabs { margin-bottom: 10px; }
.filter-row { display: flex; gap: 8px; margin-bottom: 12px; }
.filter-btn { padding: 7px 14px; border-radius: 999px; font-size: 13px; background: var(--card);
  color: var(--muted); box-shadow: 0 2px 8px rgba(43,47,58,.06); }
.filter-btn.active { background: #eef2ff; color: var(--primary-dark); font-weight: bold; }
#btn-redo { width: 100%; margin-bottom: 14px; }
.wrong-list { display: flex; flex-direction: column; gap: 12px; }
.wrong-item { background: var(--card); border-radius: 18px; padding: 16px; border-left: 5px solid var(--bad);
  box-shadow: 0 4px 14px rgba(43,47,58,.07); }
.wrong-item.mastered { border-left-color: var(--good); }
.wi-head { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
.wi-count { background: #fdeaea; color: var(--bad); }
.wi-ok { background: #e9f9ec; color: var(--good); }
.wi-time { margin-left: auto; font-size: 11px; color: var(--muted); }
.wi-text { font-size: 15px; line-height: 1.6; margin-bottom: 8px; }
.wi-opts { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.wi-opt { padding: 8px 12px; border-radius: 10px; background: #f6f8ff; font-size: 13px; border: 2px solid transparent; }
.wi-opt.correct { background: #e9f9ec; border-color: var(--good); }
.wi-opt.wrong { background: #fdeaea; border-color: var(--bad); }
.wi-ans { font-size: 13px; margin-bottom: 8px; display: flex; gap: 14px; flex-wrap: wrap; }
.wi-ans .mine { color: var(--bad); }
.wi-ans .right { color: var(--good); }
.wi-toggle { font-size: 13px; color: var(--primary); padding: 4px 0; }
.wi-explain { margin: 8px 0 0; }
.fb-wrongnote { font-size: 12px; color: var(--bad); margin-bottom: 8px; }

/* 提示与彩带 */
#toast-wrap { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 99;
  display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #333; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px;
  box-shadow: 0 6px 18px rgba(0,0,0,.25); animation: toastIn .3s; max-width: 90vw; }
.toast.badge-toast { background: linear-gradient(120deg, #f5a623, #ffd15c); color: #5a3b00; font-weight: bold; }
@keyframes toastIn { from { transform: translateY(-16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
#confetti-wrap { position: fixed; inset: 0; pointer-events: none; z-index: 98; overflow: hidden; }
.confetti-piece { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 3px;
  animation: confettiFall linear forwards; }
@keyframes confettiFall { to { transform: translateY(110vh) rotate(720deg); } }

@media (max-width: 480px) {
  .level-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .badge-grid { grid-template-columns: repeat(2, 1fr); }
  .q-text { font-size: 16px; }
}
