/* ==========================================================================
   图表：概率柱图 / loss 曲线 / 注意力扇形图 / 抽样轮盘 / token 条
   ========================================================================== */

/* ---------- 概率柱图 ---------- */
.pbars-wrap {
  display: grid;
  gap: 8px;
  min-width: 0;
}
.pbars {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 8px;
  align-items: end;
}
.pbar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 0;
}
.pbar-val {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-2);
  height: 15px;
  line-height: 15px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.pbar.is-top .pbar-val {
  color: var(--text);
  font-weight: 800;
}
.pbar-col {
  position: relative;
  width: 100%;
  height: var(--bh, 110px);
  display: flex;
  align-items: flex-end;
  background: var(--surface-2);
  border-radius: 8px;
}
.pbar-fill {
  width: 100%;
  border-radius: 8px 8px 3px 3px;
  background: linear-gradient(180deg, hsl(var(--h) 85% 64%), hsl(var(--h) 72% 52%));
  transition: height 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}
[data-theme='dark'] .pbar-fill {
  background: linear-gradient(180deg, hsl(var(--h) 70% 62%), hsl(var(--h) 60% 46%));
}
.pbar.is-dim {
  opacity: 0.32;
}
.pbar.is-target .pbar-col {
  box-shadow: 0 0 0 2px var(--good);
}
.pbar-flag {
  position: absolute;
  top: 3px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10.5px;
  font-weight: 800;
  color: #fff;
  background: var(--good);
  padding: 0 6px;
  border-radius: 99px;
  line-height: 16px;
  z-index: 2;
  white-space: nowrap;
}
[data-theme='dark'] .pbar-flag {
  color: #06210f;
}
.pbar-ideal {
  position: absolute;
  left: -3px;
  right: -3px;
  height: 0;
  border-top: 2px dashed var(--text);
  opacity: 0.8;
  z-index: 1;
  transition: bottom 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.pbar.clickable {
  cursor: pointer;
}
.pbar.is-picked .pbar-col {
  box-shadow: 0 0 0 2px var(--brand);
}
.pbars-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
}
.lg-ideal {
  display: inline-block;
  width: 18px;
  border-top: 2px dashed var(--text);
  vertical-align: middle;
  margin-right: 6px;
  opacity: 0.8;
}
.pbars-wrap.compact .pbars {
  gap: 5px;
}
.pbars-wrap.compact .pbar-val {
  font-size: 10px;
}
.pbars-wrap.compact .pbar-flag {
  display: none;
}
/* 图太窄、一根柱子放不下词牌时（ProbBars 按实际宽度加上 fit-sm / fit-xs）：词牌缩小，避免 <bos> / <eos> 互相压住 */
.pbars-wrap.fit-sm .pbar-lab .tok.special,
.pbars-wrap.fit-xs .pbar-lab .tok.special {
  padding: 0 3px;
  font-size: 9px;
  letter-spacing: -0.3px;
}
.pbars-wrap.fit-xs .pbars {
  gap: 3px;
}
.pbars-wrap.fit-xs .pbar-lab {
  max-width: 100%;
  display: flex;
  justify-content: center;
}
.pbars-wrap.fit-xs .pbar-lab .tok {
  gap: 2px;
  padding: 0 3px;
  font-size: 9.5px;
}
.pbars-wrap.fit-xs .pbar-lab .tok.special {
  font-size: 8.5px;
}
.pbars-wrap.fit-xs .pbar-lab .tok .tok-id {
  display: none;
}
/* 手机上 8 根柱子挤在一行：词牌缩小，避免 <bos> / <eos> 互相压住（JS 量宽度之前的首帧兜底） */
@media (max-width: 640px) {
  .pbars,
  .pbars-wrap.compact .pbars {
    gap: 3px;
  }
  .pbar-lab {
    max-width: 100%;
    display: flex;
    justify-content: center;
  }
  .pbar-lab .tok {
    gap: 2px;
    padding: 0 3px;
    font-size: 9.5px;
  }
  .pbar-lab .tok.special {
    font-size: 8.5px;
    letter-spacing: -0.3px;
  }
  .pbar-lab .tok .tok-id {
    display: none;
  }
}
/* 极窄（约 320px 宽的手机，ProbBars 量出每根柱子不到 34px）：再缩一档。必须放在上面的 @media 之后，才压得住它的 gap */
.pbars-wrap.fit-xxs .pbars,
.pbars-wrap.compact.fit-xxs .pbars {
  gap: 2px;
}
.pbars-wrap.fit-xxs .pbar-lab .tok {
  padding: 0 2px;
  font-size: 8.5px;
}
.pbars-wrap.fit-xxs .pbar-lab .tok.special {
  padding: 0 2px;
  font-size: 7.5px;
  letter-spacing: -0.4px;
}

/* ---------- SVG 图表文字 ---------- */
.chart-svg {
  width: 100%;
  height: auto;
  display: block;
}
.chart-svg .axis-title {
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 600;
  fill: var(--text-2);
}
.chart-svg .ref-label {
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 600;
  fill: var(--muted);
}
.chart-svg .ref-label.good {
  fill: var(--good);
}
.chart-svg .cur-label {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 800;
  fill: var(--brand-ink);
}
.chart-svg .cur-label.bad {
  fill: var(--bad);
  font-family: var(--font-sans);
}
.chart-svg .tip-t {
  font-family: var(--font-sans);
  font-size: 11px;
  fill: var(--muted);
}
.chart-svg .tip-v {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  fill: var(--text);
}
.chart-svg .pt-label {
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 700;
  fill: var(--text);
}

/* ---------- 注意力扇形图 ---------- */
.fan {
  --fc: var(--brand);
  padding: 2px 0 4px;
  min-width: 0;
}
.fan-top {
  display: grid;
  align-items: end;
  min-height: 50px;
}
.fan-q {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  justify-self: center;
}
.fan-q-lab {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}
.fan-svg {
  display: block;
  width: 100%;
  height: 58px;
  overflow: visible;
}
.fan-keys {
  display: grid;
  align-items: start;
}
.fan-k {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 0;
}
.fan-w {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 800;
  color: var(--text);
}
.fan-k.is-hidden .fan-w {
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
}

/* ---------- 抽样轮盘 ---------- */
.cdf {
  padding: 30px 12px 0;
}
.cdf-bar {
  position: relative;
  display: flex;
  height: 44px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.cdf-seg {
  display: grid;
  place-items: center;
  background: hsl(var(--h) 80% 90%);
  color: hsl(var(--h) 55% 26%);
  font-weight: 700;
  font-size: 13px;
  border-right: 2px solid var(--surface);
  overflow: hidden;
  white-space: nowrap;
  transition: width 0.4s ease, background 0.2s;
}
[data-theme='dark'] .cdf-seg {
  background: hsl(var(--h) 38% 24%);
  color: hsl(var(--h) 85% 86%);
}
.cdf-seg:first-child {
  border-radius: 9px 0 0 9px;
}
.cdf-seg:last-child {
  border-right: 0;
  border-radius: 0 9px 9px 0;
}
.cdf-seg.is-picked {
  background: hsl(var(--h) 85% 72%);
  box-shadow: inset 0 0 0 2px hsl(var(--h) 60% 40%);
}
[data-theme='dark'] .cdf-seg.is-picked {
  background: hsl(var(--h) 55% 38%);
}
.cdf-marker {
  position: absolute;
  top: -8px;
  bottom: -8px;
  width: 3px;
  margin-left: -1.5px;
  background: var(--grad);
  border-radius: 2px;
  z-index: 3;
  transition: left 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.cdf-u {
  position: absolute;
  top: -24px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 800;
  color: var(--grad);
  white-space: nowrap;
  background: var(--surface);
  padding: 0 6px;
  border-radius: 6px;
}
.cdf-ticks {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  margin-top: 5px;
}

/* ---------- token 条 ---------- */
.token-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 6px;
  align-items: flex-start;
}
.ts-item {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 8px;
  border-radius: 10px;
  transition: background 0.15s;
}
.ts-item.clickable {
  cursor: pointer;
}
.ts-item.clickable:hover {
  background: var(--surface-2);
}
.ts-item.is-active {
  background: var(--brand-soft);
}
.ts-pos {
  font-size: 10.5px;
  color: var(--muted);
  font-family: var(--font-mono);
}
