/* ===== 基础重置与全局 ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #fafaf8;
  --surface: #ffffff;
  --text: #333333;
  --text-muted: #888888;
  --border: #dcdcdc;
  --grid: #e8e8e8;
  --axis: #555555;
  --curve: #2563eb;
  --error: #dc2626;
  --focus-ring: #2563eb;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  -webkit-font-smoothing: antialiased;
}

/* ===== 容器 ===== */
.container {
  width: 100%;
  max-width: 860px;
  padding: 32px 24px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ===== 标题 ===== */
.header {
  text-align: center;
  margin-bottom: 28px;
}

.header h1 {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.3px;
  color: var(--text);
}

.subtitle {
  margin-top: 6px;
  font-size: 15px;
  color: var(--text-muted);
}

/* ===== 公式回显区 ===== */
.display-area {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-height: 48px;
  padding: 10px 16px;
  margin-bottom: 8px;
  font-size: 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
}

.display-label {
  color: var(--text-muted);
  font-style: italic;
  white-space: nowrap;
}

.formula-render {
  color: var(--text);
  overflow-x: auto;
  white-space: nowrap;
}

/* KaTeX 覆盖 */
.formula-render .katex {
  font-size: 1.15em;
}

/* ===== 输入区 ===== */
.input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-bottom: 6px;
}

.input-label {
  font-size: 20px;
  font-style: italic;
  color: var(--text-muted);
  white-space: nowrap;
  user-select: none;
}

.expr-input {
  flex: 1;
  font-size: 18px;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s;
}

.expr-input:focus {
  border-color: var(--focus-ring);
}

.expr-input::placeholder {
  color: #c0c0c0;
}

/* ===== 错误提示 ===== */
.error-msg {
  display: none;
  width: 100%;
  padding: 8px 14px;
  margin-bottom: 8px;
  font-size: 14px;
  color: var(--error);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 6px;
}

.error-msg.visible {
  display: block;
}

/* ===== 绘图区 ===== */
.canvas-wrapper {
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 70vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

#graph-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ===== 页脚 ===== */
.footer {
  margin-top: 24px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.8;
}

.footer code {
  display: inline-block;
  padding: 2px 8px;
  margin: 2px 3px;
  font-size: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  cursor: pointer;
  transition: border-color 0.15s;
}

.footer code:hover {
  border-color: var(--focus-ring);
}

/* ===== 响应式 ===== */
@media (max-width: 640px) {
  .container {
    padding: 20px 12px 32px;
  }

  .header h1 {
    font-size: 22px;
  }

  .display-area {
    font-size: 17px;
    min-height: 40px;
    padding: 8px 12px;
  }

  .expr-input {
    font-size: 16px;
    padding: 8px 12px;
  }

  .input-label {
    font-size: 17px;
  }

  .canvas-wrapper {
    aspect-ratio: 1 / 1;
  }
}
