/* anim.css —— MG 动画讲解播放器（2026-11-03）
 *
 * 视觉基调：**教科书线稿** —— 浅底、细线、无阴影渐变。理由：要和题目/导图
 * 那套观感一致，学生刚看完题目点开动画，不该像换了个 App。
 * 颜色全部走主样式变量，深色主题自动跟随。
 */

.an-overlay {
  position: fixed; top: 0; left: 0; right: 0; height: var(--vh); box-sizing: border-box; z-index: 9700;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: rgba(17, 24, 39, .62);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  -webkit-user-select: none; user-select: none;
}
.an-overlay[hidden] { display: none !important; }
body.an-open { overflow: hidden; }

.an-panel {
  display: flex; flex-direction: column;
  width: min(880px, 100%);
  /* 舞台是 16:9 且**不能压**（压了就会和绝对定位的标签错位），所以面板总高 ≈
     宽×9/16 + 顶栏/公式/字幕/控制条/幕点约 290px。视口不够高时**收窄面板**，
     而不是让内容溢出被裁 —— 否则底部控制条和幕点直接看不见（2026-11-17 MaxHub 实测）。 */
  width: min(880px, 100%, calc((var(--vh) - 330px) * 16 / 9));
  max-height: calc(var(--vh) - 32px);
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--border); border-radius: 16px;
  overflow: hidden;
}

/* ── 顶栏 ─────────────────────────────────────────────────────── */
.an-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px 10px 14px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--brand-soft), transparent 140%);
  flex: 0 0 auto;
}
.an-kicker {
  font-size: 11.5px; font-weight: 700; letter-spacing: .5px;
  color: #fff; background: var(--brand);
  padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}
.an-title {
  font-size: 13px; color: var(--muted); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.an-close {
  margin-left: auto; width: 30px; height: 30px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; line-height: 1; color: var(--muted);
  background: transparent; border: 1px solid transparent; border-radius: 9px;
  cursor: pointer;
}
.an-close:hover { background: var(--chat-bg, #f3f5f8); color: var(--ink); }

/* ── 舞台（16:9，坐标系 0~100 × 0~56） ────────────────────────── */
.an-stage {
  position: relative;
  aspect-ratio: 16 / 9;
  width: 100%;
  background: var(--panel);
  overflow: hidden;
  flex: 0 0 auto;
}
.an-svg {
  position: absolute; inset: 0; width: 100%; height: 100%;
  display: block;
}
.an-labels { position: absolute; inset: 0; pointer-events: none; }

/* 场景标题：左上角，淡入后停住 */
.an-scenet {
  position: absolute; left: 3.2%; top: 5%;
  font-size: 13px; font-weight: 700; letter-spacing: .5px;
  color: var(--brand);
  opacity: 0; transform: translateY(-4px);
  transition: opacity .35s ease, transform .35s ease;
}
.an-scenet.in { opacity: 1; transform: translateY(0); }

/* ⚠️ display:flex 会盖掉 [hidden] 的 display:none —— 必须显式写一条，
   否则"生成完成后 loading 层还在"（首版就是这样，白底上压着一行灰字）。 */
.an-loading[hidden] { display: none !important; }
.an-loading {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; text-align: center;
  font-size: 13px; color: var(--muted); line-height: 1.8;
}
.an-retry {
  padding: 7px 16px; font-size: 13px; font-weight: 600;
  color: #fff; background: var(--brand);
  border: 0; border-radius: 9px; cursor: pointer;
}

/* ── 图形（线稿） ─────────────────────────────────────────────── */
.an-line, .an-axis { stroke: var(--ink); stroke-width: .35; fill: none; }
.an-axis { stroke-opacity: .55; }
.an-head { fill: var(--ink); fill-opacity: .7; stroke: none; }
.an-arrow { stroke: var(--brand); stroke-width: .8; fill: none; stroke-linecap: round; }
.an-path { stroke: var(--brand); stroke-width: .8; fill: none; stroke-linejoin: round; }
.an-path.dash { stroke-dasharray: 1.6 1.3; }
.an-dotf { fill: var(--brand); }
.an-dotf.alt { fill: #e07b00; }
/* 数学专用元件（2026-11-15）：圆（韦恩图/单位圆）与多边形（三角形/可行域/统计柱）。
   填充必须半透明：两个相交的圆叠起来颜色更深，交集才看得见。 */
.an-circle { fill: var(--brand); fill-opacity: .10; stroke: var(--brand); stroke-width: .45; }
.an-circle.alt { fill: #e07b00; fill-opacity: .10; stroke: #e07b00; }
.an-poly { fill: none; stroke: var(--brand); stroke-width: .55; stroke-linejoin: round; }
.an-poly.filled { fill: var(--brand); fill-opacity: .12; }
.an-box { fill: transparent; stroke: var(--ink); stroke-opacity: .45; stroke-width: .3; }
.an-solid { fill: var(--ink); fill-opacity: .18; stroke: var(--ink); stroke-width: .35; stroke-opacity: .7; }
.an-wheel { fill: var(--ink); fill-opacity: .55; }
.an-grid { stroke: var(--ink); stroke-opacity: .18; stroke-width: .25; }

/* ── 第二批元件（2026-11-03）力/热/电/光 ─────────────────────────
   统一原则：细线稿、和题目区同一种墨色；只有"正在强调的东西"用品牌色。
   所以场线、弹簧、透镜这类"图的主体"用品牌色，电路/气缸的画框用墨色淡描。 */
.an-spring { stroke: var(--brand); stroke-width: .55; fill: none; stroke-linejoin: round; stroke-linecap: round; }
.an-ring { fill: none; stroke: var(--ink); stroke-width: .45; stroke-opacity: .75; }
.an-solid-line { stroke: var(--ink); stroke-width: .6; fill: none; stroke-linecap: round; stroke-opacity: .85; }
.an-box-solid { fill: var(--panel); stroke: var(--ink); stroke-width: .35; stroke-opacity: .75; }
.an-sym { stroke: var(--ink); stroke-width: .35; stroke-opacity: .7; fill: none; }
.an-sym-fill { fill: var(--ink); fill-opacity: .7; }
.an-field-l { stroke: var(--brand); stroke-width: .45; fill: none; }
.an-head-sm { fill: var(--brand); stroke: none; }
.an-lens { stroke: var(--brand); stroke-width: .7; fill: var(--brand); fill-opacity: .10; }
/* v-t / x-t 图像的端点标注（2026-11-03）：
   面积填充画在曲线下面，虚线引线连到对应的轴，标签放在绘图区外侧。 */
.an-shade { fill: var(--brand); fill-opacity: .12; stroke: none; }
/* 面积切分（2026-11-03）：把梯形按初速度高度切成矩形 + 三角形。
 * 淡底仍由 .an-shade 铺（切分前先看到完整梯形），两块再叠上去：
 * 矩形更实、三角形只勾一圈虚线 —— 同色不同"重量"，读起来是"同一块面积被切开"，
 * 不是"两个不相干的图形"。 */
.an-shade-rect { fill: var(--brand); fill-opacity: .18; stroke: none; }
.an-shade-tri  {
  fill: var(--brand); fill-opacity: .05;
  stroke: var(--brand); stroke-opacity: .5; stroke-width: .38;
  stroke-dasharray: 1.4 1.1;
}
.an-cut {
  stroke: var(--brand); stroke-opacity: .6; stroke-width: .35;
  stroke-dasharray: 1.6 1.2;
}
.an-guide { stroke: var(--ink); stroke-opacity: .38; stroke-width: .3; stroke-dasharray: 1.4 1.6; }
.an-axis-dash { stroke: var(--ink); stroke-opacity: .3; stroke-width: .3; stroke-dasharray: 1.4 1.6; }
.an-hatch { stroke: var(--ink); stroke-opacity: .3; stroke-width: .3; }
.an-dim { stroke: var(--ink); stroke-width: .3; stroke-opacity: .8; fill: none; }

/* 教材原图（2026-11-23）：垫一张白卡片，裁图从 PDF 里切出来时底是纸白，
   直接落在 --panel 上会看不出边界。图片本身不接收指针事件（图廊点击不归它管）。 */
.an-fig-bg { fill: #fff; stroke: var(--border); stroke-width: .22; }
.an-fig { pointer-events: none; }

/* ── 文字层（HTML + MathJax） ─────────────────────────────────── */
.an-t {
  position: absolute;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  line-height: 1.35;
  color: var(--ink);
  opacity: 0;
  /* 描边兜底：文字万一还是压在箭杆/轴线上，有一圈底色垫着就能读。
     位置避让在 anim.js 里做，这里只负责"真撞上了也别糊成一团"。 */
  text-shadow: 0 0 3px var(--panel, #fff), 0 0 3px var(--panel, #fff),
               0 0 6px var(--panel, #fff);
}
.an-t-sm { color: var(--muted); }
.an-t-main { font-weight: 600; color: var(--ink); }
.an-t-box { text-align: center; }
.an-t-td { color: var(--ink); }
.an-t td, .an-t mjx-container { font-size: 1em !important; }

/* 这一幕的公式：放在**舞台外**、字幕上方的一条。
   为什么不在舞台里：图形和文字本来就贴着底边，公式条压上去必然重叠
   （首版就压住了"地日距离 ≈ 1.5×10⁸ km"）。 */
.an-formula {
  flex: 0 0 auto;
  display: flex; gap: 20px; align-items: center; justify-content: center;
  flex-wrap: wrap;
  padding: 8px 18px;
  background: var(--brand-soft);
  color: var(--ink);
  font-size: 15px; line-height: 1.5;
  border-top: 1px solid var(--border);
}
.an-formula:empty { display: none; }
.an-formula mjx-container { font-size: 1.02em !important; }
html[data-theme="dark"] .an-formula { background: rgba(47, 109, 246, .16); }

/* ── 字幕 ─────────────────────────────────────────────────────── */
.an-sub {
  flex: 0 0 auto;
  min-height: 62px;
  padding: 10px 18px 12px;
  font-size: 14px; line-height: 1.75; color: var(--ink);
  background: var(--chat-bg, #f7f9fc);
  border-top: 1px solid var(--border);
}
/* 字幕里的行内公式：压到和正文同样的视觉大小。
   MathJax 行内默认比正文大一圈（约 1.2em），混在中文里会"跳出来"，
   而且会把行高撑大、字幕条高度忽高忽低。 */
.an-sub mjx-container {
  font-size: 1em !important;
  margin: 0 1px !important;
}
.an-sub mjx-container svg { vertical-align: -0.32em; }
.an-end { color: var(--brand); font-weight: 600; }
/* 结束态：字幕条右侧跟一个"去闯关"按钮 */
.an-sub.an-sub-end {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
}

/* 旁白提示条（"点一下开启旁白" / "旁白没能播放"）。
   ⚠️ display:flex 会盖掉 [hidden]，必须显式写一条 —— 与 .an-loading 同一个坑。 */
.an-hint {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 8px 14px;
  font-size: 12.5px; line-height: 1.6; color: var(--ink);
  background: #fff7e6;
  border-top: 1px solid #ffd591;
}
.an-hint[hidden] { display: none !important; }
.an-hint button {
  flex: 0 0 auto;
  padding: 6px 14px; font-size: 12.5px; font-weight: 600;
  color: #fff; background: var(--brand);
  border: 0; border-radius: 8px; cursor: pointer;
}
html[data-theme="dark"] .an-hint {
  background: rgba(255, 183, 77, .12);
  border-top-color: rgba(255, 183, 77, .3);
}

/* ── 控制条 ───────────────────────────────────────────────────── */
.an-ctrl {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
}
.an-btn {
  min-width: 32px; height: 32px; padding: 0 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; color: var(--ink);
  background: transparent; border: 1px solid var(--border); border-radius: 9px;
  cursor: pointer;
}
.an-btn:hover { border-color: var(--brand); color: var(--brand); }
/* ⚠️ 必须写在 .an-btn 之后、并且用两个类名（.an-btn.an-quizbtn）：
   .an-btn 里是 `background: transparent; color: var(--ink)`，与单类名同权重、
   且它定义在后面 → 单写 .an-quizbtn 会被它盖掉，结果"白底白字"（2026-11-03 截图）。 */
.an-btn.an-quizbtn {
  flex: 0 0 auto;
  color: #fff; background: var(--brand); border-color: var(--brand);
  font-weight: 600;
}
.an-btn.an-quizbtn:hover { color: #fff; background: var(--brand); filter: brightness(1.06); }
.an-play { min-width: 40px; }
/* 旁白加载失败：按钮变灰，配合 title 说明"画面不受影响" */
.an-sound-bad { color: var(--muted); border-color: var(--border); }
.an-speed { font-variant-numeric: tabular-nums; }
.an-bar {
  position: relative; flex: 1 1 auto; height: 6px;
  /* 进度条目前**只显示**，不能拖。写 pointer 会让人以为能拖（点上去没反应）。 */
  background: var(--border); border-radius: 999px; cursor: default;
}
.an-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0;
           background: var(--brand); border-radius: 999px; }
.an-cap {
  position: absolute; top: 50%; width: 10px; height: 10px; margin-left: -5px;
  transform: translateY(-50%);
  background: var(--brand); border-radius: 50%;
}
.an-time {
  font-size: 12px; color: var(--muted);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}

/* ── 幕进度点 ─────────────────────────────────────────────────── */
.an-dots {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 5px;
  padding: 0 12px 10px;
  overflow-x: auto;
}
.an-dot {
  flex: 0 0 auto; min-width: 22px; height: 20px;
  font-size: 11px; font-weight: 600; color: var(--muted);
  background: transparent; border: 1px solid var(--border); border-radius: 999px;
  cursor: pointer;
}
.an-dot.past { color: var(--brand); border-color: rgba(47, 109, 246, .5); }
.an-dot.cur { color: #fff; background: var(--brand); border-color: var(--brand); }

@media (max-width: 620px) {
  .an-overlay { padding: 0; }
  .an-panel { width: 100%; max-height: var(--vh); height: 100%; border-radius: 0; border: 0; }
  .an-sub { font-size: 13px; min-height: 74px; }
  .an-time { display: none; }
}
