/* ============================================================
   三年级数学小达人 - 云端版
   儿童友好配色 + 响应式双端适配
============================================================ */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #FFF9F0;
  --card: #FFFFFF;
  --primary: #4F8EF7;
  --primary-dark: #3A6FD0;
  --accent: #FFB83D;
  --accent-dark: #E89A1F;
  --success: #3DBE8B;
  --danger: #FF6B6B;
  --purple: #9B7BF7;
  --text: #2D3748;
  --text-light: #718096;
  --border: #E8EDF2;
  --shadow: 0 4px 12px rgba(79, 142, 247, 0.08);
  --shadow-lg: 0 8px 24px rgba(79, 142, 247, 0.16);
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
  min-height: 100vh;
}

.container {
  max-width: 780px;
  margin: 0 auto;
  padding: 16px;
}

.hidden { display: none !important; }

/* ============ 登录页 ============ */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #4F8EF7 0%, #6BA8FF 50%, #9B7BF7 100%);
}
.login-card {
  background: white;
  border-radius: 24px;
  padding: 32px 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}
.login-logo {
  text-align: center;
  font-size: 26px;
  font-weight: 800;
  margin-bottom: 6px;
  color: var(--primary);
}
.login-sub {
  text-align: center;
  color: var(--text-light);
  font-size: 13px;
  margin-bottom: 24px;
}
.role-switch {
  display: flex;
  gap: 8px;
  background: #F0F4F8;
  padding: 4px;
  border-radius: 14px;
  margin-bottom: 20px;
}
.role-btn {
  flex: 1;
  padding: 12px;
  border: none;
  background: transparent;
  border-radius: 11px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-light);
  cursor: pointer;
  min-height: 48px;
  transition: all 0.2s;
}
.role-btn.active {
  background: white;
  color: var(--primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
.form-group { margin-bottom: 16px; }
.form-label {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  display: block;
  color: var(--text);
}
.form-input {
  width: 100%;
  padding: 14px;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 16px;
  font-family: inherit;
}
.form-input:focus { outline: none; border-color: var(--primary); }
.form-hint { font-size: 11px; color: var(--text-light); margin-top: 4px; }

/* ============ 按钮 ============ */
.btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 14px 20px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  min-height: 50px;
  width: 100%;
  font-family: inherit;
  transition: all 0.2s;
}
.btn:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-secondary { background: var(--accent); }
.btn-secondary:hover { background: var(--accent-dark); }
.btn-success { background: var(--success); }
.btn-danger { background: var(--danger); }
.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
}
.btn-outline:hover { background: var(--primary); color: white; }
.btn-sm { padding: 10px 16px; font-size: 13px; min-height: 40px; width: auto; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============ 顶部 ============ */
.header {
  background: linear-gradient(135deg, #4F8EF7 0%, #6BA8FF 100%);
  color: white;
  padding: 18px 16px;
  border-radius: 20px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-lg);
}
.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.header-title {
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.header-actions { display: flex; gap: 8px; align-items: center; }
.header-chip {
  background: rgba(255, 255, 255, 0.22);
  padding: 6px 12px;
  border-radius: 18px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  cursor: pointer;
}
.header-chip:hover { background: rgba(255, 255, 255, 0.32); }
.header-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.hstat {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  padding: 10px 6px;
  text-align: center;
}
.hstat-num { font-size: 18px; font-weight: 800; line-height: 1.2; }
.hstat-label { font-size: 10px; opacity: 0.9; margin-top: 2px; }

/* ============ Tab ============ */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  overflow-x: auto;
  padding: 4px;
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1;
  min-width: 68px;
  padding: 11px 6px;
  text-align: center;
  background: transparent;
  border: none;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-light);
  cursor: pointer;
  min-height: 48px;
  white-space: nowrap;
  transition: all 0.2s;
  font-family: inherit;
}
.tab.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 8px rgba(79, 142, 247, 0.3);
}

/* ============ 卡片 ============ */
.card {
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.card-meta { font-size: 12px; color: var(--text-light); font-weight: 500; }

/* ============ 今日待办 ============ */
.today-card {
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--accent);
}
.today-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.today-badge {
  background: var(--accent);
  color: white;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
}
.today-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: #FFF5E6;
  border-radius: 12px;
  font-size: 14px;
  margin-bottom: 8px;
  gap: 10px;
}
.today-item.overdue { background: #FFE9E9; border-left: 3px solid var(--danger); }
.today-item-action {
  background: var(--primary);
  color: white;
  border: none;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
  min-height: 36px;
  font-weight: 600;
  white-space: nowrap;
  font-family: inherit;
}
.today-item-action:hover { background: var(--primary-dark); }
.today-empty { text-align: center; color: var(--text-light); padding: 14px; font-size: 13px; }

/* ============ 知识点网格 ============ */
.kgrid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (min-width: 620px) { .kgrid { grid-template-columns: repeat(3, 1fr); } }
.kcard {
  background: linear-gradient(135deg, #F0F7FF 0%, #E4F0FF 100%);
  border-radius: 14px;
  padding: 14px 10px;
  text-align: center;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s;
  min-height: 108px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  position: relative;
}
.kcard:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.kcard.mastered { border-color: var(--success); background: linear-gradient(135deg, #E6FBF2 0%, #D2F5E4 100%); }
.kcard.weak { border-color: var(--danger); background: linear-gradient(135deg, #FFF0F0 0%, #FFE2E2 100%); }
.kcard.inprogress { border-color: var(--accent); }
.kicon { width: 36px; height: 36px; }
.kname { font-size: 14px; font-weight: 700; }
.klevel {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 9px;
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(155, 123, 247, 0.15);
  color: var(--purple);
  font-weight: 700;
}
.kstatus { font-size: 11px; color: var(--text-light); }
.kcard.mastered .kstatus { color: var(--success); font-weight: 700; }
.kcard.weak .kstatus { color: var(--danger); font-weight: 700; }
.krate {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.05);
}

/* ============ 答题 ============ */
.quiz-box {
  background: var(--card);
  border-radius: 20px;
  padding: 22px 18px;
  box-shadow: var(--shadow-lg);
}
.quiz-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--text-light);
}
.quiz-bar {
  height: 7px;
  background: #EDF2F7;
  border-radius: 4px;
  margin-bottom: 18px;
  overflow: hidden;
}
.quiz-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--success));
  transition: width 0.3s;
  border-radius: 4px;
}
.quiz-q {
  font-size: 21px;
  font-weight: 700;
  text-align: center;
  margin: 20px 0 18px;
  line-height: 1.5;
  color: var(--text);
}
.quiz-input {
  width: 100%;
  padding: 15px;
  font-size: 24px;
  text-align: center;
  border: 2px solid var(--border);
  border-radius: 12px;
  margin-bottom: 14px;
  font-weight: 700;
  font-family: inherit;
}
.quiz-input:focus { outline: none; border-color: var(--primary); }
.quiz-fb {
  text-align: center;
  padding: 14px;
  border-radius: 12px;
  margin: 10px 0;
  font-size: 15px;
  font-weight: 600;
}
.quiz-fb.correct { background: #E6FBF2; color: var(--success); }
.quiz-fb.wrong { background: #FFECEC; color: var(--danger); }
.quiz-exp {
  background: #F7FAFF;
  border-left: 3px solid var(--primary);
  padding: 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.7;
  margin: 10px 0;
  color: var(--text);
  text-align: left;
}
.quiz-exp-title { font-weight: 700; color: var(--primary); margin-bottom: 4px; font-size: 12px; }
.timer {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #FFF3E0;
  padding: 4px 10px;
  border-radius: 8px;
  font-weight: 700;
  color: var(--accent-dark);
}

/* ============ 错题 ============ */
.wrong-item {
  background: #FFF6F6;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 8px;
  border-left: 3px solid var(--danger);
}
.wrong-item.mastered { background: #F0FBF5; border-left-color: var(--success); opacity: 0.75; }
.wrong-q { font-size: 16px; font-weight: 700; margin-bottom: 6px; line-height: 1.5; }
.wrong-a { font-size: 13px; color: var(--text-light); line-height: 1.6; }
.wrong-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  gap: 8px;
  flex-wrap: wrap;
}
.wrong-tag {
  background: var(--primary);
  color: white;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
}
.wrong-times {
  background: var(--danger);
  color: white;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
}

/* ============ 诊断 ============ */
.sug-item {
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 8px;
  font-size: 14px;
  line-height: 1.7;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.sug-urgent { background: #FFF0F0; border-left: 3px solid var(--danger); }
.sug-normal { background: #FFF8E8; border-left: 3px solid var(--accent); }
.sug-good { background: #E9FBF3; border-left: 3px solid var(--success); }
.sug-icon { flex-shrink: 0; margin-top: 2px; }

.weak-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid #F0F4F8;
}
.weak-rank {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--danger);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  flex-shrink: 0;
}
.weak-rank.r2 { background: var(--accent); }
.weak-rank.r3 { background: var(--purple); }
.weak-name { font-size: 14px; font-weight: 600; width: 96px; flex-shrink: 0; }
.weak-bar {
  flex: 1;
  height: 9px;
  background: #EDF2F7;
  border-radius: 5px;
  overflow: hidden;
}
.weak-fill { height: 100%; border-radius: 5px; }
.weak-num { font-size: 12px; color: var(--text-light); width: 88px; text-align: right; flex-shrink: 0; }

/* ============ 奖励 ============ */
.rgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 620px) { .rgrid { grid-template-columns: repeat(3, 1fr); } }
.rcard {
  background: linear-gradient(135deg, #FFF6E5 0%, #FFE9CC 100%);
  border-radius: 14px;
  padding: 14px 10px;
  text-align: center;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s;
  min-height: 116px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.rcard:hover:not(.locked) { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.rcard.locked { opacity: 0.45; cursor: not-allowed; background: #F5F5F5; }
.ricon { width: 38px; height: 38px; }
.rname { font-size: 13px; font-weight: 700; }
.rcost { font-size: 12px; color: var(--accent-dark); font-weight: 800; }

/* ============ 成长档案 ============ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.stat-box {
  background: linear-gradient(135deg, #F0F7FF 0%, #E4F0FF 100%);
  border-radius: 14px;
  padding: 14px 8px;
  text-align: center;
}
.stat-num { font-size: 22px; font-weight: 800; color: var(--primary); line-height: 1.2; }
.stat-label { font-size: 11px; color: var(--text-light); margin-top: 3px; }

/* ============ 表格 ============ */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: left;
  padding: 9px 8px;
  border-bottom: 2px solid var(--border);
  color: var(--text-light);
  font-size: 12px;
  font-weight: 600;
}
.tbl td { padding: 9px 8px; border-bottom: 1px solid #F0F4F8; }
.tbl tr:last-child td { border-bottom: none; }

/* ============ 弹窗 ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}
.modal {
  background: white;
  border-radius: 20px;
  padding: 22px;
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  margin: auto;
}
.modal-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-close {
  background: #F0F4F8;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 19px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ============ 提示条 ============ */
.alert {
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 12px;
  line-height: 1.6;
}
.alert-warn { background: #FFF4E5; color: #B7791F; border-left: 3px solid var(--accent); }
.alert-error { background: #FFEBEB; color: #C53030; border-left: 3px solid var(--danger); }
.alert-ok { background: #E9FBF3; color: #2F855A; border-left: 3px solid var(--success); }

/* ============ 加载 ============ */
.loading {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-light);
}
.spinner {
  border: 3px solid #E8EDF2;
  border-top: 3px solid var(--primary);
  border-radius: 50%;
  width: 34px;
  height: 34px;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* ============ 空状态 ============ */
.empty {
  text-align: center;
  color: var(--text-light);
  padding: 26px 16px;
  font-size: 13px;
  line-height: 1.7;
}

/* ============ 移动端 ============ */
@media (max-width: 520px) {
  .container { padding: 12px; }
  .header { padding: 14px 12px; border-radius: 16px; }
  .header-title { font-size: 17px; }
  .hstat-num { font-size: 16px; }
  .quiz-q { font-size: 18px; }
  .kgrid { grid-template-columns: repeat(2, 1fr); }
  .weak-name { width: 76px; font-size: 13px; }
  .weak-num { width: 68px; font-size: 11px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .tab { font-size: 12px; min-width: 60px; padding: 10px 4px; }
}
