:root {
  --ink: #242c3d;
  --muted: #8a95a8;
  --line: #e1e6ef;
  --blue: #588fe7;
  --blue-pale: #dbe9ff;
  --purple: #6952da;
  --purple-pale: #eee9ff;
  --teal: #37b6a0;
  --coral: #e98d99;
  --shadow: 0 24px 75px rgba(44, 53, 82, .15), 0 3px 10px rgba(44, 53, 82, .08);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body { overflow: hidden; background: white; color: var(--ink); font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", Arial, sans-serif; }
button, select, input { font: inherit; }
button { cursor: pointer; }
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 3px solid #f0ae5b; outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; top: -60px; left: 14px; z-index: 20; padding: 8px 12px; background: white; }
.skip-link:focus { top: 10px; }

.app-shell { display: grid; grid-template-rows: 72px 50px minmax(0, 1fr); height: 100dvh; min-height: 520px; }
.topbar { display: flex; align-items: center; gap: 22px; padding: 0 30px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fff; z-index: 2; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 252px; color: #6261d9; letter-spacing: -.045em; font-size: 19px; }
.brand-glyph { font-weight: 900; font-size: 20px; letter-spacing: -.09em; }
.brand-glyph span { color: #3a9fca; font-size: 17px; }
.brand strong { font-size: 18px; }
.top-controls { display: flex; align-items: center; gap: 10px; min-width: 0; margin-left: auto; }
.select-control { display: flex; align-items: center; gap: 6px; color: #8d98a9; font-size: 12px; font-weight: 650; }
.select-control select { min-height: 34px; padding: 0 28px 0 10px; background: white; color: #34415a; border: 1px solid #d5deea; border-radius: 7px; font-size: 12px; font-weight: 650; }
.select-control.compact select { min-width: 61px; }
.play-controls { display: flex; gap: 5px; margin-left: 6px; }
.control-button, .about-button, .canvas-tools button, .detail-head-actions button { border: 1px solid #d8e0eb; border-radius: 7px; background: white; color: #68778e; }
.control-button { width: 35px; height: 35px; font-size: 25px; line-height: 1; }
.control-button:disabled { opacity: .4; cursor: not-allowed; }
.play-button { display: flex; align-items: center; justify-content: center; gap: 7px; min-width: 88px; height: 35px; padding: 0 11px; border: 1px solid #6957de; border-radius: 7px; background: #6957de; color: white; font-size: 12px; font-weight: 750; }
.play-button:hover { background: #5945d0; }
.about-button { display: grid; place-items: center; width: 31px; height: 31px; margin-left: 5px; border-radius: 50%; font-weight: 800; }
.control-button:hover, .about-button:hover, .canvas-tools button:hover, .detail-head-actions button:hover { background: #f5f7fb; }

.stagebar { display: flex; align-items: center; gap: 18px; padding: 0 30px; border-bottom: 1px solid #ecf0f5; background: #fcfdff; z-index: 2; }
.stage-buttons { display: flex; align-items: stretch; gap: 0; flex: 1; min-width: 0; }
.stage-buttons button { display: flex; align-items: center; gap: 7px; width: 16.66%; min-width: 91px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: #9aa5b4; font-size: 12px; font-weight: 700; }
.stage-buttons button span { font-size: 10px; color: #b2bbcb; }
.stage-buttons button.active { color: #5d4bd5; border-bottom-color: #7664e5; }
.stage-buttons button.active span { color: #7664e5; }
.stage-buttons button.past { color: #73839a; }
.stage-buttons button:hover { color: #6553d8; }
.scrub-wrap { width: 180px; flex: none; }
.scrub-wrap input { width: 100%; accent-color: #6957de; }

.canvas-shell { position: relative; overflow: hidden; min-height: 0; background: white; }
#scene { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; background: #fff; }
#scene.dragging { cursor: grabbing; }
.canvas-metrics { position: absolute; left: 26px; bottom: 19px; display: flex; gap: 7px; pointer-events: none; }
.canvas-metrics span { padding: 6px 10px; border: 1px solid #e6ebf2; border-radius: 20px; background: rgba(255,255,255,.95); color: #68758a; font-size: 11px; font-weight: 700; box-shadow: 0 2px 7px rgba(42,56,86,.03); }
.canvas-tools { position: absolute; right: 20px; bottom: 16px; display: flex; gap: 4px; background: white; box-shadow: 0 2px 12px rgba(42,56,86,.08); border-radius: 8px; }
.canvas-tools button { width: 34px; height: 34px; font-size: 21px; }
.canvas-hint { position: absolute; top: 17px; right: 24px; color: #b1bac8; font-size: 11px; pointer-events: none; }

/* 画布对象：宽度和颜色来自模型，阶段只调整强调和动态。 */
#scene text { font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", Arial, sans-serif; user-select: none; }
#scene .world-grid { fill: url(#dot-grid); }
#scene .column-title { fill: #8e98ab; font-size: 15px; font-weight: 750; letter-spacing: 2px; }
#scene .column-subtitle { fill: #b3bdca; font-size: 11px; }
#scene .module-hit { fill: transparent; cursor: pointer; }
#scene .module-frame { fill: #fff; stroke: #e0e6f0; stroke-width: 1.5; filter: url(#soft-shadow); }
#scene .module-card { cursor: pointer; }
#scene .module-card:hover .module-frame, #scene .module-card:focus .module-frame { stroke: #a597ed; stroke-width: 2.5; }
#scene .module-card.active .module-frame { stroke: #7664e5; stroke-width: 2.5; }
#scene .module-label { fill: #526074; font-size: 15px; font-weight: 750; }
#scene .module-count { fill: #8f9aac; font-size: 11px; }
#scene .expand-icon { fill: #8d9aac; font-size: 20px; }
#scene .rank-label { fill: #738096; font-size: 12px; font-weight: 750; }
#scene .rank-count { fill: #a2adba; font-size: 10px; }
#scene .bank-stripe { fill: #c8daf8; }
#scene .bank-stripe.selected { fill: #6957de; }
#scene .output-stripe { fill: #dcd5fb; }
#scene .router-cell { stroke: #fff; stroke-width: 1; }
#scene .expert-cell { stroke: white; stroke-width: 1; }
#scene .flow-band { fill: none; stroke-linecap: round; opacity: .34; pointer-events: none; }
#scene .flow-band.input { stroke: #8bb5ed; }
#scene .flow-band.dispatch { stroke: #88b5f6; }
#scene .flow-band.combine { stroke: #a999f5; }
#scene .flow-band.active { opacity: .66; }
#scene .flow-glint { fill: none; stroke-linecap: round; opacity: 0; pointer-events: none; stroke-dasharray: 20 95; }
#scene .flow-glint.dispatch { stroke: #477de0; }
#scene .flow-glint.combine { stroke: #7358da; }
#scene .flow-glint.active { opacity: .68; animation: flow-travel 1.35s linear infinite; }
#scene .center-badge { fill: white; stroke: #dbe3ef; }
#scene .center-number { fill: #4e5d73; font-size: 20px; font-weight: 800; text-anchor: middle; }
#scene .center-caption { fill: #9aa6b7; font-size: 11px; text-anchor: middle; }
#scene .module-index { fill: #b6c1cf; font-size: 10px; font-weight: 800; }
#scene .phase-highlight { opacity: .35; }
@keyframes flow-travel { from { stroke-dashoffset: 115; } to { stroke-dashoffset: 0; } }

/* 逐层展开的详情，主图仍在背后提供空间上下文。 */
.detail-layer { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 28px; }
.detail-layer[hidden] { display: none; }
.detail-backdrop { position: absolute; inset: 0; background: rgba(244,247,252,.72); backdrop-filter: blur(2px); }
.detail-dialog { position: relative; display: flex; flex-direction: column; width: min(1150px, 100%); height: min(760px, calc(100dvh - 56px)); min-height: 480px; overflow: hidden; border: 1px solid #dce3ee; border-radius: 15px; background: #fff; box-shadow: var(--shadow); }
.detail-header { display: flex; justify-content: space-between; align-items: center; gap: 20px; min-height: 70px; padding: 0 24px; border-bottom: 1px solid var(--line); }
.detail-header > div:first-child { display: flex; align-items: baseline; gap: 13px; min-width: 0; }
.detail-number { color: #7865e2; font-size: 12px; font-weight: 850; letter-spacing: .12em; }
.detail-header h2 { margin: 0; font-size: 23px; white-space: nowrap; }
.detail-shape { color: #9aa5b5; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-head-actions { display: flex; gap: 5px; flex: none; }
.detail-head-actions button { width: 34px; height: 34px; font-size: 19px; }
.detail-head-actions button:last-child { font-size: 26px; line-height: 1; }
.detail-head-actions button:disabled { opacity: .35; cursor: not-allowed; }
.detail-subnav { display: flex; align-items: stretch; gap: 4px; min-height: 46px; padding: 0 23px; background: #fbfcff; border-bottom: 1px solid #e9edf4; overflow-x: auto; }
.detail-subnav button { padding: 0 14px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: #8996a8; font-size: 12px; font-weight: 750; white-space: nowrap; }
.detail-subnav button.active { color: #6753d7; border-bottom-color: #7865e2; }
.detail-controls { display: flex; align-items: center; gap: 13px; min-height: 48px; padding: 6px 24px; border-bottom: 1px solid #eef1f6; flex-wrap: wrap; }
.detail-controls label { display: flex; align-items: center; gap: 6px; color: #8793a5; font-size: 11px; font-weight: 700; }
.detail-controls select, .detail-controls input[type="range"] { min-height: 28px; max-width: 180px; border: 1px solid #d8e0ea; border-radius: 5px; background: white; color: #37445a; font-size: 11px; }
.detail-controls select { padding: 2px 7px; }
.detail-controls .mini-play { min-height: 28px; padding: 0 10px; border: 1px solid #d8d0f4; border-radius: 5px; background: #f7f5ff; color: #6751cf; font-size: 11px; font-weight: 800; }
.detail-controls .mini-play:hover { background: #eeebfc; }
.detail-controls .small-stat { color: #75839a; font-size: 11px; margin-left: auto; }
.detail-body { min-height: 0; flex: 1; overflow: auto; padding: 22px 25px 26px; }
.detail-footer { display: flex; justify-content: space-between; align-items: center; min-height: 45px; padding: 0 24px; border-top: 1px solid var(--line); color: #8996a9; font-size: 11px; }
.detail-footer button { border: 0; background: transparent; color: #6f5cd9; font-size: 12px; font-weight: 800; }
.detail-footer button:disabled { opacity: .4; cursor: not-allowed; }

.detail-intro { display: flex; align-items: baseline; justify-content: space-between; gap: 22px; margin: 0 0 16px; }
.detail-intro p { max-width: 760px; margin: 0; color: #647188; font-size: 13px; line-height: 1.7; }
.detail-intro strong { color: #39465f; }
.detail-intro .shape-tag { flex: none; padding: 5px 9px; border-radius: 5px; background: #f4f6fb; color: #65738a; font: 700 11px ui-monospace, SFMono-Regular, Menlo, monospace; }
.viz-split { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(250px, .8fr); gap: 20px; min-height: 375px; }
.viz-main, .viz-side { min-width: 0; padding: 15px 17px; border: 1px solid #e2e8f0; border-radius: 9px; background: #fff; }
.viz-main { overflow: auto; }
.viz-side { background: #fbfcff; }
.viz-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 11px; color: #68778e; font-size: 11px; font-weight: 750; }
.viz-head span:last-child { color: #9ba7b6; font-weight: 500; }
.tensor-grid { display: grid; gap: 2px; min-width: 340px; }
.tensor-row { display: contents; }
.tensor-label { display: flex; align-items: center; justify-content: flex-end; padding-right: 6px; color: #8290a4; font-size: 10px; font-weight: 700; white-space: nowrap; }
.tensor-cell { height: 15px; min-width: 7px; border-radius: 1px; cursor: pointer; }
.tensor-cell.focus { outline: 2px solid #5141c8; outline-offset: -1px; }
.tensor-axis { margin: 8px 0 0 46px; display: flex; justify-content: space-between; color: #a1adbb; font-size: 10px; }
.small-metrics { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
.small-metrics div { padding: 10px; border: 1px solid #e4e9f1; border-radius: 6px; background: white; }
.small-metrics span { display: block; color: #9aa7b6; font-size: 10px; }
.small-metrics strong { display: block; margin-top: 4px; color: #46546c; font-size: 16px; }
.detail-list { margin: 13px 0 0; padding: 0; list-style: none; }
.detail-list li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid #e9edf3; color: #6b7b92; font-size: 11px; }
.detail-list b { color: #424d63; }
.math-card { margin-top: 14px; padding: 12px 14px; border-left: 3px solid #9785e8; border-radius: 0 6px 6px 0; background: #f6f4ff; color: #4a416f; font-size: 12px; line-height: 1.7; overflow-x: auto; }
.math-card math { font-size: 17px; }
.math-card small { display: block; margin-top: 4px; color: #8b82a8; }
.density-bar { display: flex; height: 22px; overflow: hidden; border-radius: 4px; background: #f1f4f8; }
.density-bar i { display: block; height: 100%; }
.density-legend { display: flex; justify-content: space-between; margin-top: 5px; color: #96a3b3; font-size: 10px; }
.task-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.task-table th { position: sticky; top: 0; background: white; z-index: 1; color: #8794a6; font-size: 10px; text-align: left; border-bottom: 1px solid #dfe6ef; padding: 7px 5px; }
.task-table td { padding: 7px 5px; border-bottom: 1px solid #edf1f6; color: #5e6d83; }
.task-table tr.focus td { background: #f3f0ff; color: #4e3dab; }
.task-table tbody tr { cursor: pointer; }
.task-table tbody tr:hover td { background: #f7f9fd; }
.task-table .revealed { animation: row-reveal .28s ease-out both; }
@keyframes row-reveal { from { opacity: .2; transform: translateX(-7px); } to { opacity: 1; transform: translateX(0); } }
.matrix-canvas { display: block; width: min(100%, 620px); height: auto; border: 1px solid #e0e6ef; image-rendering: pixelated; cursor: crosshair; }
.bar-chart { display: flex; align-items: end; gap: 7px; height: 220px; padding: 12px 4px 20px; border-bottom: 1px solid #dbe3ef; }
.bar-chart .bar-column { flex: 1; min-width: 22px; height: 100%; display: flex; flex-direction: column; justify-content: end; align-items: center; gap: 5px; color: #75839b; font-size: 10px; }
.bar-chart .bar-column i { display: block; width: 70%; min-height: 3px; border-radius: 3px 3px 0 0; background: #8ab5ee; }
.bar-chart .bar-column.active i { background: #6c57d9; }
.bar-chart .bar-column b { font-size: 10px; }
.three-heatmaps { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; }
.three-heatmaps > div { min-width: 0; }
.contribution-row { display: grid; grid-template-columns: 52px repeat(var(--k), minmax(34px,1fr)) 80px; align-items: center; gap: 3px; margin-bottom: 3px; }
.contribution-row span, .contribution-row b { padding: 5px 3px; color: #7b899d; text-align: center; font-size: 10px; }
.contribution-cell { display: grid; place-items: center; min-height: 29px; border-radius: 2px; color: #fff; font-size: 10px; line-height: 1.08; text-align: center; cursor: pointer; }
.contribution-row.active .contribution-cell { outline: 1px solid #6c56dd; }
.order-list { display: grid; grid-template-columns: repeat(4,1fr); gap: 7px; }
.order-item { padding: 9px; border: 1px solid #dfe6f0; border-radius: 5px; background: #f9fbfe; color: #64748c; font-size: 11px; }
.order-item strong { display: block; color: #6551d9; }
.source-link { color: #6250cf; font-weight: 750; text-decoration: none; }
.source-link:hover { text-decoration: underline; }

@media (max-width: 1100px) {
  .topbar { padding: 0 15px; gap: 9px; }
  .brand { min-width: 183px; font-size: 16px; }
  .brand strong { font-size: 15px; }
  .select-control.speed { display: none; }
  .stagebar { padding: 0 16px; }
  .scrub-wrap { width: 120px; }
}
@media (max-width: 780px) {
  .app-shell { grid-template-rows: 94px 45px minmax(0,1fr); }
  .topbar { position: relative; display: grid; grid-template-columns: 1fr auto; grid-template-rows: 42px 50px; gap: 0; padding: 0 12px; overflow: visible; }
  .brand { min-width: 0; }
  .brand-glyph { display: none; }
  .top-controls { grid-row: 2; grid-column: 1 / -1; width: 100%; margin-left: 0; overflow-x: auto; overflow-y: hidden; }
  .play-controls { position: absolute; top: 4px; right: 54px; margin-left: 0; }
  .play-controls .control-button { width: 29px; }
  .play-controls .play-button { min-width: 72px; }
  .about-button { grid-row: 1; grid-column: 2; margin-left: 0; }
  .select-control span { display: none; }
  .stagebar { overflow-x: auto; }
  .stage-buttons { width: max-content; flex: none; }
  .stage-buttons button { min-width: 80px; }
  .scrub-wrap { display: none; }
  .canvas-metrics { flex-wrap: wrap; left: 10px; bottom: 8px; max-width: calc(100% - 105px); }
  .canvas-metrics span { padding: 4px 7px; font-size: 9px; }
  .canvas-tools { right: 9px; bottom: 8px; }
  .canvas-hint { display: none; }
  .detail-layer { padding: 0; }
  .detail-dialog { width: 100%; height: 100dvh; max-height: none; border-radius: 0; }
  .detail-header { padding: 0 14px; min-height: 60px; }
  .detail-header h2 { font-size: 17px; }
  .detail-shape { display: none; }
  .detail-subnav { padding: 0 10px; }
  .detail-controls { padding: 6px 12px; }
  .detail-body { padding: 15px 12px; }
  .viz-split { grid-template-columns: 1fr; }
  .viz-main, .viz-side { padding: 12px; }
  .detail-footer { padding: 0 12px; }
  .three-heatmaps { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
