/* ═══════════════════════════════════════════════════════════════════════════
   quark-visualizer · 样式
   ───────────────────────────────────────────────────────────────────────────
   设计语言承接参考实现（暗色 + 等宽字体 + 青/金/粉三色 + 玻璃层次），
   但结构改为「左栏结构树 + 右栏舞台」的玻璃盒双栏布局。

   三条必须守住的规则（来自 Phase 0/1 的实测结论）：
     1. 张量配色：青 = 正、粉 = 负（--pos-color / --neg-color）
     2. 遮罩格必须与「接近 0」区分开：遮罩用斜纹，不参与配色
     3. 单元格里字号极小，格式化必须自适应量级，不能统一 toFixed(1)
        （否则大量 <1e-4 的注意力权重会显示成 0，等于撒谎）
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  --bg-base: #0a0e1a;
  --bg-elev-1: #111729;
  --bg-elev-2: #1a2238;
  --bg-elev-3: #222c47;
  --border-soft: rgba(255, 255, 255, 0.06);
  --border-mid: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.2);
  --text-primary: #e6e9f2;
  --text-secondary: #8b95c7;
  --text-muted: #5a6485;
  --accent-cyan: #00d4ff;
  --accent-gold: #ffc94d;
  --accent-pink: #ff6b9d;
  --accent-green: #4ade80;
  --accent-violet: #a78bfa;
  --pos-color: 0, 212, 255;
  --neg-color: 255, 107, 157;
  --mask-bg: rgba(80, 85, 100, 0.18);
  --mask-text: #ff6b9d;
  --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'JetBrains Mono', 'SF Mono', 'Consolas', 'Monaco', monospace;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(0, 212, 255, 0.06), transparent 70%),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(255, 107, 157, 0.04), transparent 70%),
    var(--bg-base);
  background-attachment: fixed;
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

.katex { color: var(--text-primary) !important; }
.note .katex { color: var(--text-secondary) !important; }

/* ── 行内数学（tensor-view.js 的 tex()）────────────────────────────
   块级公式走 .katex-display，行内不行 —— 行内必须跟着正文走：
   ① font-size 压回 1em（KaTeX 默认 1.21em），否则行内公式比周围字大一圈，
      行高被顶开，正文段落看着忽松忽紧；
   ② display:inline-block + 负的上下 margin 抵消 KaTeX 自带 strut 高度，
      这是行内公式不破坏 line-height 的关键；
   ③ 不换行：一个符号拆两行比溢出更糟。
   ──────────────────────────────────────────────────────────────── */
.katex-inline { display: inline-block; white-space: nowrap; }
.katex-inline > .katex { font-size: 1em; }
.katex-inline .katex .base { margin: 0; }
/* 颜色必须跟随所在文字。上面那条 `.katex { color: primary !important }` 是为块级
   公式设的，但行内公式散落在各种有色上下文里（粉色的 shape 角标、金色的 badge、
   结构树按节点上色、备注的次要灰…），一旦被强制成 primary，这些语义色全被冲掉。
   行内数学的正确语义就是「跟周围文字同色」。 */
.katex-inline .katex { color: inherit !important; }
/* KaTeX 未加载时的降级：显示 TeX 源码，而不是留一片空白 */
.tex-fallback {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.94em;
  color: var(--accent-gold);
  background: rgba(255, 201, 77, 0.08);
  border-radius: 3px;
  padding: 0 3px;
}

/* ── SVG 结构树里的富标注（model-tree.js 的 foText()）──────────────
   <text> 装不下 KaTeX，只能用 <foreignObject> 内嵌 HTML。它的 y 是盒顶
   不是 baseline，垂直居中由 flex 负责（见 foText）。此处只定字体与对齐，
   尺寸/颜色是逐节点写进 style 的 —— 那是数据，不是样式。
   ──────────────────────────────────────────────────────────────── */
.fo-box { overflow: visible; }
.fo-in { line-height: 1; }
.fo-in > .katex-inline { vertical-align: baseline; }
.fo-in .katex { color: inherit !important; font-size: 1em; }
a { color: var(--accent-cyan); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ───────────────────────────────── 顶栏 */

header {
  padding: 10px 20px 8px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(10, 14, 26, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}
.header-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
h1 {
  color: var(--accent-cyan); font-size: 16px; font-weight: 600;
  text-shadow: 0 0 12px rgba(0, 212, 255, 0.3);
  letter-spacing: 0.5px; white-space: nowrap;
}
.params { display: flex; gap: 4px; flex-wrap: wrap; }
.param {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 6px; background: var(--bg-elev-1);
  border: 1px solid var(--border-soft); border-radius: 10px; font-size: 9.5px;
}
.param .k { color: var(--text-muted); }
.param .k sub { font-size: 0.8em; }
.param .v { color: var(--accent-cyan); font-weight: 600; }
.param.hot .v { color: var(--accent-pink); }

.badge {
  padding: 2px 8px; border-radius: 4px; font-size: 9.5px; font-weight: bold;
  white-space: nowrap; border: 1px solid transparent;
}
.badge-pink { background: rgba(255, 107, 157, 0.15); border-color: rgba(255, 107, 157, 0.4); color: var(--accent-pink); }
.badge-gold { background: rgba(255, 201, 77, 0.15); border-color: rgba(255, 201, 77, 0.4); color: var(--accent-gold); }
.badge-violet { background: rgba(167, 139, 250, 0.15); border-color: rgba(167, 139, 250, 0.4); color: var(--accent-violet); }
.badge-cyan { background: rgba(0, 212, 255, 0.12); border-color: rgba(0, 212, 255, 0.35); color: var(--accent-cyan); }
.badge-green { background: rgba(74, 222, 128, 0.12); border-color: rgba(74, 222, 128, 0.35); color: var(--accent-green); }
.ml-auto { margin-left: auto; }

/* ───────────────────────────────── 控件 */

.controls-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.controls-label { color: var(--text-muted); font-size: 11px; }

.btn-base, .btn-primary {
  background: var(--bg-elev-1); border: 1px solid var(--border-mid);
  color: var(--text-secondary); padding: 5px 12px; border-radius: 5px;
  font-family: inherit; font-size: 11px; cursor: pointer; transition: all 0.2s ease;
}
.btn-base:hover, .btn-primary:hover:not(:disabled) {
  border-color: var(--accent-cyan); color: var(--accent-cyan);
  box-shadow: 0 0 8px rgba(0, 212, 255, 0.2);
}
.btn-primary {
  background: linear-gradient(135deg, rgba(0, 212, 255, 0.15), rgba(0, 212, 255, 0.05));
  color: var(--accent-cyan); border-color: rgba(0, 212, 255, 0.4);
}
.btn-primary:disabled, .btn-base:disabled { opacity: 0.3; cursor: not-allowed; }

input[type="text"] {
  background: var(--bg-elev-1); border: 1px solid var(--border-mid);
  color: var(--text-primary); padding: 4px 8px; border-radius: 5px;
  font-family: inherit; width: 190px; font-size: 11px;
}
input[type="text"]:focus { outline: none; border-color: var(--accent-cyan); }

.config-group {
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  background: var(--bg-elev-1); border: 1px solid var(--border-soft);
  padding: 6px 12px; border-radius: 8px;
}
.slider-group { display: flex; flex-direction: column; gap: 2px; font-size: 10px; color: var(--text-muted); }
.slider-group span { display: flex; justify-content: space-between; gap: 10px; }
.slider-group b { color: var(--accent-cyan); font-weight: 500; }
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100px; height: 4px; background: var(--bg-base); border-radius: 2px; outline: none; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 12px; height: 12px;
  background: var(--accent-cyan); border-radius: 50%; cursor: pointer;
  box-shadow: 0 0 4px rgba(0, 212, 255, 0.5);
}
.disabled-group { opacity: 0.4; pointer-events: none; }

.mode-switch { display: flex; gap: 2px; background: var(--bg-base); border-radius: 6px; padding: 2px; }
.mode-btn {
  background: transparent; border: none; color: var(--text-muted);
  padding: 3px 8px; font-size: 10px; cursor: pointer;
  border-radius: 4px; font-family: inherit; transition: all 0.2s;
}
.mode-btn:hover { color: var(--text-secondary); }
.mode-btn.active { background: rgba(0, 212, 255, 0.15); color: var(--accent-cyan); }
#stepInfo {
  color: var(--accent-cyan); font-size: 11px; padding: 3px 10px;
  background: rgba(0, 212, 255, 0.08); border-radius: 20px;
  border: 1px solid rgba(0, 212, 255, 0.15); white-space: nowrap; flex-shrink: 0;
}

/* 词汇表面板 */
.vocab-panel {
  max-height: 0; overflow: hidden; transition: max-height 0.3s ease-out, padding 0.3s ease-out;
  background: var(--bg-elev-2); border-top: 1px solid transparent;
}
.vocab-panel.open { max-height: 320px; padding: 12px 20px; border-top: 1px solid var(--border-soft); overflow-y: auto; }

/* ───────────────────────────────── 步骤导航（两级） */

.step-nav-wrapper { display: flex; align-items: center; gap: 16px; margin-top: 6px; }
.step-nav {
  display: flex; gap: 5px; overflow-x: auto; padding: 6px 2px; flex: 1 1 auto;
  scrollbar-width: thin; scrollbar-color: rgba(0, 212, 255, 0.3) transparent;
}
/* ★ 两端渐隐只在「那一侧确实有被滚出的内容」时才挂（由 main.js 的 syncNavFade 加类）。
   以前是无条件挂 16px 渐隐 —— 6 张卡在宽屏下全放得下、根本没有被滚出的内容，
   却把第一张卡「词嵌入」压在左侧渐隐区里，**左边沿被淡没了**。
   渐隐的语义是「这边还有内容」，没有内容就不该出现。 */
.step-nav.fade-left { -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 16px); mask-image: linear-gradient(90deg, transparent 0, #000 16px); }
.step-nav.fade-right { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 16px), transparent 100%); mask-image: linear-gradient(90deg, #000 calc(100% - 16px), transparent 100%); }
.step-nav.fade-left.fade-right { -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 16px, #000 calc(100% - 16px), transparent 100%); mask-image: linear-gradient(90deg, transparent 0, #000 16px, #000 calc(100% - 16px), transparent 100%); }
.step-nav::-webkit-scrollbar { height: 4px; }
.step-nav::-webkit-scrollbar-thumb { background: rgba(0, 212, 255, 0.2); border-radius: 2px; }

.step-card {
  flex-shrink: 0; min-width: 96px; padding: 5px 8px;
  background: var(--bg-elev-1); border: 1px solid var(--border-soft);
  border-radius: 5px; cursor: pointer; user-select: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative; overflow: hidden;
}
.step-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, var(--accent-gold), var(--accent-pink));
  opacity: 0; transition: opacity 0.3s;
}
.step-card:hover { border-color: var(--border-mid); transform: translateY(-1px); }
.step-card.active {
  background: linear-gradient(135deg, rgba(255, 201, 77, 0.12), rgba(255, 107, 157, 0.08));
  border-color: rgba(255, 201, 77, 0.6);
  box-shadow: 0 0 0 1px rgba(255, 201, 77, 0.2), 0 4px 16px rgba(255, 201, 77, 0.15);
  transform: scale(1.05);
}
.step-card.active::before { opacity: 1; }
.step-card .num { color: var(--text-muted); font-size: 8px; font-weight: 600; }
.step-card.active .num { color: var(--accent-gold); }
.step-card .label {
  color: var(--text-secondary); font-size: 9.5px; margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.step-card.active .label { color: #fff; }
.step-card.visited { border-color: rgba(0, 212, 255, 0.2); }

.sub-step-nav { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.sub-step-item {
  padding: 4px 10px; border-radius: 4px; font-size: 10.5px;
  border: 1px solid var(--border-soft); background: var(--bg-elev-1);
  color: var(--text-muted); transition: all 0.3s; cursor: pointer;
}
.sub-step-item.visited { border-color: rgba(0, 212, 255, 0.2); color: var(--text-secondary); }
.sub-step-item.active { background: rgba(0, 212, 255, 0.1); color: var(--accent-cyan); border-color: rgba(0, 212, 255, 0.3); }

/* Block 层切换器（第②步顶部：Block 0…3）。以前没有任何样式 ——
   裸按钮 + active 类无高亮，当前在第几层看不出来。 */
.layer-switcher { display: flex; gap: 6px; justify-content: center; margin: 4px 0 2px; flex-wrap: wrap; }
.layer-btn {
  padding: 4px 14px; border-radius: 4px; font-size: 10.5px; font-weight: 600;
  border: 1px solid var(--border-soft); background: var(--bg-elev-1);
  color: var(--text-muted); transition: all 0.25s; cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
}
.layer-btn:hover { color: var(--text-secondary); border-color: var(--border-mid); }
.layer-btn.active {
  background: rgba(255, 201, 77, 0.12); color: var(--accent-gold);
  border-color: rgba(255, 201, 77, 0.45);
  box-shadow: 0 0 10px rgba(255, 201, 77, 0.18);
}

/* ───────────────────────────────── 双栏主体 */

main { padding: 18px 20px 48px; max-width: 1600px; margin: 0 auto; }

.layout { display: grid; grid-template-columns: 326px minmax(0, 1fr); gap: 18px; align-items: start; }
/* ★ `1fr` 等价于 `minmax(auto, 1fr)`，那个 `auto` 是**内容的 min-content** ——
   只要舞台里出现一个比可用宽度还宽的元素（如 ③ 的 W_norm：96 列 × 20px ≈ 1920px），
   这一列就会被顶宽（实测舞台 1182 → 2166），页面级出现横向滚动、右侧内容被推出屏幕。
   `minmax(0, 1fr)` 把下限钉成 0，舞台宽度从此只由视口决定（＝视口 − 386）。 */
@media (max-width: 1180px) { .layout { grid-template-columns: minmax(0, 1fr); } }

.panel {
  background: rgba(17, 23, 41, 0.5); border: 1px solid var(--border-soft);
  border-radius: 10px; padding: 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03), var(--shadow-card);
}
.panel + .panel { margin-top: 14px; }
.panel-title {
  color: var(--accent-cyan); font-size: 11px; font-weight: 600;
  letter-spacing: 0.4px; margin-bottom: 9px; display: flex;
  align-items: center; justify-content: space-between; gap: 8px;
}
.panel-title .hint { color: var(--text-muted); font-weight: 400; font-size: 9.5px; }

.stage {
  display: flex; flex-direction: column; gap: 16px; padding: 20px;
  background: rgba(17, 23, 41, 0.4); border: 1px solid var(--border-soft);
  border-radius: 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03), var(--shadow-card);
  animation: slideIn 0.45s ease-out;
}

@keyframes slideIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes popIn { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.step-title-row { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.step-title { color: var(--accent-gold); font-size: 20px; font-weight: 600; text-shadow: 0 0 12px rgba(255, 201, 77, 0.2); }
.step-desc { color: var(--text-secondary); font-size: 13px; line-height: 1.75; max-width: 980px; }
.step-desc strong { color: var(--text-primary); }
.step-desc code {
  background: var(--bg-elev-2); border: 1px solid var(--border-soft);
  padding: 1px 5px; border-radius: 3px; font-size: 11.5px; color: var(--accent-gold);
}

.sub-formula {
  background: rgba(255, 201, 77, 0.05); border: 1px solid rgba(255, 201, 77, 0.2);
  border-left: 3px solid var(--accent-gold); border-radius: 6px;
  padding: 8px 20px; display: flex; align-items: center;
}
.sub-formula .katex-display { margin: 0; }
.sub-formula .katex { font-size: 1.1em; color: var(--accent-gold) !important; }

/* ───────────────────────────────── 结构树 */

.tree-wrap { overflow-x: auto; }
.tree-node { cursor: pointer; }
.tree-node rect { transition: all 0.2s ease; }
.tree-node:hover rect { filter: brightness(1.35); }
.tree-node.active rect { stroke-width: 2; }

/* 权重检视器 */
.wtable { width: 100%; border-collapse: collapse; font-size: 10px; }
.wtable th {
  text-align: left; color: var(--text-muted); font-weight: 500;
  padding: 3px 4px; border-bottom: 1px solid var(--border-soft); font-size: 9.5px;
}
.wtable td { padding: 3px 4px; border-bottom: 1px solid rgba(255, 255, 255, 0.03); color: var(--text-secondary); }
.wtable tr:hover td { background: rgba(0, 212, 255, 0.05); color: var(--text-primary); }
.wtable td.num { text-align: right; color: var(--text-muted); }
.wtable td.shape { color: var(--accent-pink); font-size: 9.5px; }
.wtable td.kind { color: var(--accent-violet); font-size: 9px; }
.wsum { display: flex; gap: 10px; flex-wrap: wrap; font-size: 10px; margin-top: 8px; }
.wsum div { color: var(--text-muted); }
.wsum b { color: var(--accent-cyan); font-weight: 600; }

/* ───────────────────────────────── 序列 / token */

.sequence-display {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 16px; background: var(--bg-elev-1);
  border: 1px solid var(--border-soft); border-radius: 8px;
}
.token-pill {
  padding: 6px 12px; background: var(--bg-base); border: 1px solid var(--border-mid);
  border-radius: 16px; font-size: 12px; color: var(--text-primary);
  display: flex; align-items: center; gap: 6px; transition: all 0.3s;
}
.token-pill .id { color: var(--text-muted); font-size: 9px; }
.token-pill .raw { color: var(--text-muted); font-size: 9.5px; border-left: 1px solid var(--border-soft); padding-left: 6px; }
.token-pill.context { border-color: rgba(0, 212, 255, 0.3); }
.token-pill.context .word { color: var(--accent-cyan); }
.token-pill.new { border-color: var(--accent-gold); background: rgba(255, 201, 77, 0.1); box-shadow: 0 0 12px rgba(255, 201, 77, 0.3); animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }
.token-pill.new .word { color: var(--accent-gold); font-weight: 600; }
.token-pill.predicted { border-style: dashed; border-color: var(--accent-green); background: rgba(74, 222, 128, 0.1); animation: popIn 0.3s ease-out; }
.token-pill.predicted .word { color: var(--accent-green); }
.token-pill.special { border-color: rgba(167, 139, 250, 0.5); background: rgba(167, 139, 250, 0.1); }
.token-pill.special .word { color: var(--accent-violet); }
.token-pill.orphan { border-color: rgba(255, 107, 157, 0.5); border-style: dotted; }
.token-pill.orphan .word { color: var(--accent-pink); }

.vocab-display { display: flex; flex-wrap: wrap; gap: 4px; }
.vocab-item {
  padding: 3px 8px; border-radius: 4px; font-size: 10.5px;
  border: 1px solid var(--border-soft); color: var(--text-secondary); background: var(--bg-base);
}
.vocab-item .vid { color: var(--text-muted); margin-right: 4px; font-size: 9px; }
.vocab-item.special { border-color: rgba(167, 139, 250, 0.4); color: var(--accent-violet); }
.vocab-item.orphan { border-color: rgba(255, 107, 157, 0.4); color: var(--accent-pink); }
.vocab-item.masked { opacity: 0.45; }

/* ───────────────────────────────── 张量 */

.tensor-group { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; justify-content: center; }
.tensor-group.col { flex-direction: column; align-items: stretch; }
.tensor {
  display: inline-block; padding: 6px; background: var(--bg-elev-1);
  border: 1px solid var(--border-soft); border-radius: 7px;
  transition: all 0.3s ease; max-width: 100%;
}
.tensor.highlight { border-color: rgba(255, 201, 77, 0.5); background: rgba(255, 201, 77, 0.03); }
.tensor.result { border-color: rgba(74, 222, 128, 0.5); background: rgba(74, 222, 128, 0.03); animation: fadeIn 0.4s ease-out; }
.tensor.neg { border-color: rgba(255, 107, 157, 0.5); background: rgba(255, 107, 157, 0.03); }
.tensor-title {
  color: var(--accent-cyan); font-size: 10.5px; font-weight: 600;
  margin-bottom: 5px; text-align: center; letter-spacing: 0.3px;
}
.tensor-title .shape { color: var(--accent-pink); font-size: 9px; margin-left: 3px; }
.tensor-title .tip { color: var(--text-muted); font-size: 8.5px; font-weight: 400; display: block; margin-top: 2px; }
/* 张量标题里的权重路径（<code>）。必须显式定字号：浏览器给 <code> 的默认 monospace
   字号是 13px，会把 10.5px 的标题整个撑大，并连带把卡片加宽（卡片宽度由标题与
   画布两者的最大内容宽决定 —— 见 tensor-view.js 的 heatBody）。 */
.tensor-title code {
  font-family: inherit; font-size: 9.5px; font-weight: 400; letter-spacing: 0;
  color: var(--accent-gold); background: var(--bg-elev-2);
  padding: 1px 4px; border-radius: 3px; white-space: nowrap;
}
.tensor-scroll {
  max-width: 100%; overflow-x: auto;
  /* ★ 只写 overflow-x: auto 是不够的：Chrome/Edge 现在默认用 **overlay 滚动条** ——
     不占布局空间、不滚动时几乎看不见（实测 offsetHeight−clientHeight === 0）。
     显式给出 scrollbar-color / scrollbar-width（非 auto 值）会让 Chromium 切回
     **常驻的经典滚动条**，用户才真的看得见「这边还能往右滚」。 */
  scrollbar-width: thin;
  scrollbar-color: rgba(120, 160, 220, 0.55) rgba(255, 255, 255, 0.06);
}
.tensor-scroll::-webkit-scrollbar { height: 9px; }
.tensor-scroll::-webkit-scrollbar-track { background: rgba(255, 255, 255, 0.06); border-radius: 5px; }
.tensor-scroll::-webkit-scrollbar-thumb { background: rgba(120, 160, 220, 0.55); border-radius: 5px; }
.tensor-scroll::-webkit-scrollbar-thumb:hover { background: rgba(120, 160, 220, 0.85); }
/* ★ 网格型张量（cells 模式）里的卡片必须允许**收缩到容器宽**，横向溢出交给内层 .tensor-scroll。
   为什么单靠 `.tensor { max-width: 100% }` 不够：卡片是 flex/grid item，它的
   **自动最小尺寸 = min-width: auto = 内容 min-content**（96 列 × 20px ≈ 1920px），
   min-width 优先级高于 max-width → 卡片照样 1924px 宽，`.tensor-scroll` 的
   max-width:100% 跟着变成 1924，滚动条永远不出现，溢出却照旧。
   `min-width: 0` 才是让内层滚动条真正生效的那一刀。 */
.tensor.tensor-scrollable { min-width: 0; }
.tensor-grid { display: grid; gap: 2px; }
/* ★ 可选的「轨道块在卡片内左右居中」。
   没有它时：`justify-content: normal` 对 grid 视同 stretch，`auto` 标签列会吸走
   全部剩余空白 → 数据列被顶到卡片最右边缘（数据列越少越刺眼，如 [12×1] / [10×3]）。
   有它时：auto 轨道不再拉伸，整块轨道在卡片里居中。
   ⚠ `safe` 不能省：轨道比容器宽时（[1×96] ≈ 1920px）普通 center 会把起点推到负坐标，
     左侧溢出**永远滚不回来**；`safe` 在溢出时退回 start，横向滚动照常。 */
.tensor-grid.center { justify-content: safe center; }
.cell {
  display: flex; align-items: center; justify-content: center;
  color: rgba(255, 255, 255, 0.95); border-radius: 2px; overflow: hidden;
  font-variant-numeric: tabular-nums; letter-spacing: -0.3px; font-size: 8px;
  background: rgba(255, 255, 255, 0.02);
}
.cell.label { background: transparent !important; color: var(--text-muted); font-weight: 600; font-size: 8px; }
.cell.axis-x { background: transparent !important; color: var(--text-muted); font-weight: 600; font-size: 7.5px; }
.cell.row-highlight { background: rgba(255, 107, 157, 0.3) !important; outline: 1px solid var(--accent-pink); outline-offset: -1px; z-index: 1; color: #fff; font-weight: bold; }
.cell.masked {
  background: repeating-linear-gradient(45deg, var(--mask-bg), var(--mask-bg) 3px, rgba(255, 107, 157, 0.12) 3px, rgba(255, 107, 157, 0.12) 6px) !important;
  color: var(--mask-text) !important; font-weight: bold;
}
/* 高亮行里的真 −∞：保留斜纹（它仍是遮罩），只叠加高亮描边。
   以前 JS 会 remove('masked')，遮罩格因此丢掉斜纹、看起来像个普通格子。 */
.cell.masked.row-highlight {
  background: repeating-linear-gradient(45deg, var(--mask-bg), var(--mask-bg) 3px, rgba(255, 107, 157, 0.12) 3px, rgba(255, 107, 157, 0.12) 6px) !important;
  outline: 1px solid var(--accent-pink); outline-offset: -1px; z-index: 1;
}
.cell.row-live { outline: 1px solid rgba(74, 222, 128, 0.7); outline-offset: -1px; z-index: 2; }

.empty-tensor-box {
  border: 1px dashed var(--border-mid); border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 9px; margin: 2px; min-height: 30px;
}
.op { display: flex; align-items: center; justify-content: center; color: var(--accent-gold); min-width: 20px; font-weight: 700; text-shadow: 0 0 8px rgba(255, 201, 77, 0.3); font-size: 14px; }
.op.vert { padding: 2px 0; }

.canvas-wrap { display: flex; flex-direction: column; align-items: center; gap: 4px; }
canvas.heat { border-radius: 4px; image-rendering: pixelated; }

/* 图例 */
.legend { display: flex; gap: 14px; align-items: center; justify-content: center; flex-wrap: wrap; font-size: 9.5px; color: var(--text-muted); }
.legend-swatch { display: inline-flex; align-items: center; gap: 5px; }
.legend-bar { width: 74px; height: 9px; border-radius: 3px; border: 1px solid var(--border-soft); }
.legend-bar.dual { background: linear-gradient(90deg, rgb(var(--neg-color)), rgba(255, 255, 255, 0.05) 50%, rgb(var(--pos-color))); }
.legend-bar.mask {
  background: repeating-linear-gradient(45deg, var(--mask-bg), var(--mask-bg) 3px, rgba(255, 107, 157, 0.12) 3px, rgba(255, 107, 157, 0.12) 6px);
}

/* ───────────────────────────────── 柱状图 */

.bar-chart {
  display: flex; align-items: stretch; gap: 4px; height: 200px; padding: 12px;
  background: var(--bg-elev-1); border: 1px solid var(--border-soft);
  border-radius: 8px; width: fit-content; max-width: 100%; margin: 0 auto; overflow-x: auto;
}
.bar { display: flex; flex-direction: column; align-items: center; flex: none; width: 30px; }
.bar-value { color: var(--accent-cyan); font-size: 8px; margin-bottom: 4px; white-space: nowrap; opacity: 0.75; }
.bar-grow { flex: 1; width: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.bar-inner {
  width: 100%; background: linear-gradient(180deg, var(--accent-cyan), #6366f1);
  border-radius: 2px 2px 0 0; transition: height 0.5s cubic-bezier(0.4, 0, 0.2, 1); opacity: 0.35;
}
.bar-inner.valid { opacity: 1; }
.bar-inner.max { background: linear-gradient(180deg, var(--accent-gold), var(--accent-pink)); box-shadow: 0 0 8px rgba(255, 201, 77, 0.4); opacity: 1; }
.bar-label-zone { height: 50px; width: 100%; position: relative; margin-top: 4px; }
.bar-label {
  position: absolute; top: 0; right: 50%; transform-origin: top right;
  transform: rotate(-45deg); white-space: nowrap;
  color: var(--text-secondary); font-size: 9.5px; font-weight: 500;
}
.bar-label .bid { color: var(--text-muted); font-size: 8.5px; }

/* ───────────────────────────────── 提示 / 状态 */

.note { color: var(--text-muted); font-size: 11px; margin-top: 8px; font-style: italic; text-align: center; line-height: 1.7; }
.note.left { text-align: left; }

.phase-badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: bold; vertical-align: middle; }
.phase-prefill { background: rgba(0, 212, 255, 0.15); color: var(--accent-cyan); border: 1px solid rgba(0, 212, 255, 0.3); }
.phase-decode { background: rgba(255, 107, 157, 0.15); color: var(--accent-pink); border: 1px solid rgba(255, 107, 157, 0.3); }

.kv-list { display: flex; flex-direction: column; gap: 3px; font-size: 10px; }
.kv-row { display: flex; justify-content: space-between; gap: 10px; color: var(--text-muted); }
.kv-row b { color: var(--accent-cyan); font-weight: 600; }
.kv-row.pink b { color: var(--accent-pink); }

.callout {
  border-left: 3px solid var(--accent-gold); background: rgba(255, 201, 77, 0.05);
  border-radius: 0 6px 6px 0; padding: 8px 12px; font-size: 11.5px;
  color: var(--text-secondary); line-height: 1.7;
}
.callout.cyan { border-left-color: var(--accent-cyan); background: rgba(0, 212, 255, 0.05); }
.callout.pink { border-left-color: var(--accent-pink); background: rgba(255, 107, 157, 0.05); }
.callout.violet { border-left-color: var(--accent-violet); background: rgba(167, 139, 250, 0.05); }
.callout b { color: var(--text-primary); }
.callout code { background: var(--bg-elev-2); padding: 1px 5px; border-radius: 3px; color: var(--accent-gold); font-size: 11px; }

.toast {
  position: fixed; bottom: 30px; left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-elev-2); color: var(--text-primary);
  padding: 12px 24px; border-radius: 8px; border: 1px solid var(--accent-pink);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5); z-index: 1000;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
  font-size: 13px; opacity: 0; pointer-events: none; max-width: 80vw;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

.boot {
  position: fixed; inset: 0; background: var(--bg-base);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; z-index: 2000; transition: opacity 0.4s ease;
}
.boot.hidden { opacity: 0; pointer-events: none; }
.boot h2 { color: var(--accent-cyan); font-size: 18px; font-weight: 600; }
.boot .status { color: var(--text-muted); font-size: 12px; }
.boot .err { color: var(--accent-pink); font-size: 12px; max-width: 640px; line-height: 1.8; text-align: center; }
.boot .err code { background: var(--bg-elev-2); padding: 2px 6px; border-radius: 3px; color: var(--accent-gold); }
.spinner {
  width: 26px; height: 26px; border: 2px solid var(--border-mid);
  border-top-color: var(--accent-cyan); border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.corpus-section { max-width: 1600px; margin: 0 auto; padding: 0 20px 48px; }
.corpus-head { color: var(--text-secondary); font-size: 12px; font-weight: 600; margin-bottom: 8px; }
.corpus-list { display: flex; flex-wrap: wrap; gap: 8px; }
.corpus-item {
  display: inline-flex; align-items: baseline; gap: 6px; padding: 7px 12px;
  background: var(--bg-elev-1); border: 1px solid var(--border-soft);
  border-radius: 18px; cursor: pointer; font-family: inherit; font-size: 12px;
  transition: all 0.25s; color: var(--text-primary);
}
.corpus-item:hover { border-color: var(--accent-cyan); transform: translateY(-1px); box-shadow: 0 3px 12px rgba(0, 212, 255, 0.12); }
.corpus-item .cs-prompt { color: var(--text-primary); font-weight: 600; }
.corpus-item .cs-arrow { color: var(--text-muted); }
.corpus-item .cs-cont { color: var(--accent-gold); opacity: 0.85; }
.corpus-note { margin-top: 10px; font-size: 11px; color: var(--text-muted); line-height: 1.8; }

@media (max-width: 768px) {
  h1 { font-size: 14px; }
  .config-group { width: 100%; }
  .step-title { font-size: 16px; }
  main { padding: 12px 10px 32px; }
}
