/* 第一关「数学化」UI —— 可复用样式（根外壳与单独第一关页面共用）。
   变量作用域限定在 #l1Math，避免依赖/污染各页面自己的 :root。
   结构与 math-ui-base.css（L2/L3）保持同构：左概念动图 / 右数学 HUD / 顶部讲解卡。 */

#l1Math {
  --u: #73e2ff; --v: #ffb06f; --seal: #f6edc8; --green: #b3ffd7; --rose: #ff8fb8; --text: #eef7f5;
  --ca-u: #73e2ff; --ca-v: #ffb06f; --ca-seal: #f6edc8; --ca-pos: #b3ffd7; --ca-neg: #8db4ff; --ca-rose: #ff8fb8;
  --l1-lab: 0.9px;
  --l1-hud-w: min(336px, 31vw);
  --l1-learn-w: min(272px, 25vw);
  position: fixed; inset: 0; z-index: 6; pointer-events: none; opacity: 0; visibility: hidden; transition: opacity .32s ease;
}
body.l1-active #l1Math { opacity: 1; visibility: visible; }
/* 开场/说明等 overlay 打开时淡出 */
body.overlay-open #l1Math { opacity: 0; pointer-events: none; }
/* 数学 UI 接管 HUD：隐藏外壳旧面板（unified-hud/coop-ribbon）与单独页面的角落卡片（hud/center-prompt） */
body.l1-active .unified-hud, body.l1-active .coop-ribbon,
body.l1-active .hud, body.l1-active .center-prompt { display: none; }

#l1Math .t-u { color: var(--u); }
#l1Math .t-v { color: var(--v); }
#l1Math .t-r { color: var(--seal); }

/* ── 右：数学 HUD ── */
.l1-hud {
  position: fixed; right: 16px; top: 88px; max-height: calc(100vh - 106px);
  width: var(--l1-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;
}
body.l1-active .l1-hud { transform: translateY(0); }
.l1-hud-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.l1-hud-head h2 { margin: 0; font-size: 17px; letter-spacing: 0.14em; font-weight: 600; color: var(--text); white-space: nowrap; }
.l1-phases { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }
.l1-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; }
.l1-phase.is-active { color: #fff; border-color: rgba(246,237,200,0.5); background: rgba(246,237,200,0.14); box-shadow: 0 0 18px rgba(246,237,200,0.18); }

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


.l1-eq { display: flex; flex-direction: column; gap: 3px; }
.l1-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; }
.l1-eq-code::-webkit-scrollbar { display: none; }
.l1-eq-code .op { color: rgba(238,247,245,0.45); }
.l1-eq-code .dim { color: rgba(238,247,245,0.5); }
.l1-eq-code b { font-weight: 700; }
.l1-eq-sub { font-size: 11.5px; color: rgba(238,247,245,0.58); white-space: normal; }

.l1-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%, rgba(115,226,255,0.06), transparent 60%), rgba(6,10,16,0.5); }
.l1-grid line { stroke: rgba(255,255,255,0.05); stroke-width: 1; vector-effect: non-scaling-stroke; }
.l1-axes line { stroke: rgba(255,255,255,0.18); stroke-width: 1; vector-effect: non-scaling-stroke; }
.l1-origin { fill: rgba(238,247,245,0.85); }
.l1-target { fill: none; stroke: var(--green); stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.l1-err { stroke: var(--rose); stroke-width: 1.4; stroke-dasharray: 1.4 1; vector-effect: non-scaling-stroke; }
.l1-para { fill: rgba(246,237,200,0.06); stroke: rgba(246,237,200,0.4); stroke-width: 1; stroke-dasharray: 1 0.8; vector-effect: non-scaling-stroke; }
.l1-vec { stroke-width: 2.2; vector-effect: non-scaling-stroke; stroke-linecap: round; }
.l1-vec-u { stroke: var(--u); } .l1-vec-v { stroke: var(--v); } .l1-vec-r { stroke: var(--seal); }
.l1-head { stroke: none; }
.l1-head.l1-vec-u { fill: var(--u); } .l1-head.l1-vec-v { fill: var(--v); } .l1-head.l1-vec-r { fill: var(--seal); }

/* 图上直接标注：u / v / r / 目标 各写在自己的尖端旁 */
.l1-lab {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: var(--l1-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(--l1-lab) * 0.3); stroke-linejoin: round;
}
.l1-lab.l1-vec-u { fill: var(--u); }
.l1-lab.l1-vec-v { fill: var(--v); }
.l1-lab.l1-vec-r { fill: var(--seal); }
.l1-lab.is-target { fill: var(--green); font-style: normal; font-size: calc(var(--l1-lab) * 0.82); }

/* 阶段化显示：前两阶段只有 u，图上不出现 v / r / 平行四边形 / 误差线 */
.l1-plot[data-phase="size"] .l1-vec-v, .l1-plot[data-phase="size"] .l1-vec-r, .l1-plot[data-phase="size"] .l1-para, .l1-plot[data-phase="size"] .l1-err,
.l1-plot[data-phase="angle"] .l1-vec-v, .l1-plot[data-phase="angle"] .l1-vec-r, .l1-plot[data-phase="angle"] .l1-para, .l1-plot[data-phase="angle"] .l1-err { display: none; }

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

/* 本阶段做什么 —— 紧贴按键提示 */
.l1-stage { padding: 9px 11px; border-radius: 12px; border: 1px solid rgba(246,237,200,0.2); background: rgba(246,237,200,0.06); }
.l1-stage:empty { display: none; }
.l1-stage h4 { margin: 0 0 4px; font-size: 12px; letter-spacing: 0.04em; color: var(--seal); }
.l1-stage p { margin: 0; font-size: 12px; line-height: 1.58; color: rgba(238,247,245,0.8); }

.l1-keys { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.l1-keys .lbl { font-size: 11.5px; color: rgba(238,247,245,0.5); }
.l1-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; }
.l1-keys .key.hot { border-color: rgba(246,237,200,0.5); background: rgba(246,237,200,0.14); color: #fff9df; box-shadow: 0 0 14px rgba(246,237,200,0.16); }

/* ── 左：概念动图面板 ── */
.l1-learn {
  position: fixed; left: 16px; top: 88px; width: var(--l1-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;
}
.l1-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(--seal); font-size: 12.5px; letter-spacing: 0.07em; }
.l1-learn-chevron { transition: transform .3s ease; opacity: 0.7; font-size: 17px; }
.l1-learn-body { padding: 0 13px 13px; overflow: auto; scrollbar-width: thin; }
.l1-learn.is-collapsed { width: 42px; }
.l1-learn.is-collapsed .l1-learn-title, .l1-learn.is-collapsed .l1-learn-body { display: none; }
.l1-learn.is-collapsed .l1-learn-toggle { justify-content: center; padding: 12px 0; }
.l1-learn.is-collapsed .l1-learn-chevron { transform: rotate(180deg); }

/* 折叠区：完整文字说明默认收起 */
.l1-more { border-top: 1px solid rgba(255,255,255,0.07); padding-top: 8px; margin-top: 11px; }
.l1-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; }
.l1-more > summary::-webkit-details-marker { display: none; }
.l1-more > summary::before { content: '＋ '; opacity: 0.7; }
.l1-more[open] > summary::before { content: '－ '; }
.l1-more > summary:hover { color: rgba(238,247,245,0.8); }
.l1-more-body { margin-top: 7px; }
.l1-more-body h4 { margin: 0 0 4px; font-size: 12px; letter-spacing: 0.04em; color: rgba(238,247,245,0.7); }
.l1-more-body p { margin: 0; font-size: 12.5px; line-height: 1.65; color: rgba(238,247,245,0.74); }
.l1-more-body b { color: rgba(238,247,245,0.95); font-weight: 600; }

/* ── 顶部：阶段讲解卡（卡在左右面板之间，不再压住 HUD 标题） ── */
.l1-card {
  position: fixed; top: 88px;
  left: calc(var(--l1-learn-w) + 32px); right: calc(var(--l1-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;
}
.l1-card[hidden] { display: none; }
.l1-card.is-visible { opacity: 1; transform: translateY(0); pointer-events: auto; }
.l1-card-eyebrow { font-size: 10.5px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--seal); }
.l1-card h4 { margin: 4px 0 5px; font-size: 15.5px; color: var(--text); letter-spacing: 0.04em; }
.l1-card p { margin: 0 0 6px; font-size: 12.8px; line-height: 1.62; color: rgba(238,247,245,0.8); }
.l1-card code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; color: var(--seal); }
.l1-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) { #l1Math, .l1-hud, .l1-learn, .l1-card { transition: none; } }
@media (max-width: 1180px) { #l1Math { --l1-learn-w: 232px; } }
@media (max-width: 1040px) {
  .l1-learn { display: none; }
  #l1Math { --l1-hud-w: min(320px, 46vw); --l1-learn-w: 0px; }
  .l1-card { left: 16px; right: calc(var(--l1-hud-w) + 24px); }
}
