/* 字体优化和加载策略 */

/* 定义字体堆栈 */
:root {
  --font-primary: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-secondary: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Monaco', 'Consolas', 'Ubuntu Mono', monospace;
}

/* 基础字体设置 */
body {
  font-family: var(--font-primary);
  font-feature-settings: 'kern' 1, 'liga' 1;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* 防止字体闪烁（FOUT） */
.fonts-loaded {
  /* 字体加载完成后移除过渡 */
}

/* 字体加载前的临时样式 */
.fonts-loading {
  /* 在字体加载期间使用系统字体 */
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* 特定元素的字体设置 */
.font-serif {
  font-family: 'Noto Serif SC', Georgia, 'Times New Roman', serif;
}

.font-mono {
  font-family: var(--font-mono);
  font-feature-settings: 'tnum' 1; /* 等宽数字 */
}

.font-display {
  font-family: var(--font-secondary);
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* 字体大小和行高优化 */
.text-responsive-xs {
  font-size: clamp(0.75rem, 2vw, 0.875rem);
}

.text-responsive-sm {
  font-size: clamp(0.875rem, 2.5vw, 1rem);
}

.text-responsive-base {
  font-size: clamp(1rem, 3vw, 1.125rem);
}

.text-responsive-lg {
  font-size: clamp(1.125rem, 3.5vw, 1.25rem);
}

.text-responsive-xl {
  font-size: clamp(1.25rem, 4vw, 1.5rem);
}

.text-responsive-2xl {
  font-size: clamp(1.5rem, 5vw, 2rem);
}

.text-responsive-3xl {
  font-size: clamp(2rem, 6vw, 3rem);
}

.text-responsive-4xl {
  font-size: clamp(2.5rem, 7vw, 4rem);
}

.text-responsive-5xl {
  font-size: clamp(3rem, 8vw, 5rem);
}

/* 标题字体优化 */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-secondary);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin-top: 0;
  margin-bottom: 1rem;
}

/* 段落优化 */
p {
  line-height: 1.6;
  margin-top: 0;
  margin-bottom: 1rem;
}

/* 小字体优化 */
small {
  font-size: 0.875em;
  line-height: 1.4;
}

/* 引用优化 */
blockquote {
  font-family: var(--font-serif);
  font-style: italic;
  line-height: 1.6;
  border-left: 4px solid;
  padding-left: 1rem;
  margin: 1.5rem 0;
}

/* 代码字体优化 */
code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background-color: rgba(0, 0, 0, 0.05);
  padding: 0.125rem 0.25rem;
  border-radius: 0.25rem;
}

pre {
  font-family: var(--font-mono);
  font-size: 0.875em;
  line-height: 1.5;
  background-color: rgba(0, 0, 0, 0.05);
  padding: 1rem;
  border-radius: 0.5rem;
  overflow-x: auto;
}

/* 暗色模式下的代码样式 */
.dark code {
  background-color: rgba(255, 255, 255, 0.1);
}

.dark pre {
  background-color: rgba(255, 255, 255, 0.05);
}

/* 字体权重优化 */
.font-light {
  font-weight: 300;
}

.font-normal {
  font-weight: 400;
}

.font-medium {
  font-weight: 500;
}

.font-semibold {
  font-weight: 600;
}

.font-bold {
  font-weight: 700;
}

.font-black {
  font-weight: 900;
}

/* 字符间距优化 */
.tracking-tighter {
  letter-spacing: -0.05em;
}

.tracking-tight {
  letter-spacing: -0.025em;
}

.tracking-normal {
  letter-spacing: 0;
}

.tracking-wide {
  letter-spacing: 0.025em;
}

.tracking-wider {
  letter-spacing: 0.05em;
}

.tracking-widest {
  letter-spacing: 0.1em;
}

/* 行高优化 */
.leading-none {
  line-height: 1;
}

.leading-tight {
  line-height: 1.25;
}

.leading-snug {
  line-height: 1.375;
}

.leading-normal {
  line-height: 1.5;
}

.leading-relaxed {
  line-height: 1.625;
}

.leading-loose {
  line-height: 2;
}

/* 字体加载动画 */
@keyframes fontFadeIn {
  from {
    opacity: 0;
    transform: translateY(0.1em);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fonts-loaded * {
  animation: fontFadeIn 0.3s ease-out;
}

/* 性能优化 */
.text-rendering-optimize {
  text-rendering: optimizeLegibility;
  font-feature-settings: 'kern' 1, 'liga' 1;
}

/* 高对比度模式支持 */
@media (prefers-contrast: high) {
  body {
    font-weight: 500;
  }
}

/* 减少动画偏好支持 */
@media (prefers-reduced-motion: reduce) {
  .fonts-loaded * {
    animation: none;
  }
}

/* 打印样式优化 */
@media print {
  body {
    font-family: 'Times New Roman', serif;
    font-size: 12pt;
    line-height: 1.4;
    color: black;
    background: white;
  }
  
  h1, h2, h3, h4, h5, h6 {
    font-family: 'Times New Roman', serif;
    font-weight: bold;
    page-break-after: avoid;
  }
  
  p {
    orphans: 3;
    widows: 3;
  }
}