/* ===========================================================================
 * 开心格 · 数学题型训练样式
 * 复用全站 :root 品牌色与按钮（.btn / .btn-primary / .btn-outline / .hidden）。
 * 全程无 emoji，图标走内联 SVG。遵循团队 preference：
 *   · 强调色边卡片 → 彩色边两角直角（topic-card 顶部色条）
 *   · 计数为 0 显示「—」（math.js 的 dash() 输出，含中文量词避歧义）
 *   · 手机端比电脑端更简：窄屏删修饰、放大点击区（见文末媒体查询）
 *   · 复用 game_layout 共享壳，顶栏稳定
 * =========================================================================== */

/* LegalSnap 同款标题字体：拉丁 Funnel Sans + 中文 阿里巴巴普惠体 3 Heavy（仅数学页用） */
@font-face {
  font-family: "Alibaba PuHuiTi 3";
  src: url("https://cdn.jsdelivr.net/npm/alibabapuhuiti-3-105-heavy@1.0.0/AlibabaPuHuiTi-3-105-Heavy.woff2") format("woff2");
  font-weight: 900; font-style: normal; font-display: swap;
}
:root {
  --math-title: "Funnel Sans", "Alibaba PuHuiTi 3", "HarmonyOS Sans SC",
    "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", system-ui, sans-serif;
}
/* 数学部分的标题统一用该字体（中文走阿里巴巴普惠体 Heavy，拉丁/数字走 Funnel Sans 700） */
.math-main .page-title,
.grade-card .g-badge, .grade-card .g-name,
.topic-name,
.trainer-topic-name,
.problem-prompt,
.math-celebrate-title {
  font-family: var(--math-title);
  font-weight: 700;
}

.math-main { max-width: 920px; margin: 0 auto; }   /* 整个数学区水平居中 */
.math-intro { color: #6b7280; font-size: 0.92rem; font-weight: 600; margin: -4px 0 18px; }

/* 内联图标通用 */
.ic { display: inline-block; vertical-align: middle; width: 1em; height: 1em; line-height: 0; }

/* -------------------------------------------------------------- 年级选择 -- */
/* 重设计：大号分段卡，序号徽标 + 题型数，每个年级独立强调色，选中实心更醒目 */
.math-home .main-header-row { margin-bottom: 18px; }
.grade-pick { display: flex; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }
.grade-card {
  --g: var(--blue);
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px 12px 12px;
  background: var(--white); border: 2.5px solid #e9edf4; border-radius: 18px;
  cursor: pointer; font-family: inherit;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s, background 0.15s;
}
.grade-card:hover { transform: translateY(-2px); border-color: var(--g); box-shadow: 0 8px 20px -10px var(--g); }
.grade-card .g-badge {
  width: 44px; height: 44px; flex-shrink: 0; border-radius: 13px;
  background: #eef2fb; background: color-mix(in oklab, var(--g) 14%, white);
  color: var(--g); display: grid; place-items: center;
  font-size: 1.45rem; font-weight: 900; transition: all 0.15s;
}
.grade-card .g-text { display: flex; flex-direction: column; line-height: 1.15; text-align: left; }
.grade-card .g-name { font-size: 1.02rem; font-weight: 800; color: var(--dark); }
.grade-card .g-sub { font-size: 0.72rem; font-weight: 700; color: #9aa3b2; margin-top: 2px; }
.grade-card.active { background: var(--g); border-color: var(--g); box-shadow: 0 10px 24px -10px var(--g); }
.grade-card.active .g-badge { background: rgba(255, 255, 255, 0.22); color: var(--white); }
.grade-card.active .g-name { color: var(--white); }
.grade-card.active .g-sub { color: rgba(255, 255, 255, 0.85); }

/* -------------------------------------------------------------- 题型卡片 -- */
/* 重设计：图标进彩色方块 + 进度环（替代皇冠）+ 描述 + 细进度条 + 「开始 ›」 */
.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.topic-card {
  --accent: var(--blue);
  position: relative; display: flex; flex-direction: column; gap: 12px;
  text-align: left; font-family: inherit;
  background: var(--white); border: 2px solid #eef1f6; border-radius: 20px;
  padding: 18px 18px 16px; cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.topic-card:hover { transform: translateY(-4px); border-color: color-mix(in oklab, var(--accent) 45%, white); box-shadow: 0 16px 30px -16px var(--accent); }
.topic-card:active { transform: translateY(-1px); }
.topic-head { display: flex; align-items: center; justify-content: space-between; }
.topic-ic-wrap {
  width: 54px; height: 54px; border-radius: 16px;
  background: #f1f4f9; background: color-mix(in oklab, var(--accent) 13%, white);
  display: grid; place-items: center; line-height: 0;
}
.topic-ic { width: 32px; height: 32px; }
.topic-ring { width: 38px; height: 38px; flex-shrink: 0; }
.topic-ring-num { font-size: 0.66rem; font-weight: 800; fill: #9aa3b2; }
.topic-name { font-size: 1.1rem; font-weight: 800; color: var(--dark); }
.topic-desc { font-size: 0.8rem; color: #8a93a3; font-weight: 600; line-height: 1.45; min-height: 2.3em; }
.topic-bar { height: 6px; border-radius: 999px; background: #eef1f6; overflow: hidden; }
.topic-bar span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.3s; }
.topic-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 2px; }
.topic-count { font-size: 0.74rem; color: #9aa3b2; font-weight: 700; }
.topic-count b { color: var(--dark); }
.topic-go { display: inline-flex; align-items: center; gap: 4px; font-size: 0.8rem; font-weight: 800; color: var(--accent); letter-spacing: 0.3px; }
.topic-go svg { width: 15px; height: 15px; }
.topic-card:hover .topic-go svg { transform: translateX(3px); transition: transform 0.15s; }

/* =============================================================== 训练区 == */
.math-trainer { max-width: 600px; margin: 0 auto; }
/* 标题在左、返回按钮在右上角（留在 math-trainer 容器内） */
.trainer-topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.trainer-back { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; font-family: inherit; font-size: 0.82rem; font-weight: 700; color: #5a6475; background: var(--light); border: 1.5px solid #e3e7ee; border-radius: 999px; padding: 6px 14px 6px 12px; cursor: pointer; flex-shrink: 0; align-self: flex-start; transition: all 0.15s; }
.trainer-back svg { width: 16px; height: 16px; }
.trainer-back:hover { color: var(--blue); border-color: var(--blue); background: #eef4ff; }
.trainer-title-group { flex: 1; min-width: 0; }
.trainer-topic-name { display: flex; align-items: center; gap: 8px; font-size: 1.45rem; font-weight: 800; color: var(--dark); }
.trainer-topic-ic { line-height: 0; }
.trainer-topic-ic .topic-ic { width: 28px; height: 28px; }
.trainer-grade-name { display: block; font-size: 0.8rem; font-weight: 700; color: #9aa3b2; margin-top: 1px; }

/* 题型切换栏：训练中横向胶囊条，当前题型高亮，可一键跳转其它题型（窄屏可横滑） */
/* grid minmax(0,1fr)：track 最小宽=0，切断横向滚动内容把父级撑宽的传导 */
.trainer-railwrap { display: grid; grid-template-columns: minmax(0, 1fr); margin-bottom: 16px; }
.trainer-rail-label { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.5px; color: #9aa3b2; margin-bottom: 8px; padding-left: 2px; }
.trainer-rail { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: thin; }
.trainer-rail::-webkit-scrollbar { height: 6px; }
.trainer-rail::-webkit-scrollbar-thumb { background: #d8deea; border-radius: 999px; }
.rail-chip {
  --accent: var(--blue);
  flex-shrink: 0; display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px 8px 9px; border: 2px solid #e9edf4; border-radius: 999px;
  background: var(--white); cursor: pointer; font-family: inherit;
  font-size: 0.84rem; font-weight: 800; color: #5a6475; white-space: nowrap; transition: all 0.15s;
}
.rail-chip .rail-ic { width: 26px; height: 26px; border-radius: 9px; background: #f1f4f9; background: color-mix(in oklab, var(--accent) 14%, white); display: grid; place-items: center; line-height: 0; }
.rail-chip .rail-ic .topic-ic { width: 17px; height: 17px; }
.rail-chip:hover { border-color: var(--accent); color: var(--dark); }
.rail-chip.active { background: #eef4ff; background: color-mix(in oklab, var(--accent) 12%, white); border-color: var(--accent); color: var(--accent); }
.rail-chip.active .rail-ic { background: var(--accent); }
.rail-grade-divider { flex-shrink: 0; align-self: center; font-size: 0.68rem; font-weight: 800; color: #c2c9d6; padding: 0 2px; }

/* 难度条（缺砖数） */
.trainer-diff { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.trainer-diff .diff-label { font-size: 0.78rem; font-weight: 800; color: #6b7280; flex-shrink: 0; }
.diff-segs { display: flex; gap: 6px; flex-wrap: wrap; }
.diff-opt { font-family: inherit; font-size: 0.8rem; font-weight: 800; padding: 5px 13px; border: 2px solid #e3e7ee; border-radius: 999px; background: var(--white); color: #6b7280; cursor: pointer; transition: all 0.15s; }
.diff-opt:hover { border-color: var(--blue); color: var(--blue); }
.diff-opt.active { background: var(--blue); border-color: var(--blue); color: var(--white); box-shadow: var(--shadow-sm); }

.trainer-progress { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.trainer-progress-track { flex: 1; height: 12px; border-radius: 999px; background: #eef1f6; overflow: hidden; }
.trainer-progress-fill { display: block; height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, var(--green), #46d98a); transition: width 0.4s; }
.trainer-progress-label { font-size: 0.78rem; font-weight: 800; color: #6b7280; white-space: nowrap; }

/* 题卡 */
.problem-card { background: var(--white); border: 1.5px solid #eef1f6; border-radius: 18px; box-shadow: var(--shadow-sm); padding: 22px 20px; transition: box-shadow 0.2s; }
.problem-card.solved { box-shadow: 0 0 0 3px rgba(0, 200, 83, 0.35), var(--shadow); }
.problem-prompt { font-size: 1.35rem; font-weight: 800; color: var(--dark); text-align: center; letter-spacing: 0.5px; margin-bottom: 14px; }

/* 知识点小卡（体现该题型的关键方法） */
.problem-knowledge { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-bottom: 16px; }
/* 标签即标签：只放要点名，干净的胶囊，不挂描述 */
.kp-chip { display: inline-flex; align-items: center; background: #eef4ff; border: 1.5px solid #d8e6ff; color: var(--blue); border-radius: 999px; padding: 4px 13px; font-size: 0.78rem; font-weight: 800; line-height: 1.3; }

.problem-visual { display: flex; flex-direction: column; justify-content: center; align-items: center; min-height: 60px; margin-bottom: 16px; }
.problem-visual:empty { display: none; }

/* ------ 砖墙 ------ */
.brick-svg { width: 100%; max-width: 380px; height: auto; }
.row-hi { fill: none; stroke-width: 2.5; stroke-dasharray: 5 3; animation: holePulse 1s ease-in-out infinite; }
.hole-hi { fill: rgba(46, 184, 114, 0.16); stroke: #2EB872; stroke-width: 2; stroke-dasharray: 4 3; animation: holePulse 1s ease-in-out infinite; }
.half-tag { fill: #2C3E50; font-size: 11px; font-weight: 900; text-anchor: middle; }
@keyframes holePulse { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }
.brick-legend { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; margin-top: 12px; font-size: 0.76rem; font-weight: 700; color: #6b7280; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { display: inline-block; height: 15px; border: 1px solid #9A6B42; border-radius: 2px; }
.sw-whole { width: 26px; background: #B97E50; }
.sw-half { width: 13px; background: #D8A878; }

/* ------ 十格阵（凑十/破十） ------ */
.ten-frames { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.ten-frame { display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px; padding: 5px; border: 2px solid #cfd6e4; border-radius: 8px; background: #fafbfd; }
.tf-cell { position: relative; width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center; border-radius: 4px; }
.tf-cell::after { content: ''; width: 17px; height: 17px; border-radius: 50%; }
.tf-blue::after { background: var(--blue); }
.tf-orange::after { background: var(--orange); }
.tf-cell.glow { box-shadow: 0 0 0 3px rgba(46, 184, 114, 0.55); }
.tf-cell.crossed::before { content: '\00D7'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--red); font-weight: 900; font-size: 1.2rem; }

/* ------ 数一数（彩色形状） ------ */
.obj-grid { display: flex; flex-wrap: wrap; gap: 8px; max-width: 340px; justify-content: center; }
.obj-shape { line-height: 0; border-radius: 8px; padding: 2px; transition: all 0.15s; }
.obj-shape svg { width: 30px; height: 30px; display: block; }
.obj-shape.glow { background: rgba(0, 200, 83, 0.18); transform: scale(1.12); }
.obj-break { flex-basis: 100%; height: 0; }

/* ------ 竖式（100以内加减） ------ */
.vmath { font-variant-numeric: tabular-nums; font-weight: 800; color: var(--dark); display: inline-block; }
.vrow { display: flex; align-items: center; justify-content: flex-end; gap: 2px; }
.vop { width: 28px; text-align: center; font-size: 1.5rem; color: var(--blue); }
.vcell { width: 34px; height: 40px; display: flex; align-items: center; justify-content: center; font-size: 1.8rem; border-radius: 6px; }
.vcell.glow { background: rgba(74, 144, 255, 0.16); box-shadow: 0 0 0 2px rgba(74, 144, 255, 0.4); }
.vline { height: 3px; background: var(--dark); border-radius: 2px; margin: 4px 0; }
.vans .vcell { color: var(--blue); }

/* ------ 点阵（乘法） ------ */
.dot-array { display: inline-flex; flex-direction: column; gap: 5px; padding: 6px; border-radius: 10px; }
.dot-row { display: flex; gap: 5px; padding: 2px 4px; border-radius: 6px; transition: background 0.15s; }
.dot-row.glow { background: rgba(255, 90, 90, 0.14); }
.array-dot { width: 17px; height: 17px; border-radius: 50%; background: var(--red); }

/* ------ 数方块（立体） ------ */
.cube-svg { width: 100%; max-width: 280px; height: auto; }
.cube-hi-rect { fill: rgba(74, 144, 255, 0.14); stroke: var(--blue); stroke-width: 2; stroke-dasharray: 4 3; animation: holePulse 1s ease-in-out infinite; }

/* ------------------------------------------------------------ 小老师气泡 -- */
.coach-bubble { display: flex; align-items: center; gap: 10px; background: #f1f6ff; border: 1.5px solid #dbe7ff; border-radius: 14px; padding: 10px 14px; margin-bottom: 14px; transition: background 0.2s, border-color 0.2s; }
.coach-ic { flex-shrink: 0; line-height: 0; }
.coach-svg { width: 38px; height: 38px; display: block; }
.coach-text { font-size: 0.9rem; font-weight: 700; color: #3a4660; line-height: 1.4; }
.coach-happy { background: #e7f8ef; border-color: #bdebd2; }
.coach-happy .coach-svg { animation: coachBounce 0.5s; }
.coach-think { background: #fff7e8; border-color: #ffe3a8; }
@keyframes coachBounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

/* ----------------------------------------------------------- 一步步教我 -- */
.guide-steps { background: #fffdf3; border: 1.5px solid #ffe9a8; border-radius: 14px; padding: 14px 16px; margin-bottom: 16px; }
.guide-title { font-size: 0.9rem; font-weight: 800; color: #b8860b; margin-bottom: 10px; }
.guide-step { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 9px; animation: stepIn 0.25s ease; }
.guide-num { flex-shrink: 0; width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; background: var(--yellow); color: var(--dark); font-size: 0.78rem; font-weight: 900; border-radius: 50%; }
.guide-text { font-size: 0.92rem; font-weight: 600; color: var(--dark); line-height: 1.5; }
.guide-text b { color: var(--red); font-size: 1.05em; }
.guide-next { margin-top: 4px; }
.guide-done { font-size: 0.85rem; font-weight: 800; color: var(--green); margin-top: 6px; }
@keyframes stepIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ----------------------------------------------------------------- 答题 -- */
.answer-zone { margin-top: 4px; }
.answer-choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.choice-btn { font-family: inherit; font-size: 1.3rem; font-weight: 800; min-height: 56px; border: 2.5px solid #e3e7ee; border-radius: 14px; background: var(--white); color: var(--dark); cursor: pointer; transition: all 0.12s; }
.choice-btn:hover { border-color: var(--blue); }
.choice-btn.picked { border-color: var(--blue); background: #eaf2ff; color: var(--blue); }

.answer-number { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.num-display { min-width: 120px; height: 56px; display: flex; align-items: center; justify-content: center; font-size: 2rem; font-weight: 800; color: var(--blue); background: var(--light); border: 2.5px solid #e3e7ee; border-radius: 14px; font-variant-numeric: tabular-nums; }
.num-pad { display: grid; grid-template-columns: repeat(3, 64px); gap: 8px; }
.num-key { font-family: inherit; font-size: 1.4rem; font-weight: 800; height: 52px; border: 2px solid #e3e7ee; border-radius: 12px; background: var(--white); color: var(--dark); cursor: pointer; transition: all 0.1s; }
.num-key:hover { border-color: var(--blue); background: #f4f8ff; }
.num-key:active { transform: scale(0.95); }
.num-clear { font-size: 0.85rem; color: var(--red); }
.num-back { font-size: 1.2rem; }

/* 反馈条 */
.answer-feedback { text-align: center; font-weight: 800; font-size: 0.95rem; min-height: 1.4em; margin-top: 14px; opacity: 0; transition: opacity 0.2s; }
.answer-feedback.show { opacity: 1; }
.fb-ok { color: var(--green); }
.fb-no { color: var(--red); }
.fb-hint { color: var(--orange); }

/* +1星 上浮 */
.float-star { position: absolute; left: 50%; top: 40%; transform: translateX(-50%); display: inline-flex; align-items: center; gap: 2px; font-size: 1.4rem; font-weight: 900; color: #E6A700; pointer-events: none; animation: floatUp 1.1s ease-out forwards; }
.float-star .ic { width: 22px; height: 22px; }
@keyframes floatUp { 0% { opacity: 0; transform: translate(-50%, 10px) scale(0.6); } 25% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -70px) scale(1.3); } }

@keyframes shakeX { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-9px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(4px); } }
.problem-card.shake { animation: shakeX 0.45s; }

/* -------------------------------------------------------------- 工具条 -- */
.trainer-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.trainer-toolbar-left { display: flex; gap: 8px; flex-wrap: wrap; }
/* preference: stable-chrome-on-switch —— 检查/下一题同槽等宽，切换不抖；
 * 与左侧工具按钮同为 btn-small，尺寸一致，只靠红色突出主操作 */
.math-check-btn { min-width: 92px; }
/* 全站 .btn-outline 是「白字+半透明白边」，专给彩色页头用；浅色内容区会变隐形。重新着色。 */
.math-tool, .guide-next { color: var(--dark); background: var(--white); border-color: #d8deea; }
.math-tool:hover, .guide-next:hover { color: var(--blue); border-color: var(--blue); }

/* ------------------------------------------------------------- 庆祝弹层 -- */
.math-celebrate { position: fixed; inset: 0; background: rgba(20, 28, 46, 0.55); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px; }
.math-celebrate[hidden] { display: none; }
.math-celebrate-card { background: var(--white); border-radius: 22px; padding: 30px 28px; text-align: center; max-width: 340px; width: 100%; box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25); animation: popIn 0.3s cubic-bezier(0.2, 1.3, 0.5, 1); }
@keyframes popIn { from { opacity: 0; transform: scale(0.8); } to { opacity: 1; transform: scale(1); } }
.math-celebrate-emoji { line-height: 0; margin-bottom: 10px; }
.math-celebrate-emoji .ic { width: 64px; height: 64px; }
.math-celebrate-title { font-size: 1.3rem; font-weight: 800; color: var(--dark); margin-bottom: 6px; }
.math-celebrate-sub { font-size: 0.9rem; font-weight: 600; color: #6b7280; margin-bottom: 18px; line-height: 1.5; }

.math-confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1200; opacity: 0; transition: opacity 0.3s; }

/* ===========================================================================
 * 手机端：比电脑端更简（preference: mobile-simpler-than-desktop）
 * 主动删修饰、收次要信息、放大点击区——不是等比缩小。与全站一致用 max-width。
 * =========================================================================== */
@media (max-width: 640px) {
  .math-intro { display: none; }              /* 删：引导语属修饰 */
  .grade-pick { gap: 8px; }
  .grade-card { padding: 10px 14px 10px 10px; flex: 1; }
  .grade-card .g-badge { width: 38px; height: 38px; font-size: 1.2rem; }
  .topic-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .topic-card { padding: 14px 14px 12px; gap: 10px; }
  .topic-desc { display: none; }              /* 收：次要说明，手机端隐藏 */
  .topic-ic-wrap { width: 46px; height: 46px; }
  .topic-ic { width: 27px; height: 27px; }
  .topic-name { font-size: 0.98rem; }
  .problem-card { padding: 18px 14px; }
  .problem-prompt { font-size: 1.2rem; }
  .problem-knowledge { gap: 6px; }
  .kp-chip { font-size: 0.73rem; padding: 3px 11px; }
  .answer-choices { grid-template-columns: 1fr 1fr; }   /* 选项 2×2，更整齐 */
  /* 放大触控目标，键盘铺满 */
  .num-pad { grid-template-columns: repeat(3, 1fr); width: 100%; max-width: 280px; }
  .num-key { height: 56px; }
  .trainer-toolbar { justify-content: stretch; }
  .trainer-toolbar-left { flex: 1; }
  .trainer-toolbar-left .math-tool { flex: 1; }
  .trainer-toolbar-right { width: 100%; }
  .math-check-btn { width: 100%; }
}

@media (max-width: 380px) {
  .topic-grid { grid-template-columns: 1fr; }
}
