/* ==========================================================================
   base.css — 全局基础样式
   包含：CSS 变量、Reset、全局排版、通用工具类
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. CSS 变量定义
   -------------------------------------------------------------------------- */
:root {
  /* 颜色系统 */
  --primary:        #4CAF50;
  --primary-dark:   #388E3C;
  --primary-light:  #E8F5E9;
  --secondary:      #2196F3;
  --secondary-dark: #1565C0;
  --secondary-light:#E3F2FD;

  --text-main:  #333333;
  --text-sub:   #666666;
  --text-light: #999999;

  --bg-page:  #f5f5f5;
  --bg-white: #ffffff;
  --bg-dark:  #2c3e50;

  --border-color: #e0e0e0;
  --shadow:       0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-hover: 0 6px 20px rgba(0, 0, 0, 0.15);

  /* 功能色 */
  --color-info:    #2196F3;
  --color-success: #4CAF50;
  --color-warning: #FF9800;
  --color-danger:  #F44336;

  /* 徽章彩色系列 */
  --badge-1: #FF5722;
  --badge-2: #9C27B0;
  --badge-3: #2196F3;
  --badge-4: #009688;
  --badge-5: #FF9800;
  --badge-6: #795548;
  --badge-7: #607D8B;
  --badge-8: #E91E63;

  /* 字体系统 */
  --font-main: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei",
               "微软雅黑", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  --font-code: "Courier New", Consolas, "Source Code Pro", "Fira Code", monospace;

  --font-size-xs: 12px;
  --font-size-sm: 13px;
  --font-size-md: 15px;
  --font-size-lg: 18px;
  --font-size-xl: 22px;
  --font-size-2xl: 28px;

  --line-height-tight:  1.4;
  --line-height-normal: 1.7;
  --line-height-loose:  2;

  /* 间距系统 */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* 圆角系统 */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* 过渡动画 */
  --transition-fast:   0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-slow:   0.4s ease;

  /* 层级 */
  --z-dropdown: 100;
  --z-sticky:   200;
  --z-overlay:  300;
  --z-modal:    400;
  --z-toast:    500;
}

/* 暗色模式变量（可选） */
[data-theme="dark"] {
  --text-main:    #e0e0e0;
  --text-sub:     #aaaaaa;
  --text-light:   #777777;
  --bg-page:      #1a1a2e;
  --bg-white:     #16213e;
  --bg-dark:      #0f0f23;
  --border-color: #333355;
  --shadow:       0 2px 8px rgba(0, 0, 0, 0.4);
}

/* --------------------------------------------------------------------------
   2. CSS Reset
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: var(--font-main);
  font-size: var(--font-size-md);
  line-height: var(--line-height-normal);
  color: var(--text-main);
  background-color: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* 列表 */
ul, ol {
  list-style: none;
}

/* 链接 */
a {
  color: var(--primary-dark);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover {
  color: var(--primary);
}

/* 图片 */
img {
  max-width: 100%;
  height: auto;
  display: block;
  border: 0;
}

/* 表单元素基础重置 */
input,
button,
textarea,
select {
  font-family: inherit;
  font-size: inherit;
  outline: none;
  border: none;
  background: none;
}

button {
  cursor: pointer;
}

/* 表格 */
table {
  border-collapse: collapse;
  border-spacing: 0;
  width: 100%;
}

/* 水平线 */
hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: var(--space-lg) 0;
}

/* 内联代码 */
code {
  font-family: var(--font-code);
  font-size: 0.9em;
  background: #f0f0f0;
  color: #c7254e;
  padding: 2px 5px;
  border-radius: var(--radius-sm);
}

/* 引用块 */
blockquote {
  border-left: 4px solid var(--primary);
  padding: var(--space-sm) var(--space-md);
  margin: var(--space-md) 0;
  background: var(--primary-light);
  color: var(--text-sub);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* --------------------------------------------------------------------------
   3. 全局排版样式
   -------------------------------------------------------------------------- */

/* 标题层级 */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: var(--line-height-tight);
  color: var(--text-main);
}

h1 { font-size: var(--font-size-2xl); margin-bottom: var(--space-lg); }
h2 { font-size: var(--font-size-xl);  margin-bottom: var(--space-md); }
h3 { font-size: var(--font-size-lg);  margin-bottom: var(--space-md); }
h4 { font-size: var(--font-size-md);  margin-bottom: var(--space-sm); }
h5 { font-size: var(--font-size-sm);  margin-bottom: var(--space-sm); }
h6 { font-size: var(--font-size-xs);  margin-bottom: var(--space-sm); }

p {
  margin-bottom: var(--space-md);
  line-height: var(--line-height-normal);
}

/* --------------------------------------------------------------------------
   4. 通用工具类
   -------------------------------------------------------------------------- */

/* 容器 */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-md);
}

/* 文字对齐 */
.text-left   { text-align: left; }
.text-center { text-align: center; }
.text-right  { text-align: right; }

/* 文字颜色 */
.text-primary { color: var(--primary); }
.text-secondary { color: var(--secondary); }
.text-sub   { color: var(--text-sub); }
.text-light { color: var(--text-light); }
.text-danger  { color: var(--color-danger); }
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }

/* 文字大小 */
.text-xs { font-size: var(--font-size-xs); }
.text-sm { font-size: var(--font-size-sm); }
.text-md { font-size: var(--font-size-md); }
.text-lg { font-size: var(--font-size-lg); }
.text-xl { font-size: var(--font-size-xl); }

/* 文字粗细 */
.font-normal { font-weight: 400; }
.font-medium { font-weight: 500; }
.font-bold   { font-weight: 600; }
.font-black  { font-weight: 700; }

/* Flex 工具 */
.flex         { display: flex; }
.flex-center  { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-wrap    { flex-wrap: wrap; }
.flex-col     { flex-direction: column; }
.flex-1       { flex: 1; }
.items-center { align-items: center; }
.gap-xs  { gap: var(--space-xs); }
.gap-sm  { gap: var(--space-sm); }
.gap-md  { gap: var(--space-md); }
.gap-lg  { gap: var(--space-lg); }

/* 间距 */
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.p-sm  { padding: var(--space-sm); }
.p-md  { padding: var(--space-md); }
.p-lg  { padding: var(--space-lg); }

/* 显示/隐藏 */
.hidden   { display: none !important; }
.visible  { visibility: visible; }
.invisible { visibility: hidden; }

/* 溢出 */
.overflow-hidden { overflow: hidden; }
.text-ellipsis {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* 多行截断（2行） */
.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* 圆角 */
.rounded-sm { border-radius: var(--radius-sm); }
.rounded-md { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-full { border-radius: var(--radius-full); }

/* 阴影 */
.shadow    { box-shadow: var(--shadow); }
.shadow-hover:hover { box-shadow: var(--shadow-hover); }

/* 过渡 */
.transition { transition: all var(--transition-normal); }

/* 鼠标 */
.cursor-pointer { cursor: pointer; }

/* 宽高 */
.w-full  { width: 100%; }
.h-full  { height: 100%; }

/* 分割线 */
.divider {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: var(--space-md) 0;
}

/* 角标/徽章基础 */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-xs);
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.badge-primary {
  background: var(--primary);
  color: #fff;
}
.badge-secondary {
  background: var(--secondary);
  color: #fff;
}
.badge-outline {
  border: 1px solid var(--primary);
  color: var(--primary);
  background: transparent;
}

/* 字母徽章（彩色方块） */
.letter-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-xs);
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

/* 标签 */
.tag {
  display: inline-block;
  font-size: var(--font-size-xs);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  color: var(--primary-dark);
  white-space: nowrap;
}

/* 骨架屏加载动画 */
@keyframes skeleton-loading {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: var(--radius-sm);
}

/* 平滑显示/隐藏动画 */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-in {
  animation: fadeIn var(--transition-normal) forwards;
}

/* 阅读进度条 */
#reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--primary);
  z-index: var(--z-toast);
  width: 0%;
  transition: width 0.1s linear;
}

/* 返回顶部按钮 */
#back-to-top {
  position: fixed;
  bottom: 40px;
  right: 30px;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: #fff;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal), transform var(--transition-normal);
  z-index: var(--z-overlay);
  border: none;
}
#back-to-top.show {
  opacity: 1;
  pointer-events: auto;
}
#back-to-top:hover {
  background: var(--primary-dark);
  transform: translateY(-3px);
}

/* Toast 提示 */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-full);
  font-size: var(--font-size-sm);
  z-index: var(--z-toast);
  opacity: 0;
  transition: opacity var(--transition-normal), transform var(--transition-normal);
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* 提示框组件 */
.alert {
  padding: var(--space-md);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-md);
  border-left: 4px solid;
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
}
.alert-info {
  background: #E3F2FD;
  border-color: var(--color-info);
  color: #1565C0;
}
.alert-success {
  background: #E8F5E9;
  border-color: var(--color-success);
  color: #2E7D32;
}
.alert-warning {
  background: #FFF3E0;
  border-color: var(--color-warning);
  color: #E65100;
}
.alert-danger {
  background: #FFEBEE;
  border-color: var(--color-danger);
  color: #C62828;
}
