:root {
  --bg: #0b0e14;
  --bg-soft: #11151f;
  --panel: #141a26;
  --panel-2: #0f141d;
  --line: #232b3a;
  --line-2: #2b3547;
  --text: #d8e0ee;
  --text-dim: #8b97ad;
  --text-faint: #4c5874;
  --accent: #5b9bff;
  --accent-2: #37d0a0;
  --warn: #ffb454;
  --danger: #ff6b6b;
  --purple: #b48cff;
  --pink: #ff8fb3;
  --nav-h: 52px;
  --radius: 10px;
  --mono: 'SFMono-Regular', Consolas, 'Cascadia Code', 'Roboto Mono', monospace;
  --sans: 'Inter Variable', -apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  overflow: hidden;
}

#app { display: flex; height: 100vh; }

/* ---------- 侧边栏 ---------- */
#sidebar {
  width: 216px;
  flex: 0 0 216px;
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 5;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  color: #fff; font-size: 20px; font-family: var(--mono); font-weight: 700;
}
.brand-name { font-weight: 650; letter-spacing: .3px; }

#nav { flex: 1; padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text-dim);
  font: inherit; font-weight: 520; cursor: pointer; text-align: left;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active { background: linear-gradient(90deg, rgba(91,155,255,.16), transparent); color: var(--accent); }
.nav-item.active .nav-icon { color: var(--accent); }
.nav-icon {
  width: 26px; font-family: var(--mono); font-size: 14px;
  color: var(--text-faint); text-align: center; flex: 0 0 26px;
}
.sidebar-foot {
  padding: 12px 16px; border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 6px; font-family: var(--mono); font-size: 12px;
}
.sidebar-foot a { color: var(--accent); text-decoration: none; }
.version { color: var(--text-faint); }

/* ---------- 顶部栏 ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#topbar {
  height: var(--nav-h); flex: 0 0 var(--nav-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; border-bottom: 1px solid var(--line); background: var(--bg-soft);
}
.module-title { font-weight: 650; font-size: 15px; }
.module-title small { color: var(--text-dim); font-weight: 400; margin-left: 8px; font-size: 12px; }
.topbar-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text-dim); cursor: pointer; font-size: 15px;
}
.icon-btn:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- 内容区 ---------- */
.content { flex: 1; overflow: auto; background: var(--bg); position: relative; padding: 20px; }
.placeholder { height: 100%; display: grid; place-items: center; }
.ph-inner { text-align: center; max-width: 460px; padding: 40px; }
.ph-mark { font-size: 64px; font-family: var(--mono); color: var(--accent); opacity: .5; }
.placeholder h2 { font-weight: 650; margin: 12px 0 8px; }
.placeholder p { color: var(--text-dim); }

/* ---------- 模块通用布局 ---------- */
.module { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px);} to { opacity: 1; transform: none;} }

.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 16px;
  align-items: start;
}
.layout.right-side { grid-template-columns: 1fr 340px; }
.pane {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.pane.full { grid-column: 1 / -1; }

.pane h3 { margin: 0 0 14px; font-size: 13px; letter-spacing: .4px; color: var(--text-dim); text-transform: uppercase; }

.canvas-wrap { position: relative; }
canvas.plot { display: block; width: 100%; height: 100%; }

/* 控件 */
.ctrl { margin-bottom: 14px; }
.ctrl label { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--text-dim); margin-bottom: 6px; }
.ctrl label .val { font-family: var(--mono); color: var(--accent); }
.ctrl select, .ctrl input[type="text"] {
  width: 100%; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font: inherit;
}
input[type="range"] {
  -webkit-appearance: none; width: 100%; height: 5px; border-radius: 3px;
  background: var(--line-2); outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 2px solid #0b0e14;
}
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.chip {
  padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text-dim); font-size: 12.5px; cursor: pointer;
}
.chip:hover { color: var(--text); border-color: var(--line-2); }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.btn {
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font: inherit; cursor: pointer;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }

/* 图例 */
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-dim); margin-top: 8px; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }

/* 状态 / 统计条 */
.statbar { display: flex; gap: 18px; flex-wrap: wrap; padding: 12px 16px; }
.stat { display: flex; flex-direction: column; }
.stat .k { font-size: 11px; color: var(--text-faint); text-transform: uppercase; }
.stat .v { font-family: var(--mono); font-size: 15px; color: var(--accent); }

/* KaTeX 尺寸 */
.katex { font-size: 1.05em; }
.formula-lg { font-family: var(--mono); }
.formula-center { text-align: center; padding: 8px 0; }

/* 推导步骤 */
.steps { display: flex; flex-direction: column; gap: 10px; }
.step {
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2);
  overflow: hidden;
}
.step-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px; cursor: pointer;
  background: transparent; border: 0; color: var(--text-dim); font: inherit; font-weight: 550;
  width: 100%; text-align: left;
}
.step-head:hover { color: var(--text); }
.step-head .arrow { transition: transform .2s; color: var(--text-faint); font-family: var(--mono); }
.step.open .step-head .arrow { transform: rotate(90deg); }
.step-body { display: none; padding: 6px 16px 16px 42px; }
.step.open .step-body { display: block; }
.step-body .desc { color: var(--text-dim); font-size: 13px; margin-bottom: 10px; }

/* 表格 */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; }
.tbl th { background: var(--panel-2); color: var(--text-dim); font-weight: 550; }
.tbl td .katex { font-size: .98em; }

/* 手绘画布 */
.draw-canvas { border: 1px dashed var(--line-2); border-radius: 8px; background: #0a0d14; cursor: crosshair; width: 100%; height: 220px; touch-action: none; }

/* 提示框 */
.hint { font-size: 12px; color: var(--text-faint); margin-top: 8px; line-height: 1.5; }

/* 弹窗 */
.mask { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 50; }
.dialog { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 26px; max-width: 460px; width: 92%; }
.dialog h3 { margin-top: 0; }
.dialog ul { padding-left: 18px; color: var(--text-dim); }
.dialog .muted { color: var(--text-faint); font-size: 12.5px; }
.hidden { display: none !important; }

/* 滚动条 */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }

/* 响应式 */
@media (max-width: 900px) {
  body { overflow: auto; }
  #app { flex-direction: column; height: auto; }
  #sidebar { width: 100%; flex-direction: row; }
  .brand { border: 0; padding: 10px 12px; }
  .brand-name { display: none; }
  #nav { flex-direction: row; overflow-x: auto; padding: 6px; }
  .nav-label { display: none; }
  .nav-icon { width: auto; }
  .layout { grid-template-columns: 1fr; }
}