:root {
  --accent: #2563eb;
  --bg: #eef2f7;
  --panel: #ffffff;
  --line: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --danger: #dc2626;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---------- 顶栏 ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  background: linear-gradient(120deg, #1e3a8a, #2563eb 60%, #3b82f6);
  color: #fff;
  box-shadow: 0 1px 6px rgba(30, 58, 138, .25);
}

.brand { display: flex; align-items: center; gap: 12px; }

.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .16);
  font-size: 26px;
  font-weight: 700;
}

.app-header h1 { margin: 0; font-size: 18px; }
.app-header p { margin: 2px 0 0; font-size: 12px; opacity: .85; }

/* ---------- 布局 ---------- */
.layout { flex: 1; display: flex; min-height: 0; }

.panel {
  width: 372px;
  min-width: 300px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------- 卡片 ---------- */
.card {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}

.card h2 { margin: 0 0 8px; font-size: 14px; color: #334155; }

.sec-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sec-head h2 { margin: 0; }
.sec-actions { display: flex; gap: 6px; }

/* ---------- 按钮 ---------- */
.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}

.btn:hover { border-color: #c7d2fe; background: #eef2ff; }
.btn:active { transform: translateY(1px); }

.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #1d4ed8; border-color: #1d4ed8; }
.btn-accent { background: #059669; border-color: #059669; color: #fff; }
.btn-accent:hover { background: #047857; border-color: #047857; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: #eef2ff; color: #1e40af; }

/* ---------- 列表行 ---------- */
.row-list { display: flex; flex-direction: column; gap: 8px; }

.row {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}

.func-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.func-row .err { flex-basis: 100%; color: var(--danger); font-size: 12px; word-break: break-all; }

.swatch {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  background: #fff;
  flex: none;
}

.expr-input {
  flex: 1;
  min-width: 120px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Courier New", monospace;
}

.expr-input:focus, .range-label:focus, .range-fields input:focus {
  outline: 2px solid #bfdbfe;
  border-color: var(--accent);
}

.icon-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.icon-btn:hover { background: #f1f5f9; }
.icon-btn.danger:hover { background: #fee2e2; border-color: #fca5a5; color: var(--danger); }

/* ---------- 区间行 ---------- */
.range-row { display: flex; flex-direction: column; gap: 6px; }
.range-top { display: flex; align-items: center; gap: 6px; }

.range-label {
  flex: 1;
  min-width: 80px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
}

.range-fields {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.range-fields input {
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
  width: 100%;
  min-width: 0;
}

.range-row .err { color: var(--danger); font-size: 12px; }

/* ---------- 常用函数 ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}

.chip:hover { border-color: #93c5fd; background: #eff6ff; color: #1d4ed8; }

/* ---------- 动点与连线 ---------- */
.sel {
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
  background: #fff;
  min-width: 0;
}

.pt-row, .line-row { display: flex; flex-direction: column; gap: 6px; }

.pt-top, .line-top { display: flex; align-items: center; gap: 6px; }

.pt-name {
  flex: 1;
  min-width: 60px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
}

.pt-top .sel { flex: 1; min-width: 60px; }

.pt-fields { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }

.pt-fields input, .pt-fields .sel {
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
  width: 100%;
  min-width: 0;
}

.pt-fields .sel.span2 { grid-column: span 2; }

.pt-custom {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.pt-extra { display: flex; align-items: center; gap: 8px; }

.live {
  margin-left: auto;
  font-size: 11.5px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: nowrap;
}

.arrow { color: var(--muted); font-size: 13px; }

.line-top .sel { flex: 1; min-width: 40px; }

.line-live {
  font-size: 12px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.pt-row .err, .line-row .err { color: var(--danger); font-size: 12px; word-break: break-all; }

/* ---------- 交点 ---------- */
.cand-toggle { margin-bottom: 8px; }

.in-row { display: flex; align-items: center; gap: 6px; }

.in-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
  color: #334155;
}

.in-coords {
  font-size: 11.5px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: nowrap;
}

/* ---------- 参数滑块 ---------- */
.param-row { display: flex; flex-direction: column; gap: 6px; }

.param-top { display: flex; align-items: center; gap: 6px; }

.param-name {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 14px;
  font-weight: 600;
  color: #1d4ed8;
  min-width: 18px;
  text-align: center;
}

.param-val {
  width: 64px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.param-range {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
}

.param-minmax {
  width: 52px;
  padding: 4px 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 11px;
}

.param-slider {
  width: 100%;
  accent-color: var(--accent);
}

/* ---------- 不等式解集 ---------- */
.ineq-row { display: flex; align-items: center; gap: 6px; }

.ineq-row .sel { flex: 1; min-width: 30px; }
.ineq-row .op-sel { flex: 0 0 44px; text-align: center; }

.qinfo {
  flex-basis: 100%;
  font-size: 11.5px;
  line-height: 1.5;
  color: #1d4ed8;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: nowrap;          /* 永不换行：滑块拖动时高度恒定，左栏不抖动 */
  overflow: hidden;
  text-overflow: ellipsis;
}

.linfo {
  flex-basis: 100%;
  font-size: 11.5px;
  line-height: 1.5;
  color: #0d9488;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- 播放条 ---------- */
.playbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.rate-sel {
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
  background: #fff;
}

.anim-time {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12.5px;
  color: var(--muted);
  min-width: 84px;
}

.playbar-hint { color: #94a3b8; font-size: 12px; }

#btnPlay.playing { background: #d97706; border-color: #d97706; }
#btnPlay.playing:hover { background: #b45309; border-color: #b45309; }

/* ---------- 帮助 ---------- */
.help { font-size: 12.5px; color: #475569; line-height: 1.7; }
.help summary { cursor: pointer; font-weight: 600; color: #334155; }
.help ul { margin: 8px 0 0; padding-left: 18px; }
.help code { background: #eef2ff; color: #3730a3; padding: 1px 5px; border-radius: 4px; font-size: 11.5px; }

/* ---------- 绘图区 ---------- */
.plot-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.toolbar input[type="number"] {
  width: 84px;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
}

.toolbar input[type="number"]:focus { outline: 2px solid #bfdbfe; border-color: var(--accent); }

.tl { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.tl-sep { color: var(--muted); }
.spacer { flex: 1; }

.chk { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); cursor: pointer; user-select: none; }

#canvasWrap {
  flex: 1;
  position: relative;
  min-height: 0;
  margin: 12px;
}

#plotCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(15, 23, 42, .08);
  touch-action: none;
  cursor: crosshair;
}

#statusBar {
  padding: 6px 14px;
  font-size: 12px;
  color: var(--muted);
  background: #fff;
  border-top: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hint { color: #94a3b8; font-size: 12px; padding: 4px 2px; }

/* ---------- 响应式 ---------- */
.mobile-only { display: none; }

@media (max-width: 900px) {
  .mobile-only { display: inline-flex; align-items: center; }
  /* 整个页面可上下滚动 */
  html, body { height: auto; min-height: 100%; }
  body { overflow-x: hidden; overflow-y: auto; }
  .layout { flex-direction: column; }
  .panel {
    width: auto;
    max-height: none;             /* 面板自然展开，随页面滚动 */
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .plot-area { flex: none; }      /* 绘图区不再拉伸占满剩余空间 */
  /* 折叠面板：画布直接置顶 */
  body.panel-collapsed .panel { display: none; }
  body.panel-collapsed .playbar-hint { display: none; }

  .app-header { padding: 8px 12px; gap: 8px; }
  .app-header h1 { font-size: 16px; }
  .app-header p { display: none; }          /* 手机端隐藏副标题，省空间 */
  .logo { width: 34px; height: 34px; font-size: 20px; }

  /* 防止双击缩放、双击时浏览器误触 */
  body { touch-action: manipulation; }
  #plotCanvas { touch-action: none; }        /* 画布手势完全交给应用（捏合/拖动） */

  /* 触控目标加大 */
  .btn, .icon-btn, .chip { min-height: 40px; }
  .btn-sm { min-height: 36px; }
  .sel { min-height: 38px; }

  /* 输入框 16px：避免 iOS 聚焦时自动放大页面 */
  .toolbar input[type="number"],
  .expr-input, .range-label, .range-fields input,
  .pt-name, .pt-fields input, .pt-custom input,
  .param-val, .param-minmax, .rate-sel {
    font-size: 16px;
  }
  .toolbar input[type="number"] { width: 64px; }

  .toolbar, .playbar { gap: 6px; padding: 8px 10px; }
  /* 画布竖着固定高度，不再被压缩 */
  #canvasWrap { flex: none; height: 62vh; min-height: 300px; margin: 8px; }
  #statusBar { font-size: 11px; padding: 5px 10px; }

  .panel { padding: 10px; gap: 10px; }
  .card { padding: 10px; }
}
