/* ============================================
   公共基础样式 - 统一变量 + 通用组件
   ============================================ */

/* ---- 统一变量体系（合并两套命名） ---- */
:root {
  /* 背景色 */
  --bg-primary: #ffffff;
  --bg-secondary: #f6f8fa;
  --bg-tertiary: #f0f2f5;
  --bg-hover: #f8f8f8;
  --bg-active: #f0f0f0;
  --bg-panel: #fafafa;
  --bg-knowledge: #fff;

  /* 文字色 */
  --text-primary: #1f2328;
  --text-secondary: #02080f;
  --text-muted: #8c959f;

  /* 边框 */
  --border-color: #d0d7de;
  --border-light: #e5e7eb;
  --border-dashed: #ccc;

  /* 强调色 */
  --accent-color: #0969da;
  --accent-hover: #0550ae;
  --link-color: #0969da;

  /* 代码/特殊 */
  --code-bg: #f6f8fa;

  /* 阴影 */
  --shadow: 0 1px 2px rgba(31, 35, 40, 0.04), 0 1px 4px rgba(31, 35, 40, 0.04);
  --shadow-lg: 0 8px 24px rgba(31, 35, 40, 0.12);

  /* 字体 */
  --font-sans:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: "SFMono-Regular", "Fira Code", "Consolas", monospace;
  --font-serif: "Times New Roman", "SimSun", "Songti SC", serif;

  /* 尺寸 */
  --radius: 6px;
  --radius-lg: 8px;
  --header-height: 56px;
}

/* ---- 暗色主题 ---- */
[data-theme="dark"] {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-hover: #2a2a2a;
  --bg-active: #333;
  --bg-panel: #222;
  --bg-knowledge: #2a2a2a;

  --text-primary: #e6edf3;
  --text-secondary: #7d8590;
  --text-muted: #6e7681;

  --border-color: #30363d;
  --border-light: #21262d;
  --border-dashed: #555;

  --accent-color: #2f81f7;
  --accent-hover: #58a6ff;
  --link-color: #2f81f7;

  --code-bg: #161b22;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
}

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--link-color);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ============================================
   通用组件：返回顶部按钮（修复hover变黑）
   ============================================ */
.back-to-top {
  position: fixed;
  right: 24px;
  bottom: 80px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: all 0.3s ease;
  z-index: 90;
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.back-to-top:hover {
  background: #000;
  color: #fff;
  border-color: #000;
}

[data-theme="dark"] .back-to-top:hover {
  background: #fff;
  color: #000;
  border-color: #fff;
}

/* ============================================
   通用组件：主题切换按钮
   ============================================ */
.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
  background: var(--bg-secondary);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.theme-toggle:hover {
  background: var(--bg-tertiary);
}

/* ============================================
   通用组件：汉堡菜单按钮
   ============================================ */
.hamburger-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius);
  transition: background 0.2s;
  flex-shrink: 0;
}

.hamburger-btn:hover {
  background: var(--bg-tertiary);
}

.hamburger-line {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 1px;
  transition: all 0.3s ease;
  margin: 2px 0;
}

/* ============================================
   通用组件：加载动画
   ============================================ */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-light);
  border-top-color: var(--accent-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ============================================
   通用组件：代码块
   ============================================ */
code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  padding: 2px 6px;
  background: var(--code-bg);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  color: var(--text-primary);
}

pre {
  margin: 16px 0;
  padding: 16px;
  background: var(--code-bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

pre code {
  padding: 0;
  background: none;
  border: none;
  font-size: 13px;
  line-height: 1.6;
}

/* ============================================
   通用组件：表格
   ============================================ */
.markdown-table {
  border-collapse: collapse;
  width: auto;
  max-width: 100%;
  margin: 8px 0 12px;
  font-size: 0.92em;
  border: 1px solid #000;
}

.markdown-table th,
.markdown-table td {
  border: 1px solid #000;
  padding: 4px 10px;
  text-align: center;
  background-color: transparent !important;
  color: inherit;
}

.markdown-table th {
  font-weight: 600;
  border-bottom: 2px solid #000;
}

[data-theme="dark"] .markdown-table {
  border-color: #fff;
}

[data-theme="dark"] .markdown-table th,
[data-theme="dark"] .markdown-table td {
  border-color: #fff;
}

[data-theme="dark"] .markdown-table th {
  border-bottom-color: #fff;
}

/* ============================================
   通用组件：草稿模式
   ============================================ */
.draft-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.3);
  z-index: 9999;
  display: none;
  cursor: crosshair;
}

.draft-overlay.active {
  display: flex;
}

.draft-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  z-index: 9997;
}

.draft-toolbar {
  position: fixed;
  top: 266px;
  right: 20px;
  width: 52px;
  height: 220px;
  display: none;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  justify-content: center;
  background: #fff;
  padding: 12px 8px;
  border-radius: 4px;
  border: 1px solid #e0e0e0;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  z-index: 100000;
  cursor: move;
  user-select: none;
}

.draft-toolbar.active {
  display: flex;
}

.draft-tool-btn {
  background: #fff;
  color: #666;
  border: 1px solid #ddd;
  width: 36px;
  height: 36px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  padding: 0;
}

.draft-tool-btn:hover {
  background: #f5f5f5;
  border-color: #999;
}

.draft-tool-btn.active {
  background: #333;
  color: #fff;
  border-color: #333;
}

.draft-divider {
  width: 24px;
  height: 1px;
  background: #ddd;
  margin: 4px 0;
}

/* ============================================
   函数绘制弹窗
   ============================================ */
.function-plotter-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.function-plotter-modal {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  width: 90%;
  max-width: 450px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.function-plotter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
}

.function-plotter-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #1f2937;
}

.function-plotter-close {
  background: none;
  border: none;
  font-size: 20px;
  color: #6b7280;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.2s;
}

.function-plotter-close:hover {
  background: #f3f4f6;
  color: #1f2937;
}

.function-plotter-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.function-input-group {
  margin-bottom: 16px;
}

.function-input-group label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 500;
  color: #374151;
}

.function-input-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  font-family: 'Courier New', monospace;
  transition: all 0.2s;
}

.function-input-group input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.function-examples {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.example-label {
  font-size: 13px;
  color: #6b7280;
}

.example-btn {
  padding: 4px 10px;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  font-size: 12px;
  color: #4b5563;
  cursor: pointer;
  transition: all 0.2s;
  font-family: 'Courier New', monospace;
}

.example-btn:hover {
  background: #e5e7eb;
  color: #1f2937;
}

.function-examples {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
  align-items: flex-start;
}

.example-section {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  width: 100%;
  justify-content: flex-start;
}

.example-section-title {
  font-size: 11px;
  color: #9ca3af;
  font-weight: 500;
  width: 75px;
  text-align: right;
  flex-shrink: 0;
}

.function-examples-container {
  margin-top: 10px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  overflow: hidden;
}

.function-examples-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #f9fafb;
  cursor: pointer;
  user-select: none;
}

.function-examples-header:hover {
  background: #f3f4f6;
}

.function-examples-title {
  font-size: 12px;
  color: #4b5563;
  font-weight: 500;
}

.function-examples-toggle {
  font-size: 10px;
  color: #9ca3af;
  transition: transform 0.2s;
}

#customTemplatesButtons {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.function-formula-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.function-formula-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.formula-input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  font-family: 'Courier New', monospace;
  transition: all 0.2s;
}

.formula-input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.formula-remove-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  background: #fee2e2;
  border: 1px solid #fecaca;
  border-radius: 4px;
  color: #dc2626;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.formula-remove-btn:hover {
  background: #fecaca;
}

.formula-add-btn {
  padding: 8px 16px;
  background: black;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  color: #fff;
  cursor: pointer;
  transition: all 0.2s;
}

.formula-add-btn:hover {
  background: black;
  color: #fff;
}

.function-formula-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.function-formula-input-row .formula-input {
  flex: 1;
}

.pending-formulas-container {
  max-height: 120px;
  overflow-y: auto;
  margin-bottom: 8px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 8px;
}

.pending-formula-hint {
  color: #9ca3af;
  font-size: 13px;
  text-align: center;
  padding: 8px;
}

.pending-formula-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid #f3f4f6;
}

.pending-formula-item:last-child {
  border-bottom: none;
}

.pending-formula-color {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.pending-formula-text {
  flex: 1;
  font-family: 'Courier New', monospace;
  font-size: 14px;
  color: #374151;
}

.pending-formula-remove {
  width: 20px;
  height: 20px;
  padding: 0;
  background: transparent;
  border: none;
  color: #9ca3af;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pending-formula-remove:hover {
  color: #dc2626;
}

.function-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.function-zoom-buttons {
  display: flex;
  gap: 8px;
}

.zoom-btn {
  flex: 1;
  padding: 6px 12px;
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 12px;
  color: #374151;
  cursor: pointer;
  transition: all 0.2s;
}

.zoom-btn:hover {
  background: #e5e7eb;
  border-color: #9ca3af;
}

.function-scale-group {
  margin-bottom: 16px;
}

.function-scale-group label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 500;
  color: #374151;
}

.scale-inputs {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.scale-input-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #6b7280;
}

.scale-input-item input {
  width: 60px;
  padding: 6px 8px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 13px;
  text-align: center;
}

.scale-input-item input:focus {
  outline: none;
  border-color: #3b82f6;
}

.function-preview-wrap {
  margin: 12px 0;
}

.function-preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  user-select: none;
}

.function-preview-title {
  font-size: 0.85rem;
  color: #374151;
  font-weight: 500;
}

.function-preview-toggle {
  font-size: 0.75rem;
  color: #6b7280;
}

.function-preview-header:hover {
  background: #e5e7eb;
}

.function-preview {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-top: none;
  border-radius: 0 0 8px 8px;
  padding: 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  display: none;
}

.function-preview canvas {
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  display: block;
}

.function-hint {
  font-size: 12px;
  color: #9ca3af;
  text-align: center;
  margin-top: 4px;
}

.function-plotter-footer {
  display: flex;
  gap: 12px;
  padding: 16px 20px;
  border-top: 1px solid #e5e7eb;
  justify-content: flex-end;
}

.function-plotter-btn {
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.function-plotter-btn.secondary {
  background: #fff;
  border-color: #d1d5db;
  color: #4b5563;
}

.function-plotter-btn.secondary:hover {
  background: #f9fafb;
  border-color: #9ca3af;
}

.function-plotter-btn.primary {
  background: black;
  color: #fff;
}

.function-plotter-btn.primary:hover {
  background: #fff;
  color: black;
}

.no-custom-templates {
  color: #999;
  font-size: 12px;
  font-style: italic;
}

/* 自定义模板样式 */
.custom-template-input {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.custom-template-input input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 12px;
  font-family: 'Courier New', monospace;
}

.custom-template-input input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

.add-template-btn {
  padding: 6px 12px !important;
  background: #10b981 !important;
  border: none !important;
  color: #fff !important;
  font-weight: bold;
}

.add-template-btn:hover {
  background: #059669 !important;
}

#customTemplatesList {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.custom-template-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
}

.custom-template-item:hover {
  background: #fde68a;
}

.custom-template-item .template-name {
  font-family: 'Courier New', monospace;
  color: #92400e;
}

.custom-template-item .template-remove {
  width: 14px;
  height: 14px;
  padding: 0;
  background: transparent;
  border: none;
  color: #b45309;
  font-size: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.custom-template-item .template-remove:hover {
  background: #f59e0b;
  color: #fff;
}

.function-plot-canvas {
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* ============================================
   通用组件：按钮（统一风格）
   ============================================ */
.btn {
  padding: 6px 12px;
  border: 1px solid var(--text-primary);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.3s;
  font-family: inherit;
}

.btn:hover {
  background: var(--text-primary);
  color: var(--bg-primary);
}

/* ============================================
   通用：滚动条
   ============================================ */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-hover);
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ============================================
   移动端通用适配
   ============================================ */
@media screen and (max-width: 768px) {
  .hamburger-btn {
    display: flex;
  }

  .back-to-top {
    right: 16px;
    bottom: 16px;
    width: 40px;
    height: 40px;
    font-size: 16px;
  }

  .theme-toggle {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }
}

/* ============================================
   打印样式
   ============================================ */
@media print {
  .back-to-top,
  .theme-toggle,
  .hamburger-btn,
  .draft-toolbar,
  .draft-overlay {
    display: none !important;
  }
}

/* ============================================
   函数绘制弹窗 - 暗色主题
   ============================================ */
[data-theme="dark"] .function-plotter-modal {
  background: #1e1e1e;
  border: 1px solid #333;
}

[data-theme="dark"] .function-plotter-header {
  border-bottom-color: #333;
}

[data-theme="dark"] .function-plotter-header h3 {
  color: #e5e7eb;
}

[data-theme="dark"] .function-plotter-close {
  color: #9ca3af;
}

[data-theme="dark"] .function-plotter-close:hover {
  background: #2d2d2d;
  color: #e5e7eb;
}

[data-theme="dark"] .function-input-group label {
  color: #d1d5db;
}

[data-theme="dark"] .function-input-group input {
  background: #2d2d2d;
  border-color: #404040;
  color: #e5e7eb;
}

[data-theme="dark"] .function-input-group input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

[data-theme="dark"] .example-label {
  color: #9ca3af;
}

[data-theme="dark"] .example-btn {
  background: #2d2d2d;
  border-color: #404040;
  color: #d1d5db;
}

[data-theme="dark"] .example-btn:hover {
  background: #404040;
  color: #e5e7eb;
}

[data-theme="dark"] .formula-input {
  background: #2d2d2d;
  border-color: #404040;
  color: #e5e7eb;
}

[data-theme="dark"] .formula-input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

[data-theme="dark"] .formula-remove-btn {
  background: #7f1d1d;
  border-color: #991b1b;
  color: #fca5a5;
}

[data-theme="dark"] .formula-remove-btn:hover {
  background: #991b1b;
}

[data-theme="dark"] .formula-add-btn {
  background: #3b82f6;
  border: none;
  color: #fff;
}

[data-theme="dark"] .formula-add-btn:hover {
  background: #2563eb;
}

[data-theme="dark"] .pending-formulas-container {
  border-color: #404040;
  background: #2d2d2d;
}

[data-theme="dark"] .pending-formula-hint {
  color: #6b7280;
}

[data-theme="dark"] .pending-formula-item {
  border-bottom-color: #404040;
}

[data-theme="dark"] .pending-formula-text {
  color: #e5e7eb;
}

[data-theme="dark"] .pending-formula-remove {
  color: #6b7280;
}

[data-theme="dark"] .pending-formula-remove:hover {
  color: #fca5a5;
}

[data-theme="dark"] .function-controls {
  background: #1f2937;
}

[data-theme="dark"] .zoom-btn {
  background: #374151;
  border-color: #4b5563;
  color: #d1d5db;
}

[data-theme="dark"] .zoom-btn:hover {
  background: #4b5563;
  border-color: #6b7280;
}

[data-theme="dark"] .function-scale-group label {
  color: #d1d5db;
}

[data-theme="dark"] .scale-input-item {
  color: #9ca3af;
}

[data-theme="dark"] .scale-input-item input {
  background: #2d2d2d;
  border-color: #404040;
  color: #e5e7eb;
}

[data-theme="dark"] .scale-input-item input:focus {
  border-color: #3b82f6;
}

[data-theme="dark"] .function-preview {
  background: #1a1a1a;
  border-color: #333;
}

[data-theme="dark"] .function-preview-header {
  background: #374151;
  border-color: #4b5563;
}

[data-theme="dark"] .function-preview-header:hover {
  background: #4b5563;
}

[data-theme="dark"] .function-preview-title {
  color: #d1d5db;
}

[data-theme="dark"] .function-preview-toggle {
  color: #9ca3af;
}

[data-theme="dark"] .function-preview {
  background: #1f2937;
  border-color: #374151;
}

[data-theme="dark"] .function-preview canvas {
  background: #2d2d2d;
  border-color: #404040;
}

[data-theme="dark"] .function-plotter-footer {
  border-top-color: #333;
}

[data-theme="dark"] .function-plotter-btn.secondary {
  background: #2d2d2d;
  border-color: #404040;
  color: #d1d5db;
}

[data-theme="dark"] .function-plotter-btn.secondary:hover {
  background: #404040;
  border-color: #606060;
}

[data-theme="dark"] .function-plot-canvas {
  background: #2d2d2d;
  border-color: #404040;
}

/* 常用公式贴纸弹窗样式 */
.formula-sticker-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 10000;
}

.formula-sticker-modal {
  background: #fff;
  border-radius: 12px;
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.formula-sticker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #eee;
}

.formula-sticker-header h3 {
  margin: 0;
  font-size: 1.1rem;
  color: #1f2937;
}

.formula-sticker-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: #6b7280;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.formula-sticker-close:hover {
  background: #f3f4f6;
  color: #374151;
}

.formula-sticker-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.formula-sticker-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 20px;
}

.formula-sticker-item {
  display: flex;
  align-items: center;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px;
  gap: 12px;
}

.formula-sticker-content {
  flex: 1;
  cursor: pointer;
}

.formula-sticker-content:hover {
  text-decoration: underline;
}

.formula-sticker-name {
  font-size: 0.85rem;
  color: #374151;
  font-weight: 500;
  margin-bottom: 4px;
}

.formula-sticker-latex {
  font-size: 1rem;
  color: #1f2937;
}

.formula-sticker-delete {
  background: none;
  border: none;
  color: #9ca3af;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

.formula-sticker-delete:hover {
  background: #fee2e2;
  color: #dc3545;
}

.formula-sticker-add {
  background: #f3f4f6;
  border-radius: 8px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.formula-add-title {
  font-size: 0.9rem;
  color: #374151;
  font-weight: 500;
}

.formula-sticker-add input {
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.9rem;
  outline: none;
}

.formula-sticker-add input:focus {
  border-color: #3b82f6;
  outline: none;
}

.formula-sticker-footer {
  padding: 16px 20px;
  border-top: 1px solid #eee;
  display: flex;
  justify-content: flex-end;
}

.formula-sticker-btn {
  padding: 10px 24px;
  background: #3b82f6;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
}

.formula-sticker-btn:hover {
  background: #2563eb;
}

/* 草稿模式中的公式贴纸 */
.formula-sticker {
  cursor: grab;
}

.formula-sticker-inner {
  text-align: center;
}

/* 解方程弹窗样式 */
.equation-solver-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.equation-solver-modal {
  background: #fff;
  border-radius: 12px;
  width: 450px;
  max-width: 90vw;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.equation-solver-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
}

.equation-solver-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #111827;
}

.equation-solver-close {
  background: none;
  border: none;
  font-size: 20px;
  color: #6b7280;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.equation-solver-close:hover {
  color: #374151;
}

.equation-solver-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.equation-input-group textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  font-family: 'Courier New', monospace;
  resize: vertical;
  box-sizing: border-box;
}

.equation-input-group textarea:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.equation-examples {
  margin-top: 16px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
}

.equation-examples-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #f9fafb;
  cursor: pointer;
  user-select: none;
}

.equation-examples-header:hover {
  background: #f3f4f6;
}

.equation-examples-title {
  font-size: 13px;
  color: #4b5563;
  font-weight: 500;
}

.equation-examples-toggle {
  font-size: 11px;
  color: #9ca3af;
}

.equation-examples-content {
  display: none;
  padding: 12px;
  gap: 8px;
  flex-wrap: wrap;
  border-top: 1px solid #e5e7eb;
}

.equation-example-btn {
  padding: 6px 12px;
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 12px;
  color: #374151;
  cursor: pointer;
  transition: all 0.2s;
}

.equation-example-btn:hover {
  background: #e5e7eb;
  border-color: #9ca3af;
}

.equation-result {
  margin-top: 16px;
}

.equation-result-item {
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 8px;
  padding: 14px;
}

.equation-input-display {
  margin-bottom: 10px;
  color: #475569;
  font-family: 'Courier New', monospace;
  font-size: 13px;
}

.equation-lines {
  margin-top: 4px;
}

.equation-solution-display {
  border-top: 1px dashed #7dd3fc;
  padding-top: 10px;
  color: #0369a1;
}

.equation-solution-item {
  display: inline-block;
  margin-right: 16px;
  font-weight: 600;
  font-family: 'Courier New', monospace;
}

.equation-solver-footer {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid #e5e7eb;
  justify-content: flex-end;
}

.equation-solver-btn {
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.equation-solver-btn.secondary {
  background: #fff;
  border-color: #d1d5db;
  color: #4b5563;
}

.equation-solver-btn.secondary:hover {
  background: #f9fafb;
  border-color: #9ca3af;
}

.equation-solver-btn.primary {
  background: black;
  color: #fff;
}

.equation-solver-btn.primary:hover {
  background: #fff;
  color: black;
}

/* 方程结果显示容器 */
.equation-result-container {
  background: rgba(255, 255, 255, 0.95);
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  font-family: 'Courier New', monospace;
  line-height: 1.6;
  max-width: 350px;
}

/* 暗色模式支持 */
[data-theme="dark"] .equation-solver-modal {
  background: #1f2937;
}

[data-theme="dark"] .equation-solver-header {
  background: #374151;
  border-color: #4b5563;
}

[data-theme="dark"] .equation-solver-header h3 {
  color: #f9fafb;
}

[data-theme="dark"] .equation-solver-close {
  color: #9ca3af;
}

[data-theme="dark"] .equation-input-group textarea {
  background: #374151;
  border-color: #4b5563;
  color: #f9fafb;
}

[data-theme="dark"] .equation-examples {
  border-color: #4b5563;
}

[data-theme="dark"] .equation-examples-header {
  background: #374151;
}

[data-theme="dark"] .equation-examples-header:hover {
  background: #4b5563;
}

[data-theme="dark"] .equation-examples-title,
[data-theme="dark"] .equation-examples-toggle {
  color: #d1d5db;
}

[data-theme="dark"] .equation-examples-content {
  background: #374151;
  border-color: #4b5563;
}

[data-theme="dark"] .equation-example-btn {
  background: #4b5563;
  border-color: #6b7280;
  color: #e5e7eb;
}

[data-theme="dark"] .equation-example-btn:hover {
  background: #6b7280;
}

[data-theme="dark"] .equation-result-item {
  background: #1e3a5f;
  border-color: #3b82f6;
}

[data-theme="dark"] .equation-input-display {
  color: #cbd5e1;
}

[data-theme="dark"] .equation-solution-display {
  border-color: #60a5fa;
  color: #93c5fd;
}

[data-theme="dark"] .equation-solver-footer {
  border-color: #4b5563;
}

[data-theme="dark"] .equation-solver-btn.secondary {
  background: #374151;
  border-color: #4b5563;
  color: #d1d5db;
}

[data-theme="dark"] .equation-result-container {
  background: rgba(31, 41, 55, 0.95);
  color: #f9fafb;
}
