:root {
  --bg: #FFF6E9;
  --ink: #4B3A2E;
  --muted: #9A8574;
  --card: #FFFFFF;
  --primary: #FF8A3D;
  --primary-dark: #F06F1F;
  --green: #35C28C;
  --red: #FF6B6B;
  --math: #4D96FF;
  --shadow: 0 8px 24px rgba(120, 80, 20, .12);
  --radius: 22px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(600px 300px at 90% -40px, #FFE0B8 0%, transparent 60%),
    radial-gradient(500px 260px at -60px 20%, #D9ECFF 0%, transparent 55%),
    var(--bg);
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  position: relative;
  padding-bottom: env(safe-area-inset-bottom);
}

.screen { display: none; flex-direction: column; padding: 20px 18px 30px; min-height: 100vh; }
.screen.active { display: flex; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.hidden { display: none !important; }

/* 顶部条 */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 0 14px; position: relative;
}
.topbar h2 { margin: 0; font-size: 20px; flex: 1; text-align: center; }
.back {
  width: 42px; height: 42px; border: none; border-radius: 50%;
  background: #fff; font-size: 26px; line-height: 1; color: var(--ink);
  box-shadow: var(--shadow); cursor: pointer; flex: none;
}
.back:active { transform: scale(.94); }

/* 首页 */
.hero { text-align: center; padding: 46px 8px 10px; }
.mascot {
  width: 118px; height: 118px; margin: 0 auto 14px; border-radius: 50%;
  background: #fff; font-size: 62px; line-height: 118px; text-align: center;
  box-shadow: var(--shadow); animation: float 3.2s ease-in-out infinite;
}
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.hero h1 { margin: 4px 0 2px; font-size: 34px; letter-spacing: 2px; }
.slogan { margin: 0; color: var(--muted); font-size: 15px; }
.kid-line { margin-top: 12px; font-size: 17px; font-weight: 700; min-height: 24px; }

.home-actions { margin-top: auto; display: flex; flex-direction: column; gap: 12px; padding-top: 30px; }
.home-sub { display: flex; gap: 12px; }
.home-sub .btn { flex: 1; }
.home-tip {
  margin-top: 18px; text-align: center; font-size: 12px; color: var(--muted);
  background: rgba(255,255,255,.6); border-radius: 12px; padding: 8px;
}

/* 按钮 */
.btn {
  border: none; border-radius: 999px; font-size: 17px; cursor: pointer;
  font-family: inherit; color: var(--ink);
  transition: transform .08s ease, box-shadow .2s ease;
}
.btn:active { transform: scale(.96); }
.btn-big { padding: 17px 18px; font-size: 19px; font-weight: 800; }
.btn-primary { background: linear-gradient(135deg, #FF9A50, #FF7A2F); color: #fff; box-shadow: 0 10px 22px rgba(255,122,47,.35); }
.btn-soft { background: #fff; box-shadow: var(--shadow); padding: 12px 10px; font-weight: 700; }
.btn-round { background: #fff; box-shadow: var(--shadow); padding: 11px 18px; font-weight: 700; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* 网格卡片 */
.grid { display: flex; flex-direction: column; gap: 14px; }
.pick-card {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 18px; display: flex; align-items: center; gap: 16px;
  cursor: pointer; border: 3px solid transparent; text-align: left;
}
.pick-card:active { transform: scale(.98); }
.pick-card.locked { opacity: .75; }
.pick-icon {
  width: 66px; height: 66px; border-radius: 20px; flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 38px;
  background: #EEF4FF; color: #fff;
}
.pick-body { flex: 1; }
.pick-body b { display: block; font-size: 21px; margin-bottom: 4px; }
.pick-body span { font-size: 13px; color: var(--muted); }
.pick-arrow { font-size: 28px; color: #D9C9BA; }
.badge-on {
  background: #E7F9F0; color: #189A67; font-size: 12px; font-weight: 800;
  border-radius: 999px; padding: 4px 10px; white-space: nowrap;
}
.badge-off { background: #F4EFE9; color: var(--muted); font-size: 12px; font-weight: 800; border-radius: 999px; padding: 4px 10px; white-space: nowrap; }
.unit-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.unit-actions .btn { font-size: 12px; padding: 6px 10px; background: #FFF1E3; color: var(--primary-dark); }
.unit-actions .btn.alt { background: #F1F5FF; color: #3A6FD8; }

/* 学期选择 */
.semester-chips { display: flex; gap: 10px; margin: 4px 0 14px; }
.semester-chips .btn { flex: 1; padding: 12px; font-weight: 800; background: #fff; box-shadow: var(--shadow); }
.semester-chips .btn.active { background: var(--primary); color: #fff; box-shadow: 0 8px 18px rgba(255,138,61,.35); }
.semester-chips .btn:disabled { opacity: .45; }

/* 单元列表 */
.unit-list { display: flex; flex-direction: column; gap: 12px; }
.unit-card {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; display: flex; align-items: center; gap: 14px; cursor: pointer;
  border: 3px solid transparent;
}
.unit-card:active { transform: scale(.98); }
.unit-card.locked { opacity: .68; cursor: not-allowed; }
.unit-no {
  width: 46px; height: 46px; border-radius: 15px; flex: none;
  background: #FFF1E3; color: var(--primary-dark); font-weight: 900; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
}
.unit-body { flex: 1; }
.unit-body b { display: block; font-size: 17px; margin-bottom: 3px; line-height: 1.35; }
.unit-body span { font-size: 12px; color: var(--muted); }

.progress-track {
  height: 8px; background: #F0E5D8; border-radius: 999px; overflow: hidden; margin-top: 8px;
}
.progress-fill {
  height: 100%; border-radius: 999px; width: 0;
  background: linear-gradient(90deg, #FFB25C, #FF7A2F); transition: width .4s ease;
}
.unit-body .progress-track { max-width: 220px; }
.unit-body .progress-label { font-size: 11px; color: var(--muted); margin-top: 4px; }

.semester-progress {
  background: #fff; border-radius: 16px; box-shadow: var(--shadow);
  padding: 10px 14px; margin: 2px 0 12px;
}
.semester-progress .progress-track { margin: 6px 0 2px; }
.semester-progress .progress-label { font-size: 12px; color: var(--muted); }

.coming-card {
  background: #fff8; border: 2px dashed #E7D8C8; border-radius: var(--radius);
  padding: 26px 20px; text-align: center; color: var(--muted);
}
.coming-card b { display: block; font-size: 18px; color: var(--ink); margin: 8px 0 4px; }

/* 练习设置 */
.setup-card {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 26px 22px; text-align: center; margin-top: 12px;
}
.setup-icon { font-size: 48px; }
.setup-card h3 { margin: 8px 0 4px; font-size: 21px; }
.setup-card p { color: var(--muted); margin: 0 0 18px; font-size: 14px; line-height: 1.7; }
.setup-actions { display: flex; flex-direction: column; gap: 12px; }
.setup-actions .btn { width: 100%; }
.setup-danger { background: #FFE9EC !important; color: #C93A4C !important; }
.setup-note { margin-top: 16px; font-size: 12px; color: var(--muted); line-height: 1.8; background: #FFF9F0; border-radius: 12px; padding: 10px 12px; }

/* 练习页 */
.topbar-practice { gap: 8px; }
.pbar { flex: 1; height: 12px; background: #F0E5D8; border-radius: 999px; overflow: hidden; }
.pbar-fill { height: 100%; width: 0; background: linear-gradient(90deg, #FFB25C, #FF7A2F); border-radius: 999px; transition: width .3s ease; }
.pstats { font-size: 16px; font-weight: 900; white-space: nowrap; }
.practice-scroll { flex: 1; padding-bottom: 20px; }

.q-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.chip {
  font-size: 12px; font-weight: 800; padding: 5px 11px; border-radius: 999px;
  background: #FFF; color: var(--muted); box-shadow: 0 2px 8px rgba(120,80,20,.08);
}
.chip.type-basic { background: #E8F2FF; color: #2C6FD1; }
.chip.type-life { background: #FFF1DE; color: #C4660C; }
.chip.type-vary { background: #F3E8FF; color: #8B3FD8; }
.chip.type-fun { background: #FFF4D6; color: #B8860B; }
.chip.type-more { background: #FFE9EC; color: #D63A52; }
.stars { color: #FFB300; font-size: 16px; letter-spacing: 2px; }

.q-card {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; min-height: 150px; display: flex; gap: 14px; align-items: flex-start;
}
.q-main { flex: 1; min-width: 0; }
.teacher-avatar {
  width: 112px; height: 112px; flex: none;
  filter: drop-shadow(0 6px 10px rgba(160, 100, 40, .18));
}
.teacher-avatar .mouth-open {
  opacity: 0;
  transform-box: fill-box; transform-origin: center;
}
.teacher-avatar.talking .mouth-closed { opacity: 0; }
.teacher-avatar.talking .mouth-open {
  opacity: 1;
  animation: mouth-talk .34s ease-in-out infinite alternate;
}
@keyframes mouth-talk {
  from { transform: scaleY(.15); }
  to { transform: scaleY(1.05); }
}
.q-image {
  text-align: center; font-size: 46px; letter-spacing: 8px; line-height: 1.4;
  padding: 10px 0 6px; min-height: 20px; background: #FFFBF3;
  border-radius: 16px; margin-bottom: 12px; display: none;
}
.q-stem { font-size: 21px; line-height: 1.65; font-weight: 700; }

.sound-bar { display: flex; gap: 10px; margin: 12px 0; }
.sound-bar .btn { flex: 1; }

.answer-zone { margin: 6px 0 10px; }
.wrong-toggle-row { text-align: left; margin-bottom: 8px; }
.wrong-toggle-row button {
  background: #FFF7F0; border: 2px solid #F3D9C2; color: #B46A2E;
  font-size: 13px; font-weight: 800; padding: 7px 14px; border-radius: 999px; cursor: pointer;
}
.wrong-toggle-row button.in { background: #E7F9F0; border-color: #A7E3C4; color: #128A5B; }
.opt-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opt {
  background: #fff; border: 3px solid #EFE2D2; border-radius: 18px; padding: 15px 10px;
  font-size: 22px; font-weight: 800; cursor: pointer; font-family: inherit;
}
.opt:active { transform: scale(.96); }
.opt.correct { background: #E3F9EE; border-color: var(--green); color: #128A5B; animation: pop .35s ease; }
.opt.wrong { background: #FFE9EC; border-color: var(--red); color: #C93A4C; }
.opt-list.single { grid-template-columns: 1fr; }
@keyframes pop { 40% { transform: scale(1.08); } }

.mic-box {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; text-align: center;
}
.mic-line {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  flex-wrap: wrap; margin-bottom: 8px;
}
.mic-line .mic-btn {
  width: 76px; height: 76px; font-size: 36px; flex: none;
}
.mic-line .mic-hint { margin: 0; text-align: left; font-size: 14px; }
.mic-line-choice {
  justify-content: flex-start; background: #fff; border: 2px solid #EFE2D2;
  border-radius: 16px; padding: 6px 12px; margin-top: 10px;
}
.mic-line-choice .mic-btn {
  width: 50px; height: 50px; font-size: 24px;
  box-shadow: 0 6px 14px rgba(255,111,61,.3); margin-left: auto;
}
.mic-line-choice .mic-hint { font-size: 13px; }
.mic-btn {
  width: 96px; height: 96px; border-radius: 50%; border: none; cursor: pointer;
  background: linear-gradient(135deg, #FF9A50, #FF6F3D); color: #fff; font-size: 44px;
  box-shadow: 0 10px 24px rgba(255,111,61,.4);
  display: flex; align-items: center; justify-content: center;
  line-height: 1; white-space: nowrap;
}
.mic-btn.listening { animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.09); } }
.mic-hint { color: var(--muted); font-size: 13px; margin: 10px 0 4px; }
.mic-text { min-height: 24px; font-size: 17px; font-weight: 800; color: var(--primary-dark); }
.pad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 12px; }
.pad button {
  padding: 13px 0; font-size: 22px; font-weight: 900; border-radius: 14px;
  border: 2px solid #EFE2D2; background: #fff; color: var(--ink); cursor: pointer; font-family: inherit;
}
.pad button.special { font-size: 14px; }
.pad button:active { transform: scale(.94); }

.teacher-bubble {
  background: #fff; border-radius: 18px 18px 18px 4px; box-shadow: var(--shadow);
  padding: 14px 16px; margin: 12px 0; font-size: 17px; line-height: 1.7;
  border-left: 5px solid var(--primary); min-height: 30px;
}
.teacher-bubble .t-role { font-weight: 900; color: var(--primary-dark); margin-right: 6px; }
.teacher-bubble small { display: block; margin-top: 6px; font-size: 12px; color: var(--muted); }
.teacher-bubble .again { display: block; margin-top: 8px; font-size: 14px; color: var(--red); font-weight: 800; }

.next-zone { text-align: center; }
.next-zone .btn { min-width: 220px; }
.next-zone .skip-btn { background: #F4EFE9; color: var(--muted); box-shadow: none; }

/* 完成页 */
.screen-done-wrap { justify-content: center; }
.done-card {
  background: #fff; border-radius: 28px; box-shadow: var(--shadow); padding: 36px 26px;
  text-align: center; margin: auto 0;
}
.big-stars { font-size: 52px; letter-spacing: 10px; }
.done-card h2 { margin: 10px 0 6px; font-size: 26px; }
.done-stats { color: var(--muted); font-size: 16px; line-height: 2; margin-bottom: 8px; }

/* 错题本 */
.wrong-list { display: flex; flex-direction: column; gap: 12px; }
.wrong-item {
  background: #fff; border-radius: 18px; box-shadow: var(--shadow);
  padding: 14px 16px; display: flex; gap: 12px; align-items: center;
}
.wrong-item .w-stem { flex: 1; font-size: 15px; line-height: 1.5; }
.wrong-item .btn { flex: none; padding: 9px 14px; font-size: 14px; }
.empty-tip { text-align: center; padding: 60px 20px; font-size: 20px; color: var(--muted); }

/* 家长报告 */
.report-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.rep-card {
  background: #fff; border-radius: 18px; box-shadow: var(--shadow);
  padding: 16px 8px; text-align: center;
}
.rep-card b { display: block; font-size: 24px; color: var(--primary-dark); }
.rep-card span { font-size: 12px; color: var(--muted); }
.rep-section { background: #fff; border-radius: 18px; box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.rep-section h3 { margin: 0 0 10px; font-size: 16px; }
.rep-section li { font-size: 14px; line-height: 2; color: var(--ink); }
.report-actions { text-align: center; margin-top: 6px; }
.grade-reset-row { display: flex; gap: 10px; justify-content: center; margin-bottom: 10px; }
.grade-reset-row .btn { flex: 1; max-width: 220px; }

/* 设置 */
.setting-group { background: #fff; border-radius: 18px; box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.setting-group > label { display: block; font-size: 14px; font-weight: 900; color: var(--muted); margin-bottom: 10px; }
#input-nickname {
  width: 100%; border: 2px solid #EFE2D2; border-radius: 14px; padding: 13px;
  font-size: 18px; font-family: inherit; outline: none; background: #FFFBF5;
}
.voice-select {
  width: 100%; border: 2px solid #EFE2D2; border-radius: 14px; padding: 12px;
  font-size: 15px; font-family: inherit; background: #FFFBF5; margin-bottom: 12px;
  color: var(--ink);
}
.style-cards { display: flex; gap: 10px; }
.style-card {
  flex: 1; background: #FFFBF5; border: 3px solid #EFE2D2; border-radius: 16px;
  padding: 14px 10px; text-align: center; cursor: pointer; font-family: inherit;
}
.style-card.active { border-color: var(--primary); background: #FFF3E6; }
.style-icon { font-size: 30px; }
.style-card b { display: block; margin: 6px 0 4px; color: var(--ink); }
.style-card p { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.switch-row span { font-size: 15px; }
.switch { position: relative; width: 54px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; background: #E3D5C5; border-radius: 999px;
  transition: .2s; cursor: pointer;
}
.switch span::before {
  content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .2s;
}
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::before { transform: translateX(24px); }
.setting-note { font-size: 12px; color: var(--muted); line-height: 1.7; margin: 0 4px 16px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%);
  background: rgba(60, 44, 34, .92); color: #fff; padding: 12px 22px; border-radius: 999px;
  font-size: 15px; z-index: 99; max-width: 84vw; text-align: center;
  animation: fade .2s ease;
}

/* 学科主题色 */
.subject-chinese .pick-icon { background: #FF6B6B; }
.subject-math .pick-icon { background: #4D96FF; }
.subject-english .pick-icon { background: #8B6BFF; }
.subject-science .pick-icon { background: #2FBF8F; }

/* ========== 平板 / 电脑宽屏适配：内容一屏放得下 ========== */
@media (min-width: 700px) {
  #app { max-width: 1060px; }
  .screen { padding: 12px 24px 14px; }

  /* 年级 / 学科 / 单元：多列排布，减少纵向长度 */
  .grade-grid, .subject-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
  .subject-grid { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
  .unit-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .semester-chips { max-width: 420px; }

  /* 首页：横向紧凑 */
  .hero { padding: 12px 8px 4px; display: flex; align-items: center; gap: 20px; justify-content: center; }
  .hero .mascot { margin: 0; flex: none; }
  .hero h1 { font-size: 30px; }
  .home-actions { margin-top: 8px; }
  .home-sub { justify-content: center; }

  /* 练习页：两栏布局，一屏完成 */
  .practice-scroll {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr);
    grid-template-areas:
      "meta   sound"
      "qcard  teacher"
      "answer teacher"
      "next   teacher";
    gap: 10px 16px;
    align-items: start;
  }
  .q-meta { grid-area: meta; margin-bottom: 0; }
  .q-card { grid-area: qcard; min-height: 120px; }
  .sound-bar { grid-area: sound; margin: 0; align-items: center; }
  .answer-zone { grid-area: answer; margin: 0; }
  .teacher-bubble { grid-area: teacher; margin: 0; min-height: 150px; }
  .next-zone { grid-area: next; text-align: left; }
  .opt-list { grid-template-columns: repeat(3, 1fr); }

  /* 设置页两栏 */
  #screen-settings.active { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; align-content: start; }
  #screen-settings .topbar { grid-column: 1 / -1; }
  #screen-settings .setting-group { margin-bottom: 10px; }
  #screen-settings .setting-note { grid-column: 1 / -1; }
  #screen-settings .btn-big { grid-column: 1 / -1; }

  /* 家长报告卡片自动铺开 */
  .report-cards { max-width: 640px; }
  .rep-section { max-width: 760px; }

  /* 屏幕高度有限时进一步压缩留白 */
  @media (max-height: 860px) {
    .hero .mascot { width: 84px; height: 84px; font-size: 44px; line-height: 84px; }
    .hero h1 { font-size: 26px; margin: 0; }
    .btn-big { padding: 12px 16px; font-size: 17px; }
    .pick-card { padding: 12px 14px; }
    .pick-icon { width: 54px; height: 54px; font-size: 30px; border-radius: 15px; }
    .unit-card { padding: 10px 12px; }
    .q-card { padding: 14px 16px; }
    .q-stem { font-size: 18px; }
    .teacher-avatar { width: 92px; height: 92px; }
    .opt { padding: 9px 8px; font-size: 18px; }
    .teacher-bubble { padding: 10px 12px; font-size: 15px; }
    .done-card { padding: 22px 24px; }
    #screen-settings.active .setting-group { padding: 8px 12px; margin-bottom: 4px; }
    #screen-settings.active { padding-top: 6px; padding-bottom: 2px; }
    #screen-settings .topbar { padding-bottom: 4px; }
    #screen-settings .voice-select { padding: 7px; margin-bottom: 6px; }
    #screen-settings .btn-big { padding: 8px 14px; }
    #screen-settings .btn-soft { padding: 8px 10px; }
    #screen-settings #input-nickname { padding: 8px 10px; }
    #screen-settings .setting-note { margin: 0 4px 8px; }
  }
}
