* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary-color: #2563eb;
  --primary-dark: #1e40af;
  --primary-light: #3b82f6;
  --bg-color: #f8fafc;
  --sidebar-bg: #ffffff;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --border-color: #e2e8f0;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei",
    sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

.container {
  display: flex;
  height: 100vh;
}

/* 左侧侧边栏 */
.sidebar {
  width: 260px;
  background-color: var(--sidebar-bg);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-color);
  background: linear-gradient(
    135deg,
    var(--primary-color),
    var(--primary-dark)
  );
  color: white;
}

.sidebar-header.brand {
  padding: 20px 24px;
  min-height: 70px;
  display: flex;
  align-items: flex-start;
  flex-direction: row;
}

.brand-name {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 1px;
  line-height: 1.2;
  display: flex;
  align-items: center;
}

.brand-en {
  font-size: 16px;
  font-weight: 500;
  opacity: 0.8;
  margin-left: 4px;
}

.brand-slogan {
  font-size: 13px;
  opacity: 0.7;
  margin-top: 4px;
  letter-spacing: 0.5px;
}

.sidebar-header h2 {
  font-size: 24px;
  font-weight: 600;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
}

/* 分类样式 */
.category {
  margin-bottom: 8px;
}

.category-header {
  padding: 12px 20px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 500;
  color: var(--text-primary);
  transition: background-color 0.2s;
  user-select: none;
}

.category-header:hover {
  background-color: #f1f5f9;
}

.category-header.active {
  background-color: #eff6ff;
  color: var(--primary-color);
}

.category-icon {
  font-size: 12px;
  transition: transform 0.3s;
}

.category-icon.expanded {
  transform: rotate(90deg);
}

.category-items {
  display: none;
  background-color: #f8fafc;
}

.category-items.expanded {
  display: block;
}

.model-item {
  padding: 10px 20px 10px 40px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s;
  border-left: 3px solid transparent;
}

.model-item:hover {
  background-color: #f1f5f9;
  color: var(--text-primary);
  border-left-color: var(--primary-light);
}

.model-item.active {
  background-color: #eff6ff;
  color: var(--primary-color);
  border-left-color: var(--primary-color);
  font-weight: 500;
}

/* 右侧主操作区 */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 顶部工具栏 */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  height: 64px;
  background: white;
  border-bottom: 1px solid #e2e8f0;
}

.toolbar-left {
  display: flex;
  align-items: center;
}

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

/* VIP 按钮 */
.vip-btn {
  padding: 10px 20px;
  background: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
  transition: all 0.3s ease;
}

.vip-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.vip-btn:active {
  transform: translateY(0);
}

/* 脉冲动画效果 */
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.9;
    transform: scale(1.02);
  }
}

.pulse-effect {
  animation: pulse 2s ease-in-out infinite;
}

/* VIP 徽章 */
.vip-badge {
  padding: 8px 16px;
  background: #ffffff;
  color: var(--primary-color);
  border: 2px solid var(--primary-color);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.15);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* 兼容旧样式 */
.top-bar {
  padding: 20px 30px;
  background-color: var(--sidebar-bg);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow);
}

.current-model-title {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
}

/* 主内容行：画布和名师点拨左右排布 */
.content-row {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* Canvas 容器 */
.canvas-container {
  flex: 2 1 0%;
  position: relative;
  background-color: #ffffff;
  overflow: hidden;
  min-width: 45%;
}

#geometryCanvas {
  width: 100%;
  height: 100%;
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
}

#drawingCanvas {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 10;
}

/* 右上角悬浮工具栏 */
.canvas-toolbar {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 100;
}

.tool-btn {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.tool-btn svg {
  width: 24px;
  height: 24px;
  transition: all 0.3s ease;
}

.tool-btn::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.4),
    rgba(255, 255, 255, 0.1)
  );
  opacity: 0;
  transition: opacity 0.3s;
}

.tool-btn:hover::before {
  opacity: 1;
}

.tool-btn:hover {
  background: rgba(255, 255, 255, 0.85);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
  border-color: rgba(255, 255, 255, 0.5);
}

.tool-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.tool-btn.active {
  background: rgba(37, 99, 235, 0.2);
  border-color: rgba(37, 99, 235, 0.4);
  color: var(--primary-color);
}

.tool-btn.active::before {
  background: linear-gradient(
    135deg,
    rgba(37, 99, 235, 0.3),
    rgba(37, 99, 235, 0.1)
  );
  opacity: 1;
}

/* 辅助线和绘图按钮激活时的明显颜色变化 */
#auxiliaryBtn.active,
#drawBtn.active {
  background: rgba(37, 99, 235, 0.25);
  border-color: var(--primary-color);
  color: var(--primary-color);
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.3);
}

#auxiliaryBtn.active svg,
#drawBtn.active svg {
  color: var(--primary-color);
  transform: scale(1.1);
}

#auxiliaryBtn.active::before,
#drawBtn.active::before {
  background: linear-gradient(
    135deg,
    rgba(37, 99, 235, 0.4),
    rgba(37, 99, 235, 0.2)
  );
  opacity: 1;
}

/* 右侧信息卡片 */
.info-card {
  flex: 1 1 0%;
  background-color: var(--sidebar-bg);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  box-shadow: -2px 0 4px rgba(0, 0, 0, 0.05);
  min-width: 240px;
  max-width: 55%;
  overflow: hidden;
}

.split-divider {
  width: 12px;
  cursor: col-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #e2e8f0, #cbd5f5);
  border-left: 1px solid #cbd5e1;
  border-right: 1px solid #cbd5e1;
  box-shadow: inset 0 0 4px rgba(15, 23, 42, 0.15);
  flex-shrink: 0;
}

.split-divider::after {
  content: "";
  width: 4px;
  height: 40px;
  border-radius: 4px;
  background: #94a3b8;
  opacity: 0.8;
}

body.resizing,
body.resizing * {
  cursor: col-resize !important;
  user-select: none;
}

.info-card-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-color);
  background-color: #f8fafc;
}

.info-card-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--primary-color);
}

.info-card-content {
  flex: 1;
  padding: 15px 20px;
  overflow-y: auto;
  color: var(--text-secondary);
  line-height: 1.6;
  min-height: 0;
  /* 优化底部空间，减少不必要的空白 */
  padding-bottom: 15px;
  display: flex;
  flex-direction: column;
}

/* 确保内容区域内的最后一个元素没有多余的margin */
.info-card-content > *:last-child {
  margin-bottom: 0 !important;
}

/* 优化section之间的间距 */
.info-card-content section {
  margin-bottom: 18px;
}

.info-card-content section:last-child {
  margin-bottom: 0;
}

.info-card-content::-webkit-scrollbar {
  width: 6px;
}

.info-card-content::-webkit-scrollbar-track {
  background: #f1f5f9;
}

.info-card-content::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

.info-card-content::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* MathJax 数学公式样式 */
.info-card-content .MathJax {
  font-size: 1em !important;
  line-height: 1.6 !important;
}

.info-card-content .MathJax_Display {
  margin: 1em 0 !important;
  text-align: center !important;
}

.info-card-content mjx-container {
  display: inline-block;
  margin: 0 0.2em;
  vertical-align: middle;
}

.info-card-content mjx-container[display="true"] {
  display: block;
  margin: 1em auto;
  text-align: center;
}

/* 确保数学公式在深色背景下可见 */
.info-card-content mjx-container[jax="CHTML"] {
  color: var(--text-secondary);
}

/* Markdown 渲染样式增强 */
.info-card-content strong {
  font-weight: 600;
  color: var(--text-primary);
}

.info-card-content em {
  font-style: italic;
  color: var(--text-secondary);
}

.info-card-content code {
  background-color: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "Courier New", monospace;
  font-size: 0.9em;
}

/* 滚动条样式（侧边栏） */
.sidebar-nav::-webkit-scrollbar {
  width: 6px;
}

.sidebar-nav::-webkit-scrollbar-track {
  background: #f1f5f9;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* 激活码弹窗样式 */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.modal-overlay.show {
  display: flex;
}

.modal-content {
  background-color: white;
  border-radius: 12px;
  width: 90%;
  max-width: 450px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 28px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s;
}

.modal-close:hover {
  background-color: #f1f5f9;
  color: var(--text-primary);
}

.modal-body {
  padding: 24px;
}

.modal-description {
  color: var(--text-secondary);
  margin-bottom: 16px;
  font-size: 14px;
}

.modal-input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 16px;
  transition: border-color 0.2s;
  box-sizing: border-box;
}

.modal-input:focus {
  outline: none;
  border-color: var(--primary-color);
}

.modal-error {
  color: #ef4444;
  font-size: 14px;
  margin-top: 8px;
  min-height: 20px;
  display: none;
}

.modal-error.show {
  display: block;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.modal-btn {
  padding: 10px 24px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.modal-btn-primary {
  background-color: var(--primary-color);
  color: white;
}

.modal-btn-primary:hover {
  background-color: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(37, 99, 235, 0.3);
}

.modal-btn-primary:active {
  transform: translateY(0);
}

/* ============================================
   移动端响应式样式
   ============================================ */

/* 菜单按钮（移动端） */
.menu-toggle-btn {
  display: none;
  position: fixed;
  top: 60px; /* 调整位置，避免与标题重叠 */
  left: 16px;
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.95);
  border: none;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1001;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  touch-action: manipulation;
}

.menu-toggle-btn:active {
  transform: scale(0.95);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.menu-toggle-btn svg {
  color: var(--primary-color);
  width: 24px;
  height: 24px;
}

/* 侧边栏遮罩层 */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s;
}

.sidebar-overlay.active {
  display: block;
  opacity: 1;
}

/* 移动端样式（最大宽度 768px） */
@media (max-width: 768px) {
  /* 菜单按钮显示 */
  .menu-toggle-btn {
    display: flex;
  }

  /* 侧边栏：固定定位，默认隐藏 */
  .sidebar {
    position: fixed;
    left: -260px;
    top: 0;
    bottom: 0;
    z-index: 1000;
    transition: left 0.3s ease-out;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
    height: 100vh;
  }

  .sidebar.open {
    left: 0;
  }

  /* 主内容区域：全宽显示 */
  .main-content {
    width: 100%;
    margin-left: 0;
  }

  /* 顶部工具栏调整 */
  .toolbar {
    padding: 0 16px;
    height: 56px;
    flex-wrap: wrap;
  }

  .toolbar-left {
    flex: 1;
    min-width: 0;
  }

  .toolbar-left span {
    font-size: 12px !important;
  }

  #currentModelTitle {
    font-size: 16px !important;
  }

  .toolbar-right {
    gap: 8px;
  }

  .vip-btn {
    padding: 8px 14px;
    font-size: 12px;
  }

  .vip-badge {
    padding: 6px 12px;
    font-size: 11px;
  }

  /* 兼容旧样式 */
  .top-bar {
    padding: 16px 20px;
  }

  .current-model-title {
    font-size: 18px;
  }

  /* 内容区域：改为上下堆叠 */
  .content-row {
    flex-direction: column !important;
    display: flex !important;
  }

  /* Canvas 容器：1:2比例，画布占1份（1/3） */
  .canvas-container {
    width: 100% !important;
    flex: 1 1 33.333% !important; /* grow: 1, shrink: 1, basis: 33.333% */
    min-height: 0 !important;
    max-height: none !important;
    height: auto !important;
    border-bottom: 1px solid var(--border-color);
  }

  /* 隐藏分隔条 */
  .split-divider {
    display: none !important;
  }

  /* 信息卡片：1:2比例，名师点拨占2份（2/3） */
  .info-card {
    width: 100% !important;
    max-width: 100% !important;
    flex: 2 1 66.667% !important; /* grow: 2, shrink: 1, basis: 66.667% */
    min-height: 0 !important;
    max-height: none !important;
    height: auto !important;
    border-left: none !important;
    border-top: 1px solid var(--border-color) !important; /* 顶部边框明显区分 */
    overflow-y: auto !important;
    display: flex !important;
    flex-direction: column !important;
    box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.05) !important; /* 添加顶部阴影，区分上下区域 */
  }

  .info-card-header {
    padding: 10px 16px;
    flex-shrink: 0;
  }

  .info-card-header h3 {
    font-size: 14px;
  }

  .info-card-content {
    padding: 12px 16px;
    font-size: 13px;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    /* 减少底部空白，让内容紧贴底部 */
    padding-bottom: 8px;
    /* 确保内容区域充分利用空间 */
    display: flex;
    flex-direction: column;
  }

  /* 确保内容区域内的最后一个元素没有多余的margin */
  .info-card-content > *:last-child {
    margin-bottom: 0 !important;
  }

  /* 优化section之间的间距 */
  .info-card-content section {
    margin-bottom: 16px;
  }

  .info-card-content section:last-child {
    margin-bottom: 0;
  }

  /* 工具栏按钮：增大触摸区域 */
  .canvas-toolbar {
    top: 12px;
    right: 12px;
    gap: 10px;
  }

  .tool-btn {
    width: 48px;
    height: 48px;
    min-height: 44px; /* 确保符合最小触摸目标 */
    font-size: 20px;
    border-radius: 12px;
  }

  /* 模型项：增大点击区域 */
  .model-item {
    padding: 14px 20px 14px 40px;
    min-height: 44px;
    font-size: 15px;
  }

  /* 分类标题：增大点击区域 */
  .category-header {
    padding: 14px 20px;
    min-height: 44px;
    font-size: 15px;
  }

  /* 侧边栏头部调整 */
  .sidebar-header {
    padding: 16px 20px;
  }

  .sidebar-header h2 {
    font-size: 20px;
  }
}

/* 小屏幕手机（最大宽度 480px） */
@media (max-width: 480px) {
  .toolbar {
    padding: 0 12px;
    height: 52px;
  }

  .toolbar-left span {
    font-size: 11px !important;
  }

  #currentModelTitle {
    font-size: 14px !important;
  }

  .vip-btn {
    padding: 6px 12px;
    font-size: 11px;
  }

  /* 兼容旧样式 */
  .top-bar {
    padding: 12px 16px;
  }

  /* 小屏幕下菜单按钮位置也需要调整 */
  .menu-toggle-btn {
    top: 50px;
  }

  .current-model-title {
    font-size: 16px;
  }

  .info-card-content {
    font-size: 12px;
    padding: 10px 14px;
  }

  .canvas-toolbar {
    top: 8px;
    right: 8px;
  }

  .tool-btn {
    width: 44px;
    height: 44px;
    font-size: 18px;
  }
}

/* 横屏模式（移动端） */
@media (max-width: 768px) and (orientation: landscape) {
  /* 横屏时改为左右布局，1:2比例 */
  .content-row {
    flex-direction: row;
  }

  /* Canvas 容器：左侧，占1份 */
  .canvas-container {
    width: auto;
    flex: 0 0 33.33%; /* 1份 */
    max-height: 100%;
    border-bottom: none;
    border-right: 1px solid var(--border-color);
  }

  /* 信息卡片：右侧，占2份 */
  .info-card {
    width: auto;
    flex: 1 1 66.67%; /* 2份 */
    border-top: none;
    border-left: none;
  }
}
