:root {
  --bg: #fff7e6;
  --card: #ffffff;
  --ink: #2c2c2a;
  --muted: #888780;
  --orange: #ff8a3d;
  --orange-d: #e8533f;
  --teal: #1d9e75;
  --blue: #378add;
  --green: #639922;
  --pink: #d4537e;
  --radius: 20px;
  --tap: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  overflow: hidden;
}

#app { height: 100%; position: relative; }

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: max(16px, env(safe-area-inset-top)) 16px 16px;
  gap: 14px;
}
.screen.active { display: flex; }

/* 首页 */
#screen-home { align-items: center; justify-content: center; text-align: center; }
.app-title { font-size: 13vw; margin: 0; color: var(--orange-d); letter-spacing: 2px; }
.app-sub { font-size: 5vw; color: var(--muted); margin: 0 0 6vh; }
.home-buttons { display: flex; gap: 20px; justify-content: center; align-items: center; }
.parent-btn {
  position: absolute; top: max(16px, env(safe-area-inset-top)); right: 16px;
  border: none; background: #ffe6cc; color: var(--orange-d);
  font-size: 16px; padding: 8px 16px; border-radius: 999px;
}

.big-btn {
  border: none; border-radius: var(--radius);
  color: #fff;
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  font-weight: 700;
  box-shadow: 0 8px 0 rgba(0,0,0,0.12);
  transition: transform .08s;
  display: flex; align-items: center; justify-content: center;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 4px 0 rgba(0,0,0,0.12); }
.big-btn.learn { background: var(--teal); }
.big-btn.math { background: var(--blue); }
.big-btn.pinyin { background: var(--pink); }
.big-btn.next { background: var(--orange); min-height: var(--tap); min-width: 60%; font-size: 24px; margin: 8px auto 0; }

/* --- 首页按钮响应式 --- */

/* 手机竖屏 (<=480px): 单列纵向排列 */
@media (max-width: 480px) and (orientation: portrait) {
  .home-buttons { flex-direction: column; width: 100%; padding: 0 24px; }
  .big-btn:not(.next) { width: 100%; max-width: 320px; height: 36vw; max-height: 160px; font-size: 10vw; }
}

/* 手机横屏 / 小平板竖屏 (481~768px): 两列 */
@media (min-width: 481px) and (max-width: 768px) {
  .home-buttons { flex-wrap: wrap; }
  .big-btn:not(.next) { width: calc(50% - 10px); min-width: 140px; height: 28vw; max-height: 180px; font-size: clamp(24px,6vw,42px); }
}

/* 平板竖屏 (769~1024px): 两列或三列紧凑 */
@media (min-width: 769px) and (max-width: 1024px) and (orientation: portrait) {
  .home-buttons { flex-wrap: nowrap; }
  .big-btn:not(.next) { width: 30vw; height: 30vw; max-width: 220px; max-height: 220px; font-size: clamp(22px,5vw,40px); }
}

/* 平板横屏 / PC (>=768px landscape 或 >=1024px): 三列等宽 */
@media (min-width: 769px) and (orientation: landscape), (min-width: 1025px) {
  .home-buttons { flex-wrap: nowrap; }
  .big-btn:not(.next) { width: 200px; height: 200px; max-width: 220px; max-height: 220px; font-size: 38px; }
}

/* 顶栏 */
.bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; flex: none; }
/* 正文滚动区：顶栏固定，内容可上下滑（触屏原生滑动），解决小屏内容被裁 */
.screen-body {
  flex: 1; min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; align-items: center;
  gap: 14px; padding: 14px 0 16px;
}
.bar-title { font-size: 20px; font-weight: 700; }
.back {
  border: none; background: #ffe6cc; color: var(--orange-d);
  font-size: 18px; padding: 10px 18px; border-radius: 999px; min-height: 48px;
}
.chips { display: flex; gap: 8px; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
.chip {
  border: 2px solid #ffd9b3; background: #fff; color: var(--orange-d);
  font-size: 16px; padding: 8px 14px; border-radius: 999px; min-height: 44px;
}
.chip.active { background: var(--orange); color: #fff; border-color: var(--orange); }

/* 识字卡片 */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 18px; display: flex; flex-direction: column; align-items: center; gap: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.06);
  max-width: 560px; width: 100%; margin: 0 auto;
}
.char-target { width: 240px; height: 240px; }
/* hanzi-writer 内部 SVG 自适应容器 */
.char-target svg { display: block; margin: auto; max-width: 100%; max-height: 100%; }
.char-fallback { width: 240px; height: 240px; display: flex; align-items: center; justify-content: center;
  font-size: 150px; line-height: 1; color: var(--orange-d); }
.char-meta { display: flex; gap: 16px; align-items: baseline; }
.pinyin { font-size: 34px; color: var(--blue); font-weight: 700; }
.meaning { font-size: 24px; color: var(--muted); }
.words-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; max-width: 480px; }
.poly-note {
  font-size: 17px; color: var(--blue); background: #eaf3fb; border: 1.5px solid #bfe0f5;
  padding: 7px 14px; border-radius: 999px; text-align: center; max-width: 480px;
}
.word-chip {
  border: 2px solid #d9c2f0; background: #f6effd; color: var(--pink);
  font-size: 22px; padding: 10px 18px; border-radius: 999px; min-height: 52px;
}
.word-chip:active { background: #ecdcfa; }
.card-controls, .card-nav { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.ctl {
  border: none; background: #fff3e6; color: var(--orange-d);
  font-size: 20px; padding: 14px 22px; border-radius: 999px; min-height: var(--tap);
}
.ctl:active { background: #ffe0c2; }
.ctl.quiz { background: var(--orange); color: #fff; }
.ctl.nav { background: #e7f3ec; color: var(--teal); }
.ctl.danger { background: #fdeaea; color: var(--orange-d); }

.quiz-box {
  width: 100%; display: flex; flex-direction: column; gap: 10px; align-items: center;
}
.quiz-q { font-size: 22px; color: var(--ink); }
.quiz-opts { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.quiz-opt {
  border: 2px solid #ffd9b3; background: #fff; color: var(--orange-d);
  font-size: 24px; padding: 12px 22px; border-radius: 16px; min-width: 84px; min-height: 64px;
}
.quiz-opt.ok { background: var(--green); color: #fff; border-color: var(--green); }
.quiz-opt.no { background: #f09595; color: #fff; border-color: #f09595; }

.progress-dots { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; max-width: 560px; margin: 0 auto; }
.pdot { width: 12px; height: 12px; border-radius: 50%; background: #e7e2d6; }
.pdot.on { background: var(--teal); }

/* 算术 */
.math-card {
  background: var(--card); border-radius: var(--radius); padding: 22px;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.06);
  max-width: 560px; width: 100%; margin: 0 auto;
}
.math-expr { font-size: 64px; font-weight: 700; color: var(--ink); letter-spacing: 4px; min-height: 72px; }
.math-dots { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; min-height: 36px; }
.dot { width: 46px; height: 46px; border-radius: 14px; background: #ffd9b0;
  display: flex; align-items: center; justify-content: center; font-size: 28px; line-height: 1;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.06); }
.dot.b { background: #bfe3c6; }
.dot.off { background: #efece4; opacity: .45; filter: grayscale(.5); position: relative; }
.dot.off::after { content: "−"; position: absolute; top: -7px; right: -5px; width: 18px; height: 18px;
  background: var(--orange-d); color: #fff; border-radius: 50%; font-size: 13px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; }
.math-feedback { font-size: 28px; font-weight: 700; min-height: 36px; }
.math-feedback.ok { color: var(--green); }
.math-feedback.no { color: var(--orange-d); }

.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; max-width: 360px; }
.pad button {
  border: none; background: #fff3e6; color: var(--orange-d);
  font-size: 30px; padding: 16px 0; border-radius: 16px; min-height: 64px;
}
.pad button:active { background: #ffe0c2; }
.pad button.ok { background: var(--green); color: #fff; }
.pad button.clear { background: #e7f3ec; color: var(--teal); }

/* 家长 */
.parent-lock { margin: auto; display: flex; flex-direction: column; gap: 14px; align-items: center; }
.lock-tip { font-size: 22px; }
.parent-lock input {
  font-size: 28px; text-align: center; padding: 12px; width: 200px;
  border: 2px solid #ffd9b3; border-radius: 14px; letter-spacing: 6px;
}
.msg { color: var(--orange-d); min-height: 22px; }
.parent-dash { margin: auto; width: 100%; max-width: 560px; display: flex; flex-direction: column; gap: 16px; }
.summary { background: var(--card); border-radius: var(--radius); padding: 18px; font-size: 20px; line-height: 1.9; box-shadow: 0 6px 20px rgba(0,0,0,0.06); }
.summary b { color: var(--orange-d); }

/* 拼音模块 */
.py-content { flex: 1; width: 100%; max-width: 560px; margin: 0 auto; overflow-y: auto; }
.py-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 12px; padding: 4px; }
.py-item {
  border: none; background: var(--card); color: var(--orange-d);
  font-size: 34px; font-weight: 700; padding: 18px 0; border-radius: 18px; min-height: 76px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.py-item:active { background: #fff3e6; }
.py-examples { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.tone-card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: 0 6px 20px rgba(0,0,0,0.06); margin-bottom: 14px; text-align: center; }
.tone-name { font-size: 30px; font-weight: 700; color: var(--pink); }
.tone-gesture { font-size: 20px; color: var(--ink); margin: 6px 0; }
.tone-desc { font-size: 18px; color: var(--muted); margin-bottom: 10px; }

/* 详情覆盖层 */
.overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.py-detail-card { position: relative; display: flex; flex-direction: column; align-items: center; gap: 14px; max-width: 420px; width: 100%; }
.py-close { position: absolute; top: 12px; right: 12px; border: none; background: #ffe6cc; color: var(--orange-d); font-size: 16px; padding: 8px 16px; border-radius: 999px; }
.py-letter { font-size: 96px; font-weight: 700; color: var(--orange-d); line-height: 1; }
.py-jingle-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: center; }
.py-jingle { font-size: 22px; color: var(--ink); }
.ctl.mini { padding: 10px 16px; font-size: 18px; background: #fff3e6; color: var(--orange-d); border: 2px solid #ffd9b0; }
.py-sub { font-size: 18px; color: var(--muted); }

/* ===== 新增交互样式（B 组 / C1） ===== */
.ctl.mini { font-size: 16px; padding: 8px 14px; min-height: 44px; background: #fff3e6; color: var(--orange-d); }
.ctl.toggle.on { background: var(--teal); color: #fff; }
.link-btn { border: none; background: transparent; color: var(--blue); font-size: 16px; text-decoration: underline; padding: 6px; }
.pinform { display: flex; flex-direction: column; gap: 10px; align-items: center; width: 100%; max-width: 420px; }
.pinform input { font-size: 22px; text-align: center; padding: 10px; width: 200px; border: 2px solid #ffd9b3; border-radius: 14px; letter-spacing: 4px; }
.pinform .msg { font-size: 15px; }
.make10 { background: #eaf3ff; border: 2px dashed #9cc4f0; color: var(--blue); font-size: 20px; padding: 8px 14px; border-radius: 14px; text-align: center; line-height: 1.5; }
.make10 .m10-line { white-space: nowrap; }
.stars { display: flex; gap: 10px; justify-content: center; font-size: 40px; }
.stars span { display: inline-block; animation: starPop .5s ease both; }
@keyframes starPop { 0% { transform: scale(0) rotate(-30deg); opacity: 0; } 60% { transform: scale(1.3) rotate(8deg); opacity: 1; } 100% { transform: scale(1) rotate(0); opacity: 1; } }
.quiz-opt .quiz-icon { display: inline-block; font-size: 30px; margin-right: 6px; color: var(--pink); }
.practice-head { display: flex; justify-content: flex-start; width: 100%; }
.bar-wrap { position: relative; width: 100%; height: 26px; background: #efe9dc; border-radius: 999px; overflow: hidden; margin-top: 6px; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--teal), #4caf50); border-radius: 999px; transition: width .4s; }
.bar-label { position: absolute; right: 12px; top: 0; line-height: 26px; font-size: 14px; color: var(--ink); }
.math-expr.wrong { color: var(--orange-d); animation: shake .35s; }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
/* 拼音详情关闭按钮放大（B7） */
.py-close { font-size: 20px; padding: 10px 18px; }

.hidden { display: none !important; }

/* ============================================================
   手机端（竖屏 ≤600px）方案 A：紧凑化 + 底部固定操作栏
   - 缩小笔画区/拼音/组词/按钮
   - 把「读一读/笔顺/描一描」+「上一个/考一考/下一个」
     固定到底部常驻，正文可滚动，操作按钮不再被推到屏幕外
   - 仅对窄屏生效，iPad/桌面完全不受影响
   ============================================================ */
@media (max-width: 600px) {
  .screen { padding: max(10px, env(safe-area-inset-top)) 10px 0; gap: 8px; }

  /* 顶栏分类芯片压缩 */
  .bar { gap: 6px; }
  .chips { gap: 6px; padding-bottom: 2px; }
  .chip { font-size: 14px; padding: 6px 12px; min-height: 36px; }

  /* 识字卡片紧凑 */
  .card { padding: 12px; gap: 10px; max-width: 100%; }
  .char-target, .char-fallback { width: 168px; height: 168px; }
  .char-fallback { font-size: 100px; }
  /* 不再强制 svg 尺寸：由 learn.js 动态读取容器大小传给 HanziWriter，避免 viewBox 错位 */
  .char-meta { gap: 12px; }
  .pinyin { font-size: 26px; }
  .meaning { font-size: 18px; }
  .words-row { gap: 8px; max-width: 100%; }
  .word-chip { font-size: 18px; padding: 8px 14px; min-height: 42px; }
  .ctl { font-size: 16px; padding: 10px 16px; min-height: 48px; }

  /* 算术页紧凑（4行键盘必须完整可见） */
  .math-card { padding: 10px; gap: 8px; }
  .math-expr { font-size: 42px; min-height: 48px; letter-spacing: 2px; }
  .math-dots { gap: 4px; min-height: 26px; }
  .dot { width: 34px; height: 34px; font-size: 20px; border-radius: 10px; }
  .math-feedback { font-size: 22px; min-height: 26px; }
  .pad { gap: 6px; max-width: 300px; }
  .pad button { font-size: 24px; padding: 10px 0; min-height: 50px; }
  .make10 { font-size: 17px; padding: 6px 10px; }

  /* 拼音详情卡在窄屏更紧凑 */
  .py-detail-card { padding: 14px; gap: 10px; }
  .py-letter { font-size: 72px; }
}

/* ============================================================
   B8：识字底部固定操作栏——手机(≤600px)与平板竖屏(≤1024px)均生效
   （手机专属的紧凑尺寸仍在上面的 max-width:600px 内）
   ============================================================ */
@media (max-width: 1024px) and (orientation: portrait) {
  #screen-learn .screen-body { padding-bottom: 144px; gap: 10px; }
  .card-controls, .card-nav {
    position: fixed; left: 0; right: 0; z-index: 20;
    background: var(--bg);
    display: flex; gap: 8px; justify-content: space-around;
    padding: 6px 10px;
  }
  .card-controls { bottom: 64px; padding-top: 10px; }
  .card-nav {
    bottom: 0;
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
    border-top: 1px solid #ffe0c2;
  }
  .card-controls .ctl, .card-nav .ctl { flex: 1; min-width: 0; }
}
