/* ===== 函数绘图器样式（独立；色板与科研导航站、IPQuery、TextDiff 保持一致） =====
   画布区是本页主角：左侧表达式栏要窄而顺滑，右侧画布占满剩余空间。 */
:root {
  --bg: #f5f6f8;
  --bg-card: #ffffff;
  --bg-hover: #f0f2f5;
  --text: #2c3e50;
  --text-sub: #7f8c9b;
  --border: #e8ebef;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, .1);
  --accent-text: #fff;
  --danger: #e2544d;
  --shadow: 0 2px 8px rgba(30, 40, 60, .06);
  --bar-bg: #f7f8fa;
  --code-bg: #f4f6f9;
  --tag-bg: #eef2f7;
  /* 画布 */
  --canvas-bg: #ffffff;
  --canvas-grid: #e6ecf2;
  --canvas-grid-minor: #f1f5f9;
  --canvas-axis: #64748b;
  --canvas-text: #64748b;
}

html[data-theme="dark"] {
  --bg: #060a17;
  --bg-card: #0d1424;
  --bg-hover: #1a2336;
  --text: #dce3ec;
  --text-sub: #8794a8;
  --border: #1e2a44;
  --accent: #4d94ff;
  --accent-soft: rgba(77, 148, 255, .16);
  --danger: #ff6b64;
  --shadow: 0 2px 10px rgba(0, 0, 0, .5);
  --bar-bg: #0a1120;
  --code-bg: #101a30;
  --tag-bg: #16213a;
  --canvas-bg: #0d1424;
  --canvas-grid: #1d2941;
  --canvas-grid-minor: #141d33;
  --canvas-axis: #8794a8;
  --canvas-text: #8794a8;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background .25s, color .25s;
}

/* ===== 顶栏 ===== */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px; background: var(--bar-bg);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.topbar .back { color: var(--accent); text-decoration: none; font-size: 14px; white-space: nowrap; }
.topbar .back:hover { text-decoration: underline; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--accent-soft); display: flex; align-items: center; justify-content: center; }
.brand-mark img { width: 24px; height: 24px; }
.brand-text h1 { font-size: 17px; line-height: 1.2; }
.brand-text p { font-size: 12px; color: var(--text-sub); line-height: 1.2; }
.spacer { flex: 1; }
.icon-btn {
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 15px; line-height: 1;
}
.icon-btn:hover { background: var(--bg-hover); }
.lang-switch { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.lang-btn {
  border: none; background: var(--bg-card); color: var(--text-sub);
  padding: 6px 10px; font-size: 13px; cursor: pointer;
}
.lang-btn + .lang-btn { border-left: 1px solid var(--border); }
.lang-btn.active { background: var(--accent); color: var(--accent-text); }

/* ===== 主区：左表达式栏 + 右画布 ===== */
.graph-app {
  display: flex; align-items: stretch;
  height: calc(100vh - 57px);
  min-height: 480px;
}
.expr-pane {
  width: 320px; min-width: 260px;
  background: var(--bg-card); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.pane-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px 6px;
}
.pane-head h2 { font-size: 14px; color: var(--text-sub); font-weight: 600; }
.btn {
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
  border-radius: 8px; padding: 6px 14px; cursor: pointer; font-size: 14px;
}
.btn:hover { background: var(--bg-hover); }
.btn-sm { padding: 3px 10px; font-size: 12px; }
.presets {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  padding: 0 14px 10px; border-bottom: 1px solid var(--border);
}
.presets-label { font-size: 12px; color: var(--text-sub); }
.preset-btn {
  border: 1px solid var(--border); background: var(--tag-bg); color: var(--text);
  border-radius: 999px; padding: 2px 10px; font-size: 12px; cursor: pointer;
}
.preset-btn:hover { border-color: var(--accent); color: var(--accent); }

.expr-list { flex: 1; overflow-y: auto; padding: 8px 10px 4px; }
.expr-row { position: relative; padding: 4px 0 10px; border-bottom: 1px solid var(--border); }
.expr-row:last-child { border-bottom: none; }
.expr-line { display: flex; align-items: center; gap: 8px; }
.expr-dot {
  width: 14px; height: 14px; border-radius: 50%;
  border: none; cursor: pointer; flex: none;
  background: var(--row-color, var(--accent));
  transition: opacity .15s;
}
.expr-dot.hidden-row { background: transparent; border: 2px solid var(--row-color, var(--accent)); }
.expr-input {
  flex: 1; min-width: 0;
  border: 1px solid transparent; border-radius: 6px;
  background: var(--code-bg); color: var(--text);
  font-family: ui-monospace, "Cascadia Code", Consolas, "Courier New", monospace;
  font-size: 14px; padding: 7px 9px;
}
.expr-input:focus { outline: none; border-color: var(--accent); background: var(--bg-card); }
.expr-row.row-error .expr-input { border-color: var(--danger); }
.row-del {
  border: none; background: transparent; color: var(--text-sub);
  cursor: pointer; font-size: 13px; padding: 4px 5px; border-radius: 6px; flex: none;
}
.row-del:hover { color: var(--danger); background: var(--bg-hover); }
.row-err { color: var(--danger); font-size: 12px; padding: 2px 8px 0 30px; line-height: 1.4; }

/* 滑块 */
.slider-box { padding: 6px 4px 0 30px; }
.slider-line { display: flex; align-items: center; gap: 8px; }
.slider-name { font-family: ui-monospace, Consolas, monospace; font-size: 14px; color: var(--row-color, var(--accent)); font-weight: 700; }
.slider-val {
  width: 72px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg-card); color: var(--text);
  font-family: ui-monospace, Consolas, monospace; font-size: 13px; padding: 3px 6px; text-align: right;
}
.slider-val:focus { outline: none; border-color: var(--accent); }
.slider-range { flex: 1; accent-color: var(--row-color, var(--accent)); min-width: 40px; }
.slider-meta { display: none; gap: 6px; margin-top: 4px; align-items: center; }
.slider-box.expanded .slider-meta { display: flex; }
.slider-meta input {
  width: 58px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg-card); color: var(--text); font-size: 12px; padding: 2px 5px;
  font-family: ui-monospace, Consolas, monospace;
}
.slider-meta label { font-size: 11px; color: var(--text-sub); }
.slider-toggle {
  border: none; background: transparent; color: var(--text-sub); cursor: pointer;
  font-size: 11px; padding: 0 4px;
}
.slider-toggle:hover { color: var(--accent); }

.add-expr {
  margin: 6px 14px 12px; padding: 8px;
  border: 1px dashed var(--border); border-radius: 8px;
  background: transparent; color: var(--text-sub); cursor: pointer; font-size: 14px;
}
.add-expr:hover { border-color: var(--accent); color: var(--accent); }

/* 画布 */
.graph-main { position: relative; flex: 1; min-width: 0; background: var(--canvas-bg); }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#canvas.dragging { cursor: grabbing; }
.graph-tools {
  position: absolute; right: 14px; bottom: 14px;
  display: flex; flex-direction: column; gap: 6px;
}
.graph-tools button {
  width: 34px; height: 34px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
  font-size: 16px; cursor: pointer; line-height: 1;
}
.graph-tools button:hover { background: var(--bg-hover); }
.copy-link {
  position: absolute; top: 12px; right: 14px;
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
  border-radius: 8px; padding: 5px 12px; font-size: 13px; cursor: pointer;
}
.copy-link:hover { border-color: var(--accent); color: var(--accent); }
.coord {
  position: absolute; top: 12px; left: 14px;
  font-family: ui-monospace, Consolas, monospace; font-size: 13px;
  color: var(--canvas-text); background: var(--canvas-bg);
  border-radius: 6px; padding: 2px 8px; pointer-events: none;
  opacity: .92;
}
.expr-hint {
  position: absolute; bottom: 14px; left: 14px; max-width: min(70%, 520px);
  font-size: 12px; color: var(--canvas-text);
  background: var(--canvas-bg); border-radius: 6px; padding: 2px 8px;
  pointer-events: none; opacity: .92;
}

/* ===== 说明区 ===== */
.doc { max-width: 880px; margin: 0 auto; padding: 28px 20px 40px; }
.doc h2 { font-size: 19px; margin: 26px 0 10px; }
.doc p, .doc li { font-size: 14.5px; color: var(--text); }
.doc li { margin: 6px 0 6px 20px; }
.doc li b { display: inline-block; margin-right: 6px; }
.doc ol { padding-left: 20px; }
.doc ol li { margin: 6px 0; }
.faq dt { font-weight: 700; margin-top: 14px; font-size: 14.5px; }
.faq dd { color: var(--text-sub); font-size: 14px; margin-left: 0; }
/* 站内相关工具（内链区） */
.rel-links { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.rel-links a {
  display: inline-block; padding: 3px 12px; border: 1px solid var(--border); border-radius: 999px;
  color: var(--text); font-size: 13px; text-decoration: none; background: var(--tag-bg);
}
.rel-links a:hover { border-color: var(--accent); color: var(--accent); }

.ver { margin-top: 30px; color: var(--text-sub); font-size: 12.5px; text-align: center; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 36px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg-card);
  padding: 9px 18px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 99;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== 窄屏：表达式栏收成上下结构 ===== */
@media (max-width: 760px) {
  .graph-app { flex-direction: column; height: auto; }
  .expr-pane { width: 100%; min-width: 0; border-right: none; border-bottom: 1px solid var(--border); }
  .expr-list { max-height: 34vh; }
  .graph-main { height: 62vh; min-height: 340px; }
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .topbar .back { font-size: 13px; }
  .expr-hint { display: none; }
}
