/*
 * 四个学习实验页共用的外壳。
 *
 * 只放所有实验页都用得到的东西：token、基础排版、卡片、按钮、观测读数、oracle 列表、
 * 证据边界、表格和页脚。每页自己的图表样式留在自己的样式表里。
 *
 * 数据色的验证记录见 code-mode-evidence-lab.css 的文件头：分类色 --brand / --signal
 * 在两种模式下五项检查全过，且与站点 --vp-c-brand-1 同色相族；状态色的绿红对在色盲
 * 下无法靠色相区分，所以状态一律带字形和文字标签。
 */



* { box-sizing: border-box; }
html { min-width: 320px; }

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 4% 0%, color-mix(in srgb, var(--brand-soft) 75%, transparent), transparent 32rem),
    radial-gradient(circle at 98% 18%, color-mix(in srgb, var(--signal-soft) 58%, transparent), transparent 29rem),
    var(--page);
  font-family: var(--sans);
  line-height: 1.6;
}

button, input, select { font: inherit; }
/* 移动端点按不再等待双击缩放判定；所有实验页的按钮统一受益。 */
button { touch-action: manipulation; }
a { color: var(--brand); }

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--signal) 80%, white);
  outline-offset: 3px;
}

.skip-link {
  position: absolute;
  z-index: 10;
  top: 8px;
  left: 12px;
  padding: 8px 13px;
  border-radius: 8px;
  color: var(--surface-strong);
  background: var(--brand);
  transform: translateY(-160%);
}

.skip-link:focus { transform: translateY(0); }

.lab-shell {
  width: min(1540px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.card, .hero-panel {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.card {
  margin-top: 20px;
  padding: clamp(22px, 3vw, 38px);
  border-radius: var(--radius-lg);
  position: relative;
}

/*
 * 卡片聚光：指针位置由 study-lab-kit.js 的事件委托写入 --mx/--my，
 * 一团品牌色暖光以大半径径向渐变跟随——Linear 式微交互的纸面译版，
 * 刻意压到 22% 透明度，只做「纸面被台灯照亮」的暗示，不抢数据可读性。
 */
.card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--dur-slow) var(--ease);
  background: radial-gradient(
    340px circle at var(--mx, 50%) var(--my, 50%),
    color-mix(in srgb, var(--brand-soft) 22%, transparent),
    transparent 70%
  );
}
.card:hover::after { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .card::after { transition: none; }
}

/*
 * 磁吸按钮的回位弹簧：translate 由 study-lab-kit.js 的委托写入，
 * 这里只负责让跟随与回弹带物理感。背景/边框的过渡在 tokens 里，互不覆盖。
 */
@media (prefers-reduced-motion: no-preference) {
  .button {
    transition: translate 260ms var(--ease-spring),
      background var(--dur-fast) var(--ease),
      border-color var(--dur-fast) var(--ease);
  }
}

/*
 * 预测门控的解锁瞬间：锁定时控件区压暗下沉，答对的一刻以弹簧缓动
 * 浮起复明——「先思考，再动手」的身体记忆。inert 管住指针/键盘/辅助
 * 技术，这里只管看得见的部分；禁用态不参与对比度门控。
 */
#gated-controls {
  transition: opacity var(--dur-enter) var(--ease), translate var(--dur-enter) var(--ease-spring);
}
#gated-controls[data-gated='locked'] {
  opacity: 0.45;
  translate: 0 6px;
}

/*
 * 区块卡片的滚动入场：纯 CSS 滚动时间线（2026 Baseline），合成器线程执行。
 * 双层降级——不支持的浏览器和减少动态偏好下，卡片保持自然静态，功能不变。
 * 只动 opacity / transform；animation-duration 的 1ms 是 Firefox 的语法要求。
 */
@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    main.lab-shell > section {
      animation: lab-card-enter 1ms linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 55%;
    }
    @keyframes lab-card-enter {
      from { opacity: 0; transform: translateY(24px) scale(0.988); }
      to { opacity: 1; transform: none; }
    }
  }
}

.hero-panel {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 300px);
  gap: 26px;
  padding: clamp(28px, 5vw, 60px);
  border-radius: var(--radius-xl);
}

.eyebrow, .section-label, .warning-index, .schema-pill, .metric-grid dt, .page-footer span {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.eyebrow { margin: 0; color: var(--muted); }

h1 {
  max-width: 900px;
  margin: 22px 0 0;
  font-size: clamp(2.1rem, 5vw, 4.2rem);
  font-weight: 800;
  letter-spacing: -0.055em;
  line-height: 1;
}

h2 { margin: 0; font-size: clamp(1.2rem, 1.9vw, 1.65rem); letter-spacing: -0.03em; }
h3 { margin: 0 0 8px; font-size: 0.94rem; }

.hero-lead { max-width: 760px; margin: 22px 0 0; color: var(--muted); font-size: clamp(0.98rem, 1.5vw, 1.12rem); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 26px; }

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  padding: 10px 17px;
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 750;
  text-decoration: none;
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}

.button:hover { transform: translateY(-2px); }
.button-primary { color: #fff; background: var(--brand); }
.button-primary:hover { background: var(--brand-bright); }
.button-secondary { border-color: var(--line-strong); color: var(--ink); background: color-mix(in srgb, var(--surface-strong) 65%, transparent); }

.model-warning {
  align-self: start;
  padding: 17px;
  border: 1px solid color-mix(in srgb, var(--signal) 35%, var(--line));
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--signal-soft) 78%, var(--surface));
}

.warning-index { color: var(--signal-ink); }
.model-warning strong { display: block; margin: 8px 0; }
.model-warning p { margin: 0; color: var(--muted); font-size: 0.88rem; }

.lab-form { display: flex; flex-wrap: wrap; align-items: end; gap: 16px; }
.lab-form label { display: flex; min-width: 200px; flex: 1 1 200px; flex-direction: column; gap: 6px; }
.lab-form label > span { font-weight: 700; font-size: 0.9rem; }
.lab-form small { color: var(--muted); font-size: 0.78rem; }

select, input[type="number"] {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  color: var(--ink);
  background: var(--surface-strong);
}

.feedback { margin: 16px 0 0; color: var(--muted); font-size: 0.88rem; }
.feedback[data-tone="success"] { color: var(--allow-ink); }
.feedback[data-tone="error"] { color: var(--deny-ink); }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 12px;
  margin: 18px 0 0;
}

.metric-grid > div {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--surface-strong) 62%, transparent);
}

.metric-grid dt { margin: 0 0 6px; color: var(--muted); }
.metric-grid dd { margin: 0; font-family: var(--mono); font-size: 1.24rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.metric-oracle dd[data-pass="true"] { color: var(--allow-ink); }
.metric-oracle dd[data-pass="false"] { color: var(--deny-ink); }

.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.section-label { margin: 0 0 8px; color: var(--brand); }

.schema-pill {
  padding: 5px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--muted);
  white-space: nowrap;
}

.section-intro { margin: 14px 0 0; color: var(--muted); font-size: 0.94rem; }

.chart-note {
  margin: 16px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.86rem;
}

.plot-scroll, .table-scroll {
  overflow-x: auto;
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--surface-strong) 62%, transparent);
}

.plot-scroll { padding: 14px; }
/*
 * 图表在容器变窄时会等比缩小，SVG 里的字号也跟着缩。按 .lab-shell 到 .plot-scroll
 * 的盒模型推算：1270 单位宽的图在 1440px 视口下拿到 1296px（缩放 1.02），到 1024px
 * 视口只剩 895px（缩放 0.70），11px 的文字实际只有 7.7px。
 *
 * 所以给 SVG 设一个接近设计宽度的 min-width：低于它就横向滚动，而不是继续缩小到
 * 读不出来。完整表格始终是这张图的文字替代，滚动不是唯一出路。
 */
/*
 * 图宽由脚本按容器算出并写进 viewBox，所以缩放恒为 1，SVG 里的字号就是屏幕上的
 * 字号。这里不再设 min-width：设了只会在窄屏强制出现一条本不需要的横向滚动条。
 * 宽度下限由脚本负责（760，保证坐标轴标签不互相压住），到不了才滚动。
 */
.plot-scroll svg { display: block; width: 100%; }

.grid { stroke: var(--line); stroke-width: 1; }
.baseline { stroke: var(--line-strong); stroke-width: 1; }

.axis, .axis-title, .mark-label, .mark-value {
  fill: var(--muted);
  font-family: var(--mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.axis-title { font-size: 14px; font-weight: 750; }
.mark-value { fill: var(--ink); font-weight: 750; }

.evidence-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.evidence-grid > * { min-width: 0; margin-top: 20px; }

.oracle-list { margin: 18px 0 0; padding: 0; list-style: none; }

.oracle-list li {
  display: grid;
  gap: 4px;
  padding: 11px 0;
  border-top: 1px solid var(--line);
}

.oracle-list li:first-child { border-top: 0; }
.oracle-list strong { font-size: 0.9rem; }
.oracle-list li[data-pass="true"] strong { color: var(--allow-ink); }
.oracle-list li[data-pass="false"] strong { color: var(--deny-ink); }
.oracle-list span { color: var(--muted); font-family: var(--mono); font-size: 0.78rem; }

.boundary-columns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; margin-top: 18px; }
.boundary-columns ul { margin: 0; padding-left: 20px; color: var(--muted); font-size: 0.88rem; }
.boundary-columns li { margin-bottom: 8px; }
.boundary-yes h3 { color: var(--allow-ink); }
.boundary-no h3 { color: var(--deny-ink); }

table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
caption { padding: 14px; color: var(--muted); font-size: 0.82rem; text-align: left; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; }

thead th {
  position: sticky;
  top: 0;
  color: var(--muted);
  background: var(--surface-strong);
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

td { font-family: var(--mono); font-variant-numeric: tabular-nums; }
tbody tr:hover { background: color-mix(in srgb, var(--brand) 7%, transparent); }

.page-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

@media (max-width: 1080px) {
  .hero-panel, .evidence-grid, .boundary-columns { grid-template-columns: minmax(0, 1fr); }
}

/* 读数拖柄：横向像素换算成滑杆步数；键盘路径仍走原生滑杆，这里只管指针手感。
   touch-action 保留纵向滚动，只接管横向拖动；文本不可选中，避免拖动时拉蓝。
   指针拖动本身不是动画，reduced-motion 下照常可用。 */
.lab-scrub-number {
  cursor: ew-resize;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
}

/* 反向联动表：行可点击跳时间轴。悬停高亮由既有的 tbody tr:hover 规则承担。 */
.lab-rows-jump tr[data-key] {
  cursor: pointer;
}

/* 这里的过渡只标记指针位置，不编码任何数值，去掉不损失信息。 */
@media (prefers-reduced-motion: reduce) {
  .button { transition: none; }
}

@media (forced-colors: active) {
  .card, .hero-panel, .plot-scroll, .table-scroll { border: 1px solid CanvasText; }
  .button, select, input { border: 1px solid ButtonText; }
}

/*
 * 内联图标。语义由旁边的文字标签承担，图标只加快扫读；去掉全部图标后信息量不变。
 * 用 currentColor 描边，所以颜色跟随所在容器，不引入第二套配色。
 */
.icon {
  flex: none;
  vertical-align: -0.16em;
  margin-right: 0.42em;
}

.has-icon {
  display: inline-flex;
  align-items: baseline;
}

/* 图标不参与减少动态效果的判断，它本身不动。 */
@media (forced-colors: active) {
  .icon { stroke: CanvasText; }
  [data-pass="true"] .icon, [data-pass="true"].icon { stroke: CanvasText; }
}

/* 播放按钮的按下态与正文术语联动的高亮（共享层）。 */
button[aria-pressed="true"] {
  border-color: var(--brand, #3aa2ff);
  color: var(--brand, #3aa2ff);
  font-weight: 600;
}

.term-flash {
  outline: 2px solid var(--brand, #3aa2ff);
  outline-offset: 2px;
  border-radius: 6px;
}
/* 正文术语联动：说明文字里的可聚焦术语，悬停/聚焦高亮对应视图元素。 */
.term-ref {
  font: inherit;
  padding: 0;
  border: none;
  background: none;
  color: var(--brand, #3aa2ff);
  text-decoration: underline dotted;
  cursor: pointer;
}
/* 排版与微交互打磨。 */
.lab-shell h1 { text-wrap: balance; letter-spacing: -0.01em; }
.lab-shell .button { transition: transform var(--dur-fast, 120ms) var(--ease-out-soft, ease), box-shadow var(--dur-fast, 120ms) ease, border-color var(--dur-fast, 120ms) ease; }
.lab-shell .button:hover { transform: translateY(-1px); box-shadow: 0 2px 10px rgb(0 0 0 / 0.08); }
.lab-shell .button:active { transform: translateY(0); box-shadow: none; }
@media (prefers-reduced-motion: reduce) {
  .lab-shell .button, .lab-shell .button:hover, .lab-shell .button:active { transform: none; transition: none; }
}

/* 页顶滚动进度条：位置映射滚动，不是时间动画；不支持的浏览器保持零宽。 */
#dsh-scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 90;
  width: 100%;
  height: 3px;
  transform: scaleX(0);
  transform-origin: 0 50%;
  background: linear-gradient(90deg, var(--brand), var(--brand-bright, var(--brand)));
  pointer-events: none;
}
@supports (animation-timeline: scroll()) {
  #dsh-scroll-progress {
    animation: dsh-scroll-progress-grow linear both;
    animation-timeline: scroll(root block);
  }
  @keyframes dsh-scroll-progress-grow {
    from { transform: scaleX(0); }
    to { transform: scaleX(1); }
  }
}

/*
 * 弹簧缓动升级：study-lab-motion.css 已在 .lab-shell 上定义了
 * cubic-bezier 近似的 --ease-spring；linear() 能表达真正的欠阻尼振荡
 * （过冲 1.16 后衰减），本文件加载在后，支持的浏览器自动取用这条升级，
 * 不支持的继续用 motion.css 的 bezier 近似。采样点来自
 * linear-easing-generator 的弹簧预设（刚度 235 / 阻尼 10）。
 */
@supports (animation-timing-function: linear(0, 1)) {
  .lab-shell {
    --ease-spring: linear(
      0, 0.009, 0.035 2.1%, 0.141, 0.281 6.7%, 0.723 12.9%, 0.938 16.7%,
      1.017, 1.077, 1.121, 1.149 24.3%, 1.159, 1.163, 1.161,
      1.154 29.9%, 1.129 32.8%, 1.051 39.6%, 1.017 43.1%, 0.991,
      0.977 51%, 0.974 53.8%, 0.975 57.1%, 0.997 69.8%, 1.003 76.9%, 1
    );
  }
}

/*
 * 主题切换的圆形扩散：View Transitions 快照 + clip-path 揭示。
 * 旧快照保持不动，新快照从点击点（--vt-x/--vt-y，JS 写入；键盘激活时
 * 回落屏幕中心）以 150% 半径扫开——角落按钮到对角需要约 142%，取整留裕量。
 * 双层降级：不支持 VT 的浏览器与减少动态偏好下，JS 侧直接切换主题。
 * mix-blend-mode: normal 是浏览器默认混合模式在实色底上会产生伪影的已知修正。
 */
@media (prefers-reduced-motion: no-preference) {
  @supports (view-transition-name: root) {
    ::view-transition-old(root) {
      animation: none;
      mix-blend-mode: normal;
    }
    ::view-transition-new(root) {
      animation: dsh-vt-reveal var(--dur-enter) var(--ease) forwards;
      mix-blend-mode: normal;
      z-index: 1;
    }
    @keyframes dsh-vt-reveal {
      from { clip-path: circle(0% at var(--vt-x, 50%) var(--vt-y, 50%)); }
      to { clip-path: circle(150% at var(--vt-x, 50%) var(--vt-y, 50%)); }
    }
  }
}

/*
 * 时间轴步进控件：滑杆、上一步/下一步和当前步骤说明。
 * 状态切换不做动画：is-current / is-future 只换外观，reduced-motion 与否都一样。
 */
.stepper {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: var(--space-sm);
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid var(--line);
}

.stepper-seek { display: flex; min-width: 220px; flex: 1 1 260px; flex-direction: column; gap: var(--space-2xs); }
.stepper-seek > span { font-weight: 700; font-size: 0.9rem; }
.stepper-seek output { color: var(--brand); font-family: var(--mono); font-variant-numeric: tabular-nums; }
.stepper-seek input[type="range"] { width: 100%; min-height: 44px; margin: 0; }
.stepper-seek small { color: var(--muted); font-size: 0.78rem; }

.stepper-buttons { display: flex; gap: var(--space-2xs); }
.stepper-buttons .button[disabled] { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }

.step-caption { flex: 1 1 100%; margin: 0; color: var(--ink); font-size: 0.9rem; }

.plot-scroll [data-step].is-future { opacity: 0.28; }
.plot-scroll [data-step].is-current { stroke: var(--ink); stroke-width: 3; r: 11px; }

tbody tr[data-key].is-future { opacity: 0.5; }
tbody tr[data-key].is-current { background: color-mix(in srgb, var(--brand) 10%, transparent); }

/* 签名瞬间：步进落到关键步骤时的一次性动画；reduced-motion 全关。 */
@keyframes sig-spark { 0% { r: 9px; opacity: 1; } 60% { r: 24px; opacity: .35; } 100% { r: 30px; opacity: 0; } }
@keyframes sig-shake { 0%, 100% { transform: translate(0, 0); } 25% { transform: translate(-3px, 0); } 55% { transform: translate(3px, -1px); } 80% { transform: translate(-2px, 1px); } }
@keyframes sig-wall-x { 0%, 100% { transform: translateX(0); } 35% { transform: translateX(-5px); } 70% { transform: translateX(4px); } }
@keyframes sig-pop { 0% { transform: scale(.55); } 60% { transform: scale(1.2); } 100% { transform: scale(1); } }
@keyframes sig-ping { 0%, 100% { r: 11px; } 45% { r: 17px; } }
@keyframes sig-bounce-y { 0% { transform: translateY(0); } 30% { transform: translateY(-8px); } 55% { transform: translateY(4px); } 78% { transform: translateY(-2px); } 100% { transform: translateY(0); } }
.plot-scroll [data-step].is-spark { animation: sig-spark .7s ease-out both; fill: var(--signal); }
.plot-scroll [data-step].is-dead { opacity: .28; }
.plot-scroll [data-step].is-crash { animation: sig-shake .5s ease-in-out both; fill: var(--deny); }
.plot-scroll [data-step].is-split { animation: sig-ping .6s ease-out 2 both; stroke: var(--brand-bright, var(--brand)); stroke-width: 3; }
.plot-scroll [data-step].is-wall { animation: sig-wall-x .5s ease both; stroke: var(--deny); stroke-width: 3; }
.plot-scroll [data-step].is-pop { animation: sig-pop .55s cubic-bezier(.34, 1.56, .64, 1) both; transform-box: fill-box; transform-origin: center; }
.plot-scroll [data-step].is-ping { animation: sig-ping .5s ease-out both; fill: var(--brand); }
.plot-scroll [data-step].is-thud { animation: sig-ping .38s ease-out 2 both; fill: var(--signal); }
svg rect.is-rejected.is-bounce { animation: sig-bounce-y .65s ease both; stroke: var(--deny); stroke-width: 2; }
@media (prefers-reduced-motion: reduce) {
  .plot-scroll [data-step].is-spark,
  .plot-scroll [data-step].is-crash,
  .plot-scroll [data-step].is-split,
  .plot-scroll [data-step].is-wall,
  .plot-scroll [data-step].is-pop,
  .plot-scroll [data-step].is-ping,
  .plot-scroll [data-step].is-thud,
  svg rect.is-rejected.is-bounce { animation: none; }
}

/* 播放速度档位：跟随 stepper-buttons 的高度与静音按钮气质。 */
.jb-speed {
  min-height: 30px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.8rem;
}

/* 叙事节拍带：Distill 式滚动位置感。粘性、可点击、当前拍高亮。 */
.story-rail {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: var(--space-2xs);
  overflow-x: auto;
  padding: var(--space-2xs) 0;
  margin: 0 0 var(--space-sm);
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(10px);
}
.story-beat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
}
.story-beat-num {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--brand);
}
.story-beat.is-active {
  border-color: var(--brand);
  color: var(--ink);
  background: color-mix(in srgb, var(--brand) 8%, transparent);
}
@media (prefers-reduced-motion: reduce) {
  .story-rail { scroll-behavior: auto; }
}

/* Spring 过渡：状态 pill 和徽标的颜色/背景变化不再硬切。 */
.schema-pill,
.tj-view-chip,
.wn-status,
.story-beat,
.jb-transition {
  transition: background-color 240ms cubic-bezier(0.34,1.56,0.64,1),
              border-color 240ms cubic-bezier(0.34,1.56,0.64,1),
              color 240ms cubic-bezier(0.34,1.56,0.64,1);
}

/* Metric dd 的补间期间微微放大再回弹（TF Playground 式实时感）。 */
.metric-grid dd {
  transition: transform 200ms cubic-bezier(0.34,1.56,0.64,1);
}
.metric-grid dd[data-tweening='true'] {
  transform: scale(1.06);
}
@media (prefers-reduced-motion: reduce) {
  .schema-pill, .tj-view-chip, .wn-status, .story-beat, .jb-transition { transition: none; }
  .metric-grid dd[data-tweening='true'] { transform: none; }
}

/* 移动端防溢出：metric-grid 在窄屏下从固定列改为单列堆叠。 */
@media (max-width: 640px) {
  .metric-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  .table-scroll, .plot-scroll, .nest-scroll, .stage-scroll {
    max-width: calc(100vw - 32px);
  }
  /* 防溢出：所有卡片和主区域不允许子元素撑宽 */
  .card, .trace-card, .control-strip {
    overflow-x: hidden;
    max-width: 100%;
  }
  .lab-form label {
    min-width: 0;
    flex: 1 1 100%;
  }
  svg[role="img"] {
    max-width: 100%;
    height: auto;
  }
  pre, code {
    max-width: 100%;
    overflow-x: auto;
    word-break: break-all;
  }
}

/* 跨实验导航：概念相邻链接。 */
.related-labs { margin: var(--space-sm) 0; }
.related-list { display: flex; flex-wrap: wrap; gap: var(--space-2xs); margin-top: var(--space-2xs); }

/*
 * 长页渲染优化（INP presentation delay）：离屏区块跳过渲染，
 * 接近视口时浏览器才绘制。contain-intrinsic-size 给出估算高度，
 * 滚动条不跳动；打印时全部展开，不影响输出。
 */
@supports (content-visibility: auto) {
  .lab-shell > section:not(:nth-of-type(-n + 2)) {
    content-visibility: auto;
    contain-intrinsic-size: auto 520px;
  }
}

@media print {
  .lab-shell > section {
    content-visibility: visible !important;
  }
}

/* === 全局微交互层：hover 弹起 + 按下缩放 + 状态变化脉冲 === */

.card {
  transition: transform 200ms cubic-bezier(0.22,1,0.36,1),
              box-shadow 200ms cubic-bezier(0.22,1,0.36,1);
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.08), var(--dsh-card-shadow, 0 12px 34px rgba(38,34,26,0.06));
}
.card:active {
  transform: translateY(0) scale(0.995);
}

.button {
  transition: transform 150ms cubic-bezier(0.34,1.56,0.64,1),
              box-shadow 150ms ease;
}
.button:hover {
  transform: translateY(-1px);
}
.button:active {
  transform: scale(0.97) translateY(0);
}

.story-beat:hover,
.wt-source:hover,
.jb-step:hover {
  border-color: var(--brand);
}

@keyframes dsh-pulse-once {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--brand) 40%, transparent); }
  70% { box-shadow: 0 0 0 8px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/*
 * 表格行微交互（GitHub / Linear 式）：
 * 悬停时左侧出现品牌色竖条 + 底色微变；离开时弹簧回位。
 * 纯 CSS 合成器安全——只动 border-color 和 background。
 */
.table-scroll table tbody tr {
  transition: background-color 120ms ease, box-shadow 120ms ease;
  border-left: 3px solid transparent;
}
.table-scroll table tbody tr:hover {
  background: color-mix(in srgb, var(--brand) 5%, transparent);
  border-left-color: var(--brand);
}

/*
 * 平滑滚动：锚点跳转不再瞬移，而是缓动到目标位置。
 * 减少动态偏好下自动禁用（浏览器原生行为）。
 */
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

/*
 * 返回顶部浮动按钮：滚动超过两屏后淡入，点击平滑回顶。
 * 纯 CSS scroll-driven——合成器线程执行，零 JS 零监听。
 * 不支持的浏览器不显示按钮（功能不受影响）。
 */
.back-to-top {
  position: fixed;
  inset-block-end: 24px;
  inset-inline-end: 24px;
  z-index: 50;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--card-bg, #fff);
  color: var(--ink);
  border: 1px solid var(--border, rgba(0,0,0,0.1));
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  text-decoration: none;
  font-size: 18px;
  line-height: 1;
  transition: opacity 200ms ease, transform 200ms ease;
}
.back-to-top.is-visible {
  opacity: 1;
  pointer-events: auto;
}
.back-to-top:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(0,0,0,0.16);
}
.back-to-top:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/*
 * 焦点可见性增强（键盘导航人性化）：所有可交互元素获得焦点时
 * 显示品牌色轮廓环 + 微偏移，与鼠标悬停视觉区分。
 */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}
.pulse-once { animation: dsh-pulse-once 500ms ease-out 1; }

@media (prefers-reduced-motion: reduce) {
  .card, .button, .story-beat, .wt-source, .jb-step { transition: none !important; }
  .card:hover { transform: none; }
  .pulse-once { animation: none; }
}

/*
 * ===== 以下为全站视觉增强层（纯 CSS，合成器安全）=====
 */

/*
 * 1. Oracle 徽标脉冲：判定从 fail → pass 时绿色扩散环，
 *    从 pass → fail 时红色抖动。data-pass 属性由 renderOracle 写入。
 */
.metric-oracle dd[data-pass="true"] {
  animation: oracle-pass-pulse 600ms ease-out 1;
}
.metric-oracle dd[data-pass="false"] {
  animation: oracle-fail-shake 400ms ease-out 1;
}
@keyframes oracle-pass-pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--allow-ink, #2e7d32) 50%, transparent); }
  70% { box-shadow: 0 0 0 10px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
@keyframes oracle-fail-shake {
  0%, 100% { translate: 0 0; }
  20% { translate: -3px 0; }
  40% { translate: 3px 0; }
  60% { translate: -2px 0; }
  80% { translate: 2px 0; }
}

/*
 * 2. 卡片悬停渐变描边（@property + conic-gradient，Chrome 111+/Firefox 128+）：
 *    悬停时品牌色光弧绕卡片边框旋转一圈。不支持的浏览器静默降级。
 */
@property --dsh-card-angle {
  syntax: '<angle>';
  initial-value: 0deg;
  inherits: false;
}
@media (prefers-reduced-motion: no-preference) {
  .card {
    position: relative;
  }
  .card::after {
    content: '';
    position: absolute;
    inset: -1.5px;
    border-radius: inherit;
    padding: 1.5px;
    background: conic-gradient(
      from var(--dsh-card-angle),
      transparent 0deg,
      transparent 280deg,
      var(--brand) 330deg,
      transparent 360deg
    );
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    opacity: 0;
    pointer-events: none;
    transition: opacity 300ms ease;
  }
  .card:hover::after {
    opacity: 1;
    animation: dsh-card-spin 2.5s linear infinite;
  }
}
@keyframes dsh-card-spin {
  to { --dsh-card-angle: 360deg; }
}

/*
 * 3. 表格行交错进场（view() timeline）：每行在进入视口时淡入上移，
 *    行序号通过 nth-child 计算延迟，形成瀑布效果。
 *    仅在浏览器支持 view() timeline 且未减少动态时启用。
 */
@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    .table-scroll table tbody tr {
      animation: row-stagger-enter 1ms linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 60%;
    }
    @keyframes row-stagger-enter {
      from { opacity: 0; transform: translateX(-12px); }
      to { opacity: 1; transform: none; }
    }
  }
}

/*
 * 4. 区块标题下划线绘制：h2 下方的伪元素线条从左到右展开，
 *    由 view() timeline 驱动——滚到哪画到哪。
 */
@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    .section-heading h2 {
      position: relative;
      padding-bottom: 6px;
    }
    .section-heading h2::after {
      content: '';
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
      height: 2px;
      background: linear-gradient(90deg, var(--brand), transparent);
      transform-origin: left;
      animation: heading-underline-draw 1ms linear both;
      animation-timeline: view();
      animation-range: entry 10% entry 45%;
    }
    @keyframes heading-underline-draw {
      from { transform: scaleX(0); opacity: 0; }
      to { transform: scaleX(1); opacity: 0.35; }
    }
  }
}

/*
 * 5. 指标值变更闪烁背景：MutationObserver 检测到文本变化时，
 *    给 dd 元素加 .metric-flash 类触发一次性背景闪光。
 */
.metric-flash {
  animation: metric-flash-bg 500ms ease-out 1;
}
@keyframes metric-flash-bg {
  0% { background: color-mix(in srgb, var(--brand) 15%, transparent); border-radius: 4px; }
  100% { background: transparent; }
}

/*
 * 状态徽章与终局色调：此前只有 trajectory-lab.css / jobs-lab.css 各自定义了
 * .tj-view-chip，其余实验室页挂这些类时没有任何样式（死类名）。这里给出
 * shell 级默认值；页面级 CSS 同名规则按加载顺序自然覆盖。
 */
.tj-view-chip {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--signal-ink, var(--signal));
  border: 1px solid color-mix(in srgb, var(--signal, var(--vp-c-brand-1)) 45%, transparent);
  border-radius: 999px;
  padding: 1px 8px;
  white-space: nowrap;
}

.tj-view-chip.is-suppressed {
  color: var(--muted);
  border-color: var(--line);
}

.metric-grid dd.is-running { color: var(--brand); }
.metric-grid dd.is-stopping { color: var(--warning-ink); }
.metric-grid dd.is-completed { color: var(--allow-ink); }
.metric-grid dd.is-killed { color: var(--warning-ink); }
.metric-grid dd.is-failed { color: var(--deny-ink); }
.metric-grid dd.is-none { color: var(--muted); }

/* 时间线步骤可点击寻址（图形即控制器）：指针形态提示可点。 */
.cr-timeline .cr-step,
.hg-timeline .hg-step,
.iv-timeline .iv-step,
.sh-timeline .sh-step {
  cursor: pointer;
}

/* 减少动态偏好下全部禁用 */
@media (prefers-reduced-motion: reduce) {
  .metric-oracle dd[data-pass="true"],
  .metric-oracle dd[data-pass="false"] { animation: none !important; }
  .card::after { display: none !important; }
  .table-scroll table tbody tr { animation: none !important; }
  .section-heading h2::after { animation: none !important; }
  .metric-flash { animation: none !important; }
}
