/* 数学面板公共样式（L2 / L3 共用，结构对齐 l1-math-ui.css）。
   颜色经 .tgm-root 上的 CSS 变量注入：--tgm-u / --tgm-v / --tgm-seal / --tgm-pos / --tgm-neg。
   --tgm-lab 由 createMathUI 按 viewBox 跨度算出，供图上标注换算字号。 */

.tgm-root {
  --tgm-u: #73e2ff; --tgm-v: #ffb06f; --tgm-seal: #f6edc8;
  --tgm-pos: #b3ffd7; --tgm-neg: #8db4ff; --tgm-rose: #ff8fb8; --tgm-text: #eef7f5;
  --tgm-lab: 0.98px;
  --tgm-hud-w: min(336px, 31vw);
  --tgm-learn-w: min(272px, 25vw);
  position: fixed; inset: 0; z-index: 6; pointer-events: none;
  opacity: 0; visibility: hidden; transition: opacity .32s ease;
}
.tgm-root.is-active { opacity: 1; visibility: visible; }
body.overlay-open .tgm-root { opacity: 0; pointer-events: none; }

/* 数学面板接管 HUD：隐藏外壳旧面板与各关 standalone 页面被替代的角落卡片
   （#mathPanel 是 M 键矩阵输入面板，保留；formulaReveal 不带 .hud，也保留） */
body.tgm-active .unified-hud, body.tgm-active .coop-ribbon { display: none; }
body.tgm-active-02 .hud:not(.math-panel), body.tgm-active-02 .center-prompt { display: none; }
body.tgm-active-03 .hud:not(.math-panel), body.tgm-active-03 .center-prompt { display: none; }

.tgm-root .t-u { color: var(--tgm-u); }
.tgm-root .t-v { color: var(--tgm-v); }
.tgm-root .t-r { color: var(--tgm-seal); }
.tgm-root .t-pos { color: var(--tgm-pos); }
.tgm-root .t-neg { color: var(--tgm-neg); }

/* ── 右：数学 HUD ── */
.tgm-hud {
  position: fixed; right: 16px; top: 88px; max-height: calc(100vh - 106px);
  width: var(--tgm-hud-w);
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px 15px; overflow: auto; pointer-events: auto;
  color: rgba(238,247,245,0.82);
  border: 1px solid rgba(255,255,255,0.10); border-radius: 18px;
  background: linear-gradient(180deg, rgba(7,12,19,0.82), rgba(7,12,19,0.62));
  backdrop-filter: blur(18px) saturate(1.06); -webkit-backdrop-filter: blur(18px) saturate(1.06);
  box-shadow: 0 18px 54px rgba(0,0,0,0.46);
  transform: translateY(8px); transition: transform .32s ease;
  scrollbar-width: thin;
}
.tgm-root.is-active .tgm-hud { transform: translateY(0); }
.tgm-hud-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.tgm-hud-head h2 { margin: 0; font-size: 17px; letter-spacing: 0.14em; font-weight: 600; color: var(--tgm-text); white-space: nowrap; }
.tgm-phases { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }
.tgm-phase { padding: 3px 8px; border-radius: 999px; border: 1px solid rgba(255,255,255,0.12); background: rgba(255,255,255,0.05); color: rgba(238,247,245,0.5); font-size: 11px; white-space: nowrap; }
.tgm-phase.is-active { color: #fff; border-color: color-mix(in srgb, var(--tgm-seal) 50%, transparent); background: color-mix(in srgb, var(--tgm-seal) 14%, transparent); box-shadow: 0 0 18px color-mix(in srgb, var(--tgm-seal) 18%, transparent); }

/* 图例：一眼说清 u / v / 目标各是谁的、按什么键 */
.tgm-legend { display: flex; flex-direction: column; gap: 3px; }
.tgm-leg { display: flex; align-items: baseline; gap: 6px; font-size: 11.5px; line-height: 1.5; color: rgba(238,247,245,0.6); }
.tgm-leg i { width: 15px; height: 2.5px; border-radius: 2px; background: currentColor; transform: translateY(-3px); flex: none; }
.tgm-leg b { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-style: italic; font-size: 12.5px; font-weight: 700; color: currentColor; }
.tgm-leg.t-u, .tgm-leg.t-v, .tgm-leg.t-r, .tgm-leg.t-pos { }
.tgm-leg.is-dim { opacity: 0.45; }

.tgm-leg span { color: rgba(238,247,245,0.6); }

.tgm-eq { display: flex; flex-direction: column; gap: 3px; }
.tgm-eq-code { display: block; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; line-height: 1.5; letter-spacing: 0.01em; color: rgba(238,247,245,0.92); white-space: nowrap; overflow-x: auto; scrollbar-width: none; }
.tgm-eq-code::-webkit-scrollbar { display: none; }
.tgm-eq-code .op { color: rgba(238,247,245,0.45); }
.tgm-eq-code .dim { color: rgba(238,247,245,0.5); }
.tgm-eq-code b { font-weight: 700; }
.tgm-eq-sub { font-size: 11.5px; color: rgba(238,247,245,0.58); white-space: normal; }

.tgm-plot { width: 100%; aspect-ratio: 1 / 1; border: 1px solid rgba(255,255,255,0.09); border-radius: 14px;
  background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--tgm-u) 6%, transparent), transparent 60%), rgba(6,10,16,0.5); }
.tgm-grid line { stroke: rgba(255,255,255,0.05); stroke-width: 1; vector-effect: non-scaling-stroke; }
.tgm-axes line { stroke: rgba(255,255,255,0.18); stroke-width: 1; vector-effect: non-scaling-stroke; }
.tgm-origin { fill: rgba(238,247,245,0.85); }
.tgm-vec { stroke-width: 2.2; vector-effect: non-scaling-stroke; stroke-linecap: round; }
.tgm-vec-u { stroke: var(--tgm-u); } .tgm-head.tgm-vec-u { fill: var(--tgm-u); }
.tgm-vec-v { stroke: var(--tgm-v); } .tgm-head.tgm-vec-v { fill: var(--tgm-v); }
.tgm-vec-r { stroke: var(--tgm-seal); } .tgm-head.tgm-vec-r { fill: var(--tgm-seal); }
/* 注意：必须排在 .tgm-vec-* 颜色规则之后——同级特异性后者覆盖，否则箭头会
   吃到 1 个 SVG 单位粗的彩色描边（无 vector-effect），视觉膨胀约 3 倍。 */
.tgm-head { stroke: none !important; }
.tgm-err { stroke: var(--tgm-rose); stroke-width: 1.4; stroke-dasharray: 1.4 1; vector-effect: non-scaling-stroke; }

/* 图上直接写字：u / v / r / target 就标在各自尖端，不用回头对照图例 */
.tgm-lab {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: var(--tgm-lab); font-style: italic; font-weight: 700;
  text-anchor: middle; dominant-baseline: middle;
  paint-order: stroke; stroke: rgba(4,8,14,0.82); stroke-width: calc(var(--tgm-lab) * 0.3); stroke-linejoin: round;
}
.tgm-lab.tgm-vec-u { fill: var(--tgm-u); }
.tgm-lab.tgm-vec-v { fill: var(--tgm-v); }
.tgm-lab.tgm-vec-r { fill: var(--tgm-seal); }
.tgm-lab.tgm-vec-ax { fill: var(--tgm-v); }
.tgm-lab.tgm-vec-lx { fill: var(--tgm-seal); }
.tgm-lab.is-target { fill: var(--tgm-pos); font-style: normal; font-size: calc(var(--tgm-lab) * 0.82); }

.tgm-readout { display: flex; flex-direction: column; gap: 6px; }
.tgm-meter { position: relative; height: 6px; border-radius: 999px; overflow: hidden; background: rgba(255,255,255,0.08); }
.tgm-meter span { position: absolute; inset: 0; transform: scaleX(0); transform-origin: left center; border-radius: inherit; background: linear-gradient(90deg, var(--tgm-u), var(--tgm-seal), var(--tgm-pos)); box-shadow: 0 0 20px color-mix(in srgb, var(--tgm-seal) 24%, transparent); }
.tgm-status { margin: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; color: rgba(238,247,245,0.78); }
.tgm-status.is-ready { color: var(--tgm-pos); }

/* 本阶段做什么 —— 从左面板搬来，紧贴按键提示 */
.tgm-stage { padding: 9px 11px; border-radius: 12px; border: 1px solid color-mix(in srgb, var(--tgm-seal) 20%, transparent); background: color-mix(in srgb, var(--tgm-seal) 6%, transparent); }
.tgm-stage:empty { display: none; }
.tgm-stage h4 { margin: 0 0 4px; font-size: 12px; letter-spacing: 0.04em; color: var(--tgm-seal); }
.tgm-stage p { margin: 0; font-size: 12px; line-height: 1.58; color: rgba(238,247,245,0.8); }

.tgm-keys { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.tgm-keys .lbl { font-size: 11.5px; color: rgba(238,247,245,0.5); }
.tgm-keys .key { min-width: 20px; padding: 2px 6px; text-align: center; border-radius: 6px; border: 1px solid rgba(255,255,255,0.16); background: rgba(255,255,255,0.06); color: rgba(238,247,245,0.78); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11.5px; font-weight: 700; }
.tgm-keys .key.hot { border-color: color-mix(in srgb, var(--tgm-seal) 50%, transparent); background: color-mix(in srgb, var(--tgm-seal) 14%, transparent); color: #fff9df; box-shadow: 0 0 14px color-mix(in srgb, var(--tgm-seal) 16%, transparent); }
.tgm-foot { margin: 6px 0 0; font-size: 11.5px; line-height: 1.6; color: rgba(238,247,245,0.5); }

/* 折叠区：详细文字默认收起，需要时再展开（原先是四段并排硬塞在左边） */
.tgm-more { border-top: 1px solid rgba(255,255,255,0.07); padding-top: 8px; margin-top: 2px; }
.tgm-more > summary { list-style: none; cursor: pointer; font-size: 11.5px; letter-spacing: 0.04em; color: rgba(238,247,245,0.46); transition: color .2s ease; }
.tgm-more > summary::-webkit-details-marker { display: none; }
.tgm-more > summary::before { content: '＋ '; opacity: 0.7; }
.tgm-more[open] > summary::before { content: '－ '; }
.tgm-more > summary:hover { color: rgba(238,247,245,0.8); }
.tgm-more-body { margin-top: 7px; }
.tgm-more-body h4 { margin: 0 0 4px; font-size: 12px; letter-spacing: 0.04em; color: rgba(238,247,245,0.7); }
.tgm-more-body p { margin: 0; font-size: 12.5px; line-height: 1.65; color: rgba(238,247,245,0.74); }
.tgm-more-body b { color: rgba(238,247,245,0.95); font-weight: 600; }
.tgm-more-foot { border-top: none; padding-top: 0; }

/* ── 左：概念动图面板 ── */
.tgm-learn {
  position: fixed; left: 16px; top: 88px; width: var(--tgm-learn-w); max-height: calc(100vh - 118px);
  display: flex; flex-direction: column; pointer-events: auto; overflow: hidden;
  border: 1px solid rgba(255,255,255,0.10); border-radius: 18px;
  background: linear-gradient(180deg, rgba(7,12,19,0.80), rgba(7,12,19,0.58));
  backdrop-filter: blur(18px) saturate(1.06); -webkit-backdrop-filter: blur(18px) saturate(1.06);
  box-shadow: 0 18px 54px rgba(0,0,0,0.42); transition: width .3s ease;
}
.tgm-learn-toggle { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 11px 13px; border: none; background: transparent; cursor: pointer; width: 100%; color: var(--tgm-seal); font-size: 12.5px; letter-spacing: 0.07em; }
.tgm-learn-chevron { transition: transform .3s ease; opacity: 0.7; font-size: 17px; }
.tgm-learn-body { padding: 0 13px 13px; overflow: auto; scrollbar-width: thin; }
.tgm-learn.is-collapsed { width: 42px; }
.tgm-learn.is-collapsed .tgm-learn-title, .tgm-learn.is-collapsed .tgm-learn-body { display: none; }
.tgm-learn.is-collapsed .tgm-learn-toggle { justify-content: center; padding: 12px 0; }
.tgm-learn.is-collapsed .tgm-learn-chevron { transform: rotate(180deg); }

/* ── 顶部：讲解卡（横向卡在左右面板之间，不再压住 HUD 标题） ── */
.tgm-card {
  position: fixed; top: 88px;
  left: calc(var(--tgm-learn-w) + 32px); right: calc(var(--tgm-hud-w) + 32px);
  max-width: 560px; margin: 0 auto;
  transform: translateY(-12px); opacity: 0; pointer-events: none;
  padding: 14px 42px 14px 16px; z-index: 8;
  border: 1px solid rgba(255,255,255,0.13); border-radius: 16px;
  background: linear-gradient(180deg, rgba(10,15,24,0.95), rgba(8,12,20,0.88));
  backdrop-filter: blur(18px) saturate(1.05); -webkit-backdrop-filter: blur(18px) saturate(1.05);
  box-shadow: 0 24px 70px rgba(0,0,0,0.5); transition: opacity .35s ease, transform .35s ease;
}
.tgm-card[hidden] { display: none; }
.tgm-card.is-visible { opacity: 1; transform: translateY(0); pointer-events: auto; }
.tgm-card-eyebrow { font-size: 10.5px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--tgm-seal); }
.tgm-card h4 { margin: 4px 0 5px; font-size: 15.5px; color: var(--tgm-text); letter-spacing: 0.04em; }
.tgm-card p { margin: 0 0 6px; font-size: 12.8px; line-height: 1.62; color: rgba(238,247,245,0.8); }
.tgm-card code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; color: var(--tgm-seal); }
.tgm-card-close { position: absolute; top: 9px; right: 11px; width: 24px; height: 24px; padding: 0; border: 1px solid rgba(255,255,255,0.14); border-radius: 999px; background: rgba(255,255,255,0.05); color: rgba(238,247,245,0.7); cursor: pointer; font-size: 15px; line-height: 1; }

@media (prefers-reduced-motion: reduce) { .tgm-root, .tgm-hud, .tgm-learn, .tgm-card { transition: none; } }
@media (max-width: 1180px) {
  .tgm-root { --tgm-learn-w: 232px; }
}
@media (max-width: 1040px) {
  .tgm-learn { display: none; }
  .tgm-root { --tgm-hud-w: min(320px, 46vw); --tgm-learn-w: 0px; }
  .tgm-card { left: 16px; right: calc(var(--tgm-hud-w) + 24px); }
}

/* ── L2 专属图层：填充平行四边形 + 目标幽灵方块 ── */
.l2-para { fill: color-mix(in srgb, var(--tgm-pos) 18%, transparent); stroke: var(--tgm-pos); stroke-width: 1.3; vector-effect: non-scaling-stroke; transition: fill .3s ease, stroke .3s ease; }
.l2-para.is-negative { fill: color-mix(in srgb, var(--tgm-neg) 18%, transparent); stroke: var(--tgm-neg); }
.l2-target-ghost { fill: none; stroke: color-mix(in srgb, var(--tgm-seal) 55%, transparent); stroke-width: 1.2; stroke-dasharray: 1.6 1.1; vector-effect: non-scaling-stroke; }

/* ── L3 专属图层：单位圆 + 理论轴 + x / Ax / λ̂x ── */
.l3-unit-circle { fill: none; stroke: rgba(255,255,255,0.12); stroke-width: 1; vector-effect: non-scaling-stroke; }
.l3-eigen-axis { stroke: color-mix(in srgb, var(--tgm-seal) 30%, transparent); stroke-width: 1; stroke-dasharray: 2.2 1.6; vector-effect: non-scaling-stroke; }
.l3-locked-axis { stroke: var(--tgm-seal); stroke-width: 2; vector-effect: non-scaling-stroke; filter: drop-shadow(0 0 3px color-mix(in srgb, var(--tgm-seal) 60%, transparent)); }
.l3-probe-axis { stroke: color-mix(in srgb, var(--tgm-u) 35%, transparent); stroke-width: 1; vector-effect: non-scaling-stroke; }
.l3-gap { stroke: var(--tgm-rose); stroke-width: 1.6; stroke-dasharray: 1.2 0.9; vector-effect: non-scaling-stroke; }
.tgm-vec-ax { stroke: var(--tgm-v); } .tgm-head.tgm-vec-ax { fill: var(--tgm-v); }
.tgm-vec-lx { stroke: var(--tgm-seal); } .tgm-head.tgm-vec-lx { fill: var(--tgm-seal); }
