:root {
  color-scheme: dark;
  --bg: #080d18;
  --bg-soft: #0c1424;
  --panel: #101a2d;
  --panel-2: #0d1627;
  --border: #22304a;
  --border-soft: #1a2740;
  --text: #e6edf7;
  --muted: #8a9ab4;
  --dim: #5f7191;
  --accent: #38bdf8;
  --accent-2: #f97316;
  --green: #34d399;
  --yellow: #fbbf24;
  --red: #f87171;
  --violet: #a78bfa;
  --mono: "JetBrains Mono", "Cascadia Mono", Consolas, "SFMono-Regular", monospace;
  --sans: "Segoe UI", system-ui, -apple-system, "Microsoft YaHei", "PingFang SC", sans-serif;
  --sidebar-w: 384px;
  --hair: var(--border-soft);
  --hair-soft: #16223a;
  --field-bg: #0b1423;
  --side-pad: 12px;
  --sec-gap: 16px;
  --ctl-h: 30px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
.mono { font-family: var(--mono); }
button, input, select { font-family: inherit; }
button { cursor: pointer; }

.layout { display: flex; height: 100vh; width: 100vw; }

/* ---------- 侧栏 ---------- */
.sidebar {
  width: var(--sidebar-w, 384px);
  flex: 0 0 var(--sidebar-w, 384px);
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--bg-soft);
  border-right: 1px solid var(--hair);
  min-height: 0;
}
.sidebar-resizer {
  position: absolute; top: 0; right: -3px; width: 7px; height: 100%;
  cursor: col-resize; z-index: 12; background: transparent;
  transition: background .15s;
}
.sidebar-resizer::after { content: ''; position: absolute; top: 0; bottom: 0; left: 2px; width: 2px; background: var(--accent); opacity: 0; transition: opacity .15s ease; }
.sidebar-resizer:hover::after, body.resizing-sidebar .sidebar-resizer::after { opacity: .95; }
body.resizing-sidebar { cursor: col-resize; user-select: none; }
body.resizing-sidebar * { user-select: none !important; }
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 18px 16px;
  border-bottom: 1px solid var(--border-soft);
}
.brand-mark {
  width: 38px; height: 38px; flex: 0 0 38px;
  border-radius: 10px; overflow: hidden;
}
.brand-mark img { display: block; width: 100%; height: 100%; }
.brand-text { min-width: 0; }
.brand-text h1 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: 0.3px; white-space: nowrap; }
.brand-text p {
  margin: 3px 0 0; font-size: 9px; letter-spacing: 0.9px; color: var(--dim); font-family: var(--mono);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.scroll { flex: 1; min-height: 0; overflow-y: auto; position: relative; padding: var(--side-pad) var(--side-pad) 24px; }
.scroll::-webkit-scrollbar { width: 8px; }
.scroll::-webkit-scrollbar-thumb { background: #24344f; border-radius: 8px; }
.scroll::-webkit-scrollbar-track { background: transparent; }

/* ---------- 文档式小节 ---------- */
.doc-sec { margin: 0 0 var(--sec-gap); padding-top: 13px; border-top: 1px solid var(--hair); }
.sec-head { display: flex; align-items: center; gap: 8px; min-height: var(--ctl-h); cursor: pointer; user-select: none; }
.sec-head:hover .sec-title { color: #fff; }
.sec-no { font-family: var(--mono); font-size: 10.5px; color: var(--dim); letter-spacing: .4px; }
.sec-title {
  flex: 1; min-width: 0; margin: 0; font-size: 13px; font-weight: 600;
  color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sec-toggle {
  flex: 0 0 auto; width: 24px; height: 24px; display: grid; place-items: center;
  border: 0; background: none; color: var(--dim); transition: transform .16s ease;
}
.sec-toggle:hover { color: var(--accent); }
.doc-sec.collapsed .sec-toggle { transform: rotate(-90deg); }
.doc-sec.collapsed .sec-body { display: none; }
.sec-body { padding-top: 6px; }
.sub-sec { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--hair-soft); }
.sub-sec:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.sub-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.sub-title { margin: 0; font-size: 11.5px; font-weight: 600; color: var(--muted); }
.sub-note { margin-left: auto; font-size: 9.8px; color: var(--dim); white-space: nowrap; }

label { display: block; color: var(--muted); font-size: 11.5px; margin: 10px 0 5px; }
label:first-of-type { margin-top: 0; }
input[type="text"], input[type="number"], input:not([type]), select {
  width: 100%;
  background: var(--field-bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 7px 9px;
  font-size: 12.5px;
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus { border-color: var(--accent); }
input:disabled { opacity: .45; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #7c8db0 50%), linear-gradient(135deg, #7c8db0 50%, transparent 50%); background-position: calc(100% - 16px) 14px, calc(100% - 11px) 14px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
.narrow { width: 118px; padding: 6px 8px; font-size: 11.5px; }
.hint { margin: 8px 0 0; font-size: 10.8px; line-height: 1.65; color: var(--dim); }
.hint code { font-family: var(--mono); color: #9fb6d8; background: rgba(120,150,190,.10); padding: 1px 4px; border-radius: 3px; }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
/* 指定 K / s / σ / ω 定位：输入框占剩余空间（带最小宽度保护），按钮按内容定宽且不换行 */
.k-locate-row { display: flex; align-items: stretch; gap: 8px; }
.k-locate-row input { flex: 1 1 auto; width: auto; min-width: 72px; }
.k-locate-row select { flex: 0 0 76px; width: 76px; padding: 6px 20px 6px 7px; font-size: 11px;
  background-position: calc(100% - 12px) 14px, calc(100% - 8px) 14px; }
.k-locate-row .btn { flex: 0 0 auto; white-space: nowrap; }
.k-locate-actions { display: flex; gap: 6px; margin-top: 6px; }
.k-locate-actions .btn { flex: 1 1 auto; padding: 6px 8px; font-size: 11.5px; }
.k-locate-actions .btn.ghost { flex: 0 0 62px; }
.hit-row { cursor: pointer; }
.hit-row:hover td { color: var(--text); }
.hit-row.sel td { color: var(--accent); }
.row-between label { margin: 0; }
.range-head { margin-top: 14px; margin-bottom: 6px; }
.tag { font-size: 11px; color: var(--accent); background: rgba(56,189,248,.10); padding: 2px 7px; border-radius: 4px; }

input[type="range"] { width: 100%; accent-color: var(--accent); height: 18px; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 9px 8px; }
/* 图层密度自定义 */
.layer-density { margin-top: 11px; padding-top: 10px; border-top: 1px dashed var(--border); }
.density-title { display: flex; align-items: center; gap: 5px; font-size: 10.6px; color: var(--muted); margin-bottom: 6px; }
.layer-density label { margin: 7px 0 3px; font-size: 10.4px; }
.layer-density input { padding: 5px 8px; font-size: 11.2px; }
.layer-density .hint { margin-top: 8px; }
.freq-toggles { display: flex; flex-direction: column; gap: 6px; margin: 10px 0 2px; }
.freq-toggles label { margin: 0; }
.param-actions { margin-top: 7px; }
.edge-actions { display: flex; gap: 6px; margin-top: 6px; }
.edge-actions .btn { flex: 1; font-size: 10.6px; padding: 6px 5px; }
.param-actions .btn { width: 100%; font-size: 11px; padding: 7px 8px; }
.param-actions { display: grid; gap: 6px; }
.param-derived { margin: 9px 0 2px; padding: 4px 0 4px 10px; border-left: 2px solid var(--hair);
  font-family: var(--mono); font-size: 10.6px; line-height: 1.75;
  color: #9fb6d8; word-break: break-all; }
.param-derived b { color: #7dd3fc; font-weight: 600; }
.param-derived .pd-err { color: var(--red); }
.break-kind { display: inline-block; margin-right: 5px; padding: 1px 5px; border-radius: 4px; font-size: 10px;
  border: 1px solid rgba(251,191,36,.32); color: #fbbf24; }
.break-kind.in { border-color: rgba(167,139,250,.38); color: #c4b5fd; }

/* 画布顶栏只显示当前子模块标题；选择器已移到侧栏金刚区下方的下拉 */
.topbar-lead { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1 1 auto; }
.view-title { min-width: 0; margin: 0; font-size: 12.5px; font-weight: 650; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 结果区公式排版 ---------- */
.math-host { position: relative; }
span.mono.math-host, td.mono.math-host { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; }
.code-line.math-host, .plot-note.math-host { padding-right: 30px; }
.math-render { font-family: "Cambria Math", "Times New Roman", Georgia, serif; font-size: 12.8px; color: #dbe8fb; line-height: 1.9; white-space: pre-wrap; word-break: break-word; }
.math-render .m-var { font-style: italic; }
.math-render sup, .math-render sub { font-size: .72em; line-height: 0; }
.math-render .m-op { padding: 0 1px; color: #9fb6d8; }
.m-frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; margin: 0 2px; font-size: .92em; }
.m-frac .m-num { border-bottom: 1px solid currentColor; padding: 0 3px 1px; }
.m-frac .m-den { padding: 1px 3px 0; }
.m-sqrt { display: inline-flex; align-items: stretch; }
.m-sqrt .m-radic { font-size: 1.1em; }
.m-sqrt .m-body { border-top: 1px solid currentColor; padding: 1px 2px 0; }
.math-copy { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; padding: 0; border: 1px solid var(--border); border-radius: 4px; background: var(--panel-2); color: var(--dim); }
.math-copy:hover, .math-copy.copied { color: var(--accent); border-color: var(--accent); }
.code-line.math-host > .math-copy, .plot-note.math-host > .math-copy { position: absolute; top: 4px; right: 4px; }

/* ---------- 导出模态窗 ---------- */
.export-modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px; }
.export-backdrop { position: absolute; inset: 0; background: rgba(3, 7, 15, .74); backdrop-filter: blur(3px); }
.export-dialog {
  position: relative; width: min(560px, 100%); max-height: min(86vh, 780px);
  display: flex; flex-direction: column; border-radius: 14px; overflow: hidden;
  border: 1px solid #33486c; background: linear-gradient(165deg, #142038, #0b1322);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .6), 0 0 0 1px rgba(56, 189, 248, .08);
}
.export-head { display: flex; align-items: center; gap: 11px; padding: 15px 17px; border-bottom: 1px solid var(--border-soft); }
.export-head-icon { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 9px; color: #04121f; background: linear-gradient(135deg, #38bdf8, #6366f1); }
.export-head-text { flex: 1; min-width: 0; }
.export-head-text h2 { margin: 0; font-size: 14px; font-weight: 650; color: var(--text); }
.export-head-text p { margin: 3px 0 0; font-size: 10.5px; color: var(--dim); }
.export-close { width: 26px; height: 26px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel-2); color: var(--muted); font-size: 16px; line-height: 1; }
.export-close:hover { color: var(--text); border-color: var(--accent); }
.export-body { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 17px 10px; }
.export-section { padding: 12px 0; border-bottom: 1px dashed var(--border-soft); }
.export-section:last-child { border-bottom: 0; }
.export-section h3 { margin: 0 0 8px; font-size: 11px; font-weight: 650; letter-spacing: .5px; color: var(--muted); }
.export-scope { padding: 8px 10px; margin-bottom: 9px; border-radius: 7px; border: 1px solid #2b3d5c; background: rgba(8, 13, 24, .6); color: #a9bdd8; font-size: 10.8px; line-height: 1.7; }
.export-field { display: flex; align-items: center; gap: 10px; margin: 0; font-size: 10.8px; color: var(--muted); }
.export-field > span { flex: 0 0 66px; }
.export-field select { flex: 1; padding: 6px 8px; font-size: 11px; }
.export-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px 10px; margin-bottom: 9px; }
.export-grid > label { margin: 0; display: flex; flex-direction: column; gap: 4px; font-size: 10.5px; color: var(--muted); }
.export-grid input, .export-grid select, .export-section > input { width: 100%; padding: 6px 9px; font-size: 11.5px; }
.export-section > input { margin-top: 2px; }
.export-custom { margin-top: 9px; }
.export-foot { display: flex; align-items: center; gap: 8px; padding: 12px 17px; border-top: 1px solid var(--border-soft); background: rgba(8, 13, 24, .45); }
.export-foot .status { flex: 1; min-width: 0; font-size: 10.4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.export-foot .btn.primary { width: auto; margin: 0; padding: 8px 14px; }
@media (max-width: 620px) { .export-grid { grid-template-columns: 1fr; } }
.check { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11.3px; margin: 0; cursor: pointer; white-space: nowrap; }
.check input { accent-color: var(--accent); width: 13px; height: 13px; margin: 0; flex: 0 0 13px; }

.lucide { display: inline-block; vertical-align: middle; flex: 0 0 auto; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; border-radius: 6px; border: 1px solid var(--border); padding: 8px 12px; font-size: 12px; color: var(--text); background: #16233a; transition: .15s; }
.btn:hover { border-color: #3a5378; background: #1c2d49; }
.btn.primary { padding: 10px; font-weight: 600; letter-spacing: .3px; color: #04121f; background: var(--accent); border: none; }
/* 主按钮只有落在侧栏小节里才独占整行；顶栏「计算」按内容定宽，
   否则 .btn.primary 的 margin-top 会把它从顶栏中线往下顶，看起来与周边不对齐 */
.sec-body .btn.primary, .param-actions .btn.primary, .wb-actions .btn.primary { width: 100%; margin-top: 14px; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.primary:disabled { opacity: .55; cursor: wait; }
.btn.ghost { background: transparent; padding: 6px 11px; font-size: 11.5px; color: var(--muted); }
.status { margin-top: 9px; font-size: 11.3px; line-height: 1.5; min-height: 0; }
/* 顶栏里的状态文字与「计算」按钮同一条中线 */
.topbar .status { margin-top: 0; align-self: center; }
.status.ok { color: var(--green); }
.status.err { color: var(--red); }
.status.warn { color: var(--yellow); }

/* ---------- 分析结果 ---------- */
.info { font-size: 11.5px; }
.info .empty-info { color: var(--dim); line-height: 1.6; }
.info h4 { margin: 14px 0 7px; font-size: 10.8px; font-weight: 650; letter-spacing: .4px; color: var(--muted); text-transform: uppercase; }
.info h4:first-child { margin-top: 0; }
.kv { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; color: var(--muted); }
.kv b { color: var(--text); font-family: var(--mono); font-weight: 500; font-size: 11px; }
.chip { display: inline-block; font-family: var(--mono); font-size: 10.5px; padding: 2px 7px; border-radius: 4px; margin: 0 5px 5px 0; border: 1px solid; }
.chip.good { color: var(--green); border-color: rgba(52,211,153,.35); background: rgba(52,211,153,.08); }
.chip.info-c { color: var(--accent); border-color: rgba(56,189,248,.3); background: rgba(56,189,248,.07); }
.chip.warn { color: var(--yellow); border-color: rgba(251,191,36,.32); background: rgba(251,191,36,.07); }
.list { margin: 0; padding: 0; list-style: none; }
.list li { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; color: var(--muted); font-family: var(--mono); font-size: 10.7px; }
.list li span:last-child { color: var(--text); }
.warn-line { color: var(--yellow); font-size: 10.8px; line-height: 1.55; margin: 3px 0; }
details > summary { cursor: pointer; color: var(--muted); font-size: 11px; padding: 4px 0; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸ "; color: var(--accent); }
details[open] > summary::before { content: "▾ "; }

/* ---------- 主绘图区 ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.topbar { height: 50px; flex: 0 0 50px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; border-bottom: 1px solid var(--border-soft); gap: 12px; }
.legend { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.lg { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.swatch { font-style: normal; font-family: var(--mono); font-size: 14px; width: 15px; text-align: center; line-height: 1; }
.swatch.pole { color: #fb7185; }
.swatch.zero { color: var(--accent); }
.swatch.break { color: var(--yellow); font-size: 11px; }
.line { width: 18px; height: 0; border-top: 2px solid var(--accent-2); display: inline-block; }
.line.dash { border-top: 2px dashed #64748b; }
.actions { display: flex; gap: 8px; align-items: center; }
/* 状态文字换行会把行高撑开，按钮默认 stretch 会被一起拉高——保持单行 + 中线对齐 */
.topbar .actions > .btn { flex: 0 0 auto; align-self: center; }
.canvas-shell { flex: 1; position: relative; min-height: 0; overflow: hidden; }
#plot { display: block; width: 100%; height: 100%; cursor: crosshair; }
#plot.dragging { cursor: grabbing; }
.canvas-tip { position: absolute; right: 14px; bottom: 12px; color: var(--dim); font-size: 10.5px; pointer-events: none; letter-spacing: .2px; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: rgba(10, 18, 32, .95); border: 1px solid #35507a;
  border-radius: 7px; padding: 9px 11px; min-width: 178px;
  box-shadow: 0 8px 28px rgba(0,0,0,.5);
  font-family: var(--mono); font-size: 11px; line-height: 1.65; color: var(--text);
}
.tooltip .t-title { color: var(--accent); font-weight: 600; margin-bottom: 3px; }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 14px; color: var(--muted); }
.tooltip .t-row b { color: var(--text); font-weight: 500; }
.footer { height: 34px; flex: 0 0 34px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 12px; border-top: 1px solid var(--border-soft); color: var(--dim); font-size: 10.5px; }
#footerLeft { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.footer-actions { display: flex; align-items: center; gap: 5px; }
.footer-actions label { margin: 0; font-size: 10px; color: var(--dim); }
.mini-select { width: auto; padding: 2px 20px 2px 6px; font-size: 10px; font-family: var(--mono); background-position: calc(100% - 8px) 8px, calc(100% - 5px) 8px; }
.footer-actions .btn.ghost { padding: 3px 7px; font-size: 10px; white-space: nowrap; }
.footer > span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 34%; }
.footer-actions label { white-space: nowrap; }
.chart-tools { position: absolute; top: 6px; right: 8px; display: flex; gap: 4px; z-index: 3; }
.chart-tools button { display: inline-flex; align-items: center; gap: 3px; font-size: 9.5px; padding: 2px 7px; border-radius: 4px; border: 1px solid var(--border); background: rgba(12,20,36,.88); color: var(--muted); }
.chart-tools button:hover { color: var(--text); border-color: var(--accent); }

/* ---------- 分式 / LaTeX 双入口 ---------- */
.def-derived { margin-top: 9px; padding: 6px 0 6px 10px; border-left: 2px solid var(--hair);
  font-family: var(--mono); font-size: 10.6px; line-height: 1.75; color: #9fb6d8; word-break: break-all; }
.latex-follow { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.latex-follow label { margin: 0; font-size: 10.5px; }
.latex-follow select { flex: 1; width: auto; padding: 5px 8px; font-size: 11px; }
.sec-body textarea { width: 100%; min-height: 52px; resize: vertical; background: var(--field-bg);
  border: 1px solid var(--border); color: #d8e6fb; border-radius: 4px; padding: 8px 10px;
  font-family: var(--mono); font-size: 11.5px; line-height: 1.6; outline: none; }
.sec-body textarea:focus { border-color: var(--accent); }
.routh-actions { margin-bottom: 9px; }
.routh-cell { cursor: copy; display: inline-block; padding: 1px 3px; border-radius: 3px; white-space: nowrap; }
.routh-cell:hover { background: rgba(56,189,248,.14); }

/* 传递函数：N(s) / D(s) 上下两行，中间只留 1px 实线 */
.tf { margin-top: 4px; }
.tf-row { display: flex; align-items: center; gap: 8px; }
.tf-prefix { flex: 0 0 34px; text-align: right; font-family: var(--mono); font-size: 10.5px; color: var(--dim); user-select: none; }
.tf-row input { flex: 1; min-width: 0; }
.tf-line { height: 0; border-top: 1px solid var(--hair); margin: 6px 0 6px 42px; }
.tf-note { margin: 8px 0 0; font-size: 10.2px; line-height: 1.6; color: var(--dim); }

.latex-status { display: flex; align-items: flex-start; margin-top: 7px; font-size: 10.4px; line-height: 1.5; color: var(--dim); }
.latex-status::before { content: ''; flex: 0 0 4px; width: 4px; height: 4px; border-radius: 50%; background: var(--green); margin: 5px 6px 0 0; }
.latex-status.err { color: var(--red); }
.latex-status.err::before { background: var(--red); }

/* ---------- 自动类别识别 ---------- */
.class-line { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; margin: 8px 0 2px; min-height: 22px; }
.class-line .class-hint { color: var(--dim); font-size: 10.8px; }
.class-chip { font-size: 10.3px; padding: 2px 7px; border-radius: 4px; border: 1px solid rgba(56,189,248,.28); background: rgba(56,189,248,.08); color: #9bd3f5; white-space: nowrap; }
.class-chip.warn { border-color: rgba(251,191,36,.32); background: rgba(251,191,36,.08); color: var(--yellow); }
.class-chip.bad { border-color: rgba(248,113,113,.32); background: rgba(248,113,113,.08); color: var(--red); }

/* ---------- 可选示例库 ---------- */
.preset-box { margin-top: 12px; border-top: 1px solid var(--hair-soft); padding-top: 9px; }
.preset-box > summary { cursor: pointer; color: var(--muted); font-size: 11px; list-style: none; }
.preset-box > summary::-webkit-details-marker { display: none; }
.preset-box > summary::before { content: "▸ "; color: var(--accent); }
.preset-box[open] > summary::before { content: "▾ "; }
.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 9px; }
.preset-btn { font-size: 10.6px; color: var(--muted); background: var(--field-bg); border: 1px solid var(--border-soft); border-radius: 4px; padding: 6px 7px; text-align: left; }
.preset-btn:hover { color: var(--text); border-color: var(--accent); }

/* ---------- 角度单位切换 / 三制对比 ---------- */
.unit-switch { display: flex; gap: 4px; margin: 7px 0 8px; }
.unit-btn { flex: 1; font-size: 10.1px; padding: 4px 3px; border-radius: 4px; border: 1px solid var(--border); background: var(--panel-2); color: var(--muted); }
.unit-btn:hover { color: var(--text); }
.unit-btn.active { color: #04121f; background: var(--accent); border-color: var(--accent); font-weight: 600; }
.cmp-table { width: 100%; border-collapse: collapse; margin: 6px 0 10px; font-family: var(--mono); font-size: 10px; }
.cmp-table th, .cmp-table td { border-bottom: 1px solid var(--border-soft); padding: 4px 5px; text-align: left; color: var(--muted); }
.cmp-table th { color: var(--dim); font-weight: 500; }

/* ---------- 目录条：滚动区之上，展开为浮层 ---------- */
.doc-toc { position: relative; flex: 0 0 auto; height: var(--ctl-h); padding: 0 6px; border-bottom: 1px solid var(--hair); }
.toc-sum { width: 100%; height: 100%; display: flex; align-items: center; gap: 7px; padding: 0;
  border: 0; background: none; color: var(--muted); font-size: 11px; text-align: left; }
.toc-sum:hover { color: var(--text); }
.toc-cur { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toc-chev { flex: 0 0 auto; transition: transform .16s ease; }
.doc-toc.open .toc-chev { transform: rotate(180deg); }
.toc-list { position: absolute; top: 100%; left: 0; right: 0; z-index: 8;
  list-style: none; margin: 0; padding: 4px 6px; max-height: min(50vh, 320px); overflow-y: auto;
  border: 1px solid var(--hair); border-top: 0; background: var(--bg-soft); }
.toc-item { width: 100%; display: flex; align-items: center; gap: 8px; padding: 6px;
  border: 0; background: none; color: var(--muted); font-size: 12px; text-align: left; white-space: nowrap; }
.toc-item:hover { color: var(--text); background: var(--panel-2); }
.toc-item.active { color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.toc-no { flex: 0 0 22px; font-family: var(--mono); font-size: 10px; color: var(--dim); }
.toc-item.active .toc-no { color: var(--accent); }
.toc-item.is-collapsed { color: var(--dim); }
.toc-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* 子模块下拉：位于金刚区正下方，与目录条同高、同一套条形控件外观 */
.sub-nav { padding: 0 6px; border-top: 1px solid var(--hair); }
.sub-nav-row { display: flex; align-items: center; gap: 8px; height: 100%; margin: 0; color: var(--muted); font-size: 11px; }
.sub-nav-label { flex: 0 0 auto; font-size: 10.5px; letter-spacing: .3px; color: var(--dim); }
.sub-nav select {
  flex: 1 1 auto; width: auto; min-width: 0; height: calc(var(--ctl-h) - 8px);
  padding: 0 26px 0 8px; font-size: 11.5px; color: var(--text);
  background-color: rgba(56,189,248,.06); border-color: transparent;
  background-position: calc(100% - 14px) calc(50% - 2px), calc(100% - 9px) calc(50% - 2px);
}
.sub-nav select:hover { border-color: var(--border); }

/* ---------- 模块工作台 ---------- */
[hidden] { display: none !important; }
.root-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.module-nav { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 10px 12px 0; margin-bottom: 12px; }
.module-btn { font-size: 10.8px; padding: 7px 4px; border-radius: 5px; border: 1px solid transparent; background: transparent; color: var(--muted); }
.module-btn:hover { color: var(--text); background: var(--panel-2); }
.module-btn.active { color: var(--accent); background: rgba(56,189,248,.08); box-shadow: inset 0 -2px 0 var(--accent); font-weight: 650; }
.module-panel[hidden] { display: none !important; }
.hidden { display: none !important; }
.sub-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.sub-tab { font-size: 11px; padding: 5px 10px; border-radius: 5px; border: 1px solid var(--border); background: transparent; color: var(--muted); }
.sub-tab.active { color: var(--text); background: #1b2b46; border-color: rgba(56,189,248,.35); }
.analysis-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.analysis-stage { flex: 1; min-height: 0; overflow: auto; padding: 14px 16px 24px; }
.doc-block { margin: 0 0 18px; padding: 0; border: 0; background: none; }
.doc-block + .doc-block { border-top: 1px solid var(--hair); padding-top: 14px; }
.blk-title { margin: 0 0 8px; font-size: 12px; font-weight: 600; color: var(--text); }
.plot-note { color: var(--dim); font-size: 10.6px; margin-top: 7px; line-height: 1.6; }
.chart-box { position: relative; width: 100%; height: var(--chart-h, var(--chart-h-base, 300px)); }
.chart-box canvas { display: block; width: 100%; height: 100%; }
.data-table { width: 100%; border-collapse: collapse; font-size: 11.2px; }
.data-table th, .data-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border-soft); color: var(--muted); }
.data-table th { color: var(--dim); font-weight: 500; font-size: 10.5px; }
.data-table td b { color: var(--text); font-family: var(--mono); font-weight: 500; }
.steps { counter-reset: step; list-style: none; margin: 0; padding: 0; }
.steps li { position: relative; padding: 6px 0 6px 6px; color: var(--muted); font-size: 11.2px; line-height: 1.65; border-bottom: 1px dashed var(--border-soft); }
.steps li:last-child { border-bottom: 0; }
.code-line { font-family: var(--mono); font-size: 11px; color: #a5d6f7; background: none; border: 0; border-left: 2px solid var(--hair); border-radius: 0; padding: 6px 0 6px 10px; line-height: 1.7; overflow-x: auto; white-space: pre-wrap; word-break: break-word; }
.stat-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px 14px; }
.stat span { display: block; color: var(--dim); font-size: 10.4px; margin-bottom: 3px; }
.stat b { color: var(--text); font-family: var(--mono); font-size: 13px; font-weight: 600; }
.edge-row { display: grid; grid-template-columns: 1fr 1fr 1.3fr 28px; gap: 5px; margin-bottom: 5px; }
.edge-row input { padding: 5px 6px; font-size: 11px; }
.edge-row button { border: 1px solid var(--border); background: var(--panel-2); color: var(--red); border-radius: 5px; }
.matrix-input { width: 100%; min-height: 74px; resize: vertical; font-family: var(--mono); font-size: 11px; }

@media (max-width: 1080px) {
  .legend { gap: 10px; }
  .lg:nth-child(n+4) { display: none; }
}

/* ---------- 移动端：WebView 壳 / 手机浏览器 ---------- */
/* 画布接管全部指针手势，禁止浏览器把拖拽解释为滚动或页面缩放 */
#plot { touch-action: none; }

/* 触屏没有悬停：轻点命中的读数条固定贴底显示 */
.tooltip.pinned {
  left: 10px !important; right: 10px !important;
  top: auto !important; bottom: 44px;
  min-width: 0; box-shadow: 0 -8px 26px rgba(0, 0, 0, .55);
}

.nav-toggle {
  display: none;
  position: absolute; top: 7px; left: 8px; z-index: 36;
  width: 34px; height: 34px; padding: 0;
  align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 7px;
  background: rgba(12, 20, 36, .92); color: var(--muted);
  transition: color .15s, border-color .15s;
}
.nav-toggle:active { color: var(--text); border-color: var(--accent); }

/* 窄屏（竖屏手机）与矮屏（横屏手机）都转为抽屉布局：侧栏脱离文档流，主区占满 */
@media (max-width: 900px), (max-height: 520px) {
  .layout { height: 100dvh; }
  .main { position: relative; width: 100%; }

  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 40;
    /* 宽度由 shell.js 在打开时冻结为像素值：软键盘弹起会改变视口宽度，
       若用 vw 计算抽屉会跟着变窄，输入时布局抖动。 */
    width: var(--drawer-w, 310px); max-width: 100%; flex-basis: auto;
    transform: translateX(-101%);
    transition: transform .22s cubic-bezier(.3, .8, .3, 1);
    box-shadow: 0 0 44px rgba(0, 0, 0, .65);
  }
  body.nav-open .sidebar { transform: none; }
  .sidebar-resizer { display: none; }
  .nav-toggle { display: inline-flex; }

  /* 抽屉遮罩用伪元素，不新增 DOM */
  .layout::after {
    content: ''; position: fixed; inset: 0; z-index: 35;
    background: rgba(3, 7, 15, .55);
    opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  body.nav-open .layout::after { opacity: 1; pointer-events: auto; }

  .topbar { height: 46px; flex: 0 0 46px; padding: 0 10px 0 50px; gap: 8px; }
  .footer { height: 30px; flex: 0 0 30px; font-size: 10px; padding: 0 8px; }
  #footerLeft { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .btn, .module-btn, .sub-tab, .sec-head { min-height: 34px; }
  /* 目录条与子模块下拉都在抽屉里，随抽屉一起出现（画布顶栏不放目录入口） */
  .doc-toc { height: 34px; }
  .footer-actions .btn.ghost { min-height: 24px; }
  .export-modal { padding: 10px; }
  .export-dialog { max-height: 90dvh; }
}

/* 窄屏：图表与表格转单列 */
@media (max-width: 900px) {
  .chart-box { --chart-h: 260px; }
  .edge-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.2fr) 26px; }
  .edge-row input { min-width: 0; }
}

@media (max-width: 560px) {
  :root { --side-pad: 10px; --sec-gap: 12px; --ctl-h: 32px; }
  .legend { display: none; }
  #footerRight { display: none; }
  .brand { padding: 10px 10px 8px; gap: 8px; }
  .brand-mark { width: 28px; height: 28px; flex-basis: 28px; }
  .brand-text p { display: none; }
  .module-nav { display: flex; overflow-x: auto; gap: 4px; padding: 6px 8px 0; margin-bottom: 8px; }
  .module-nav::-webkit-scrollbar { display: none; }
  .module-btn { flex: 0 0 auto; font-size: 10px; padding: 6px 9px; }
  /* 顶部子标签单行横滚：窄屏下 3~4 个标签不能让顶栏换行挤压状态与计算按钮 */
  .topbar .sub-tabs { flex: 1 1 auto; min-width: 0; flex-wrap: nowrap; overflow-x: auto; }
  .topbar .sub-tabs::-webkit-scrollbar { display: none; }
  .topbar .sub-tab { flex: 0 0 auto; }
  #moduleStatus { display: none; }
  input { padding: 8px; font-size: 12px; }
  .analysis-stage { padding: 10px 10px 20px; }
  .stat-strip { grid-template-columns: 1fr 1fr; }
  .data-table { font-size: 10.4px; }
  .data-table th, .data-table td { padding: 5px 4px; word-break: break-word; }
  .canvas-tip { display: none; }
  /* 底部条改两行：状态占一行，导出入口整行右对齐，避免按钮被裁切 */
  .footer { flex-wrap: wrap; height: auto; flex: 0 0 auto; padding: 4px 8px; row-gap: 4px; gap: 4px; overflow: hidden; }
  .footer-actions { flex: 1 1 100%; width: 100%; justify-content: flex-end; gap: 4px; }
  .footer-actions > label, .footer-actions > #formulaStyle { display: none; }
  .footer-actions .btn.ghost { padding: 3px 6px; font-size: 9.5px; }
  #footerLeft { flex: 1 1 100%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* 矮屏（横屏手机）：宽度足够，保留双列图表，只压缩纵向留白。
   必须带 orientation: landscape——竖屏时软键盘会把视口高度压到 520 以下，
   否则弹出的键盘会误触发这一整套横屏排版。 */
@media (max-height: 520px) and (orientation: landscape) {
  .legend, .canvas-tip { display: none; }
  .chart-box { --chart-h: 220px; }
  .topbar { height: 40px; flex: 0 0 40px; }
  /* 用最小高度而非固定高度：否则会压死 ≤560px 的两行底部条 */
  .footer { height: auto; min-height: 26px; flex: 0 0 auto; font-size: 9.5px; }
  .nav-toggle { top: 3px; }
  .brand { padding: 9px 14px 9px; }
  .brand-mark { width: 30px; height: 30px; flex: 0 0 30px; border-radius: 8px; }
  .brand-text h1 { font-size: 14px; }
}
