/**
 * 代码高亮主题 - 与正文字体一致，美观的语法高亮
 * 基于GitHub风格，优化了注释和代码的颜色区分
 */

/* ===== 代码块基础样式 ===== */
.highlight {
  position: relative;
  margin: 2rem 0;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 
    0 4px 16px rgba(0, 0, 0, 0.06),
    0 2px 4px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  background: #ffffff;
}

.highlight:hover {
  box-shadow: 
    0 8px 24px rgba(0, 0, 0, 0.1),
    0 4px 8px rgba(0, 0, 0, 0.15);
  transform: translateY(-2px);
}

/* ===== 代码容器 - 使用等宽字体保持代码格式 ===== */
.highlight pre {
  margin: 0;
  padding: 2rem 2.5rem;
  background: #ffffff !important;
  overflow-x: auto;
  line-height: 1.6;
  font-size: 14px; /* 适合代码阅读的字体大小 */
  font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace; /* 等宽字体 */
  font-weight: 400;
  letter-spacing: 0;
  color: #24292f; /* 深灰色，易于阅读 */
  border-radius: 12px;
  position: relative;
  white-space: pre !important; /* 强制保持空白字符和换行 */
  word-wrap: normal !important; /* 不自动换行 */
  word-break: normal !important; /* 不强制断词 */
  tab-size: 4 !important; /* 设置制表符宽度 */
  -moz-tab-size: 4 !important; /* Firefox支持 */
}

/* ===== 代码内容样式 ===== */
.highlight code {
  font-family: inherit; /* 继承容器的等宽字体 */
  font-size: inherit;
  line-height: inherit;
  background: none !important;
  padding: 0 !important;
  border: none !important;
  border-radius: 0 !important;
  font-weight: inherit;
  letter-spacing: inherit;
  white-space: pre !important; /* 强制保持空白字符 */
  word-wrap: normal !important; /* 不自动换行 */
  word-break: normal !important; /* 不强制断词 */
  display: block; /* 确保代码块正确显示 */
}

/* ===== 行号样式 ===== */
.highlight .lntable {
  border-spacing: 0;
  padding: 0;
  margin: 0;
  border: 0;
  width: 100%;
  table-layout: fixed;
}

.highlight .lntd {
  vertical-align: top;
  padding: 0;
  margin: 0;
  border: 0;
  white-space: pre; /* 保持空白字符 */
}

.highlight .lnt,
.highlight .ln {
  color: rgba(36, 41, 47, 0.4); /* 行号颜色 */
  user-select: none;
  margin-right: 1.5rem;
  padding-right: 1rem;
  width: 3rem;
  text-align: right;
  font-size: 12px;
  font-weight: 400;
  border-right: 1px solid rgba(36, 41, 47, 0.1);
  line-height: 1.6;
  font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
}

/* ===== 语法高亮颜色 ===== */

/* 注释 - 使用较淡的绿色，与代码区分 */
.highlight .c,     /* Comment */
.highlight .c1,    /* Comment.Single */
.highlight .cm,    /* Comment.Multiline */
.highlight .cp,    /* Comment.Preproc */
.highlight .cs {   /* Comment.Special */
  color: #6a737d !important;
  font-style: italic;
  font-weight: 400;
}

/* 关键字 - 使用蓝色 */
.highlight .k,     /* Keyword */
.highlight .kc,    /* Keyword.Constant */
.highlight .kd,    /* Keyword.Declaration */
.highlight .kn,    /* Keyword.Namespace */
.highlight .kp,    /* Keyword.Pseudo */
.highlight .kr,    /* Keyword.Reserved */
.highlight .kt {   /* Keyword.Type */
  color: #d73a49 !important;
  font-weight: 600;
}

/* 字符串 - 使用绿色 */
.highlight .s,     /* String */
.highlight .s1,    /* String.Single */
.highlight .s2,    /* String.Double */
.highlight .sa,    /* String.Affix */
.highlight .sb,    /* String.Backtick */
.highlight .sc,    /* String.Char */
.highlight .sd,    /* String.Doc */
.highlight .se,    /* String.Escape */
.highlight .sh,    /* String.Heredoc */
.highlight .si,    /* String.Interpol */
.highlight .sr,    /* String.Regex */
.highlight .ss,    /* String.Symbol */
.highlight .sx {   /* String.Other */
  color: #032f62 !important;
  font-weight: 400;
}

/* 数字 - 使用橙色 */
.highlight .m,     /* Number */
.highlight .mb,    /* Number.Bin */
.highlight .mf,    /* Number.Float */
.highlight .mh,    /* Number.Hex */
.highlight .mi,    /* Number.Integer */
.highlight .mo {   /* Number.Oct */
  color: #005cc5 !important;
  font-weight: 500;
}

/* 函数名 - 使用紫色 */
.highlight .n,     /* Name */
.highlight .na,    /* Name.Attribute */
.highlight .nb,    /* Name.Builtin */
.highlight .nc,    /* Name.Class */
.highlight .nd,    /* Name.Decorator */
.highlight .ne,    /* Name.Exception */
.highlight .nf,    /* Name.Function */
.highlight .ni,    /* Name.Entity */
.highlight .nl,    /* Name.Label */
.highlight .nn,    /* Name.Namespace */
.highlight .no,    /* Name.Constant */
.highlight .nt,    /* Name.Tag */
.highlight .nv,    /* Name.Variable */
.highlight .nx {   /* Name.Other */
  color: #6f42c1 !important;
  font-weight: 500;
}

/* 操作符 - 使用深灰色 */
.highlight .o,     /* Operator */
.highlight .ow {   /* Operator.Word */
  color: #d73a49 !important;
  font-weight: 600;
}

/* 标点符号 - 使用默认颜色 */
.highlight .p {    /* Punctuation */
  color: #24292f !important;
  font-weight: 400;
}

/* 泛型/类型 - 使用青色 */
.highlight .g,     /* Generic */
.highlight .gd,    /* Generic.Deleted */
.highlight .ge,    /* Generic.Emph */
.highlight .gh,    /* Generic.Heading */
.highlight .gi,    /* Generic.Inserted */
.highlight .go,    /* Generic.Output */
.highlight .gp,    /* Generic.Prompt */
.highlight .gr,    /* Generic.Error */
.highlight .gs,    /* Generic.Strong */
.highlight .gt,    /* Generic.Traceback */
.highlight .gu {   /* Generic.Subheading */
  color: #22863a !important;
  font-weight: 500;
}

/* 错误 - 使用红色背景 */
.highlight .err {
  color: #cb2431 !important;
  background-color: #ffeef0 !important;
  font-weight: 500;
}

/* 高亮行 - 使用淡黄色背景 */
.highlight .hll {
  background-color: #fffbdd !important;
  display: block;
  margin: 0 -2.5rem;
  padding: 0 2.5rem;
  border-left: 4px solid #ffd33d;
}

/* ===== 特殊语言优化 ===== */

/* Go语言特殊关键字 */
.highlight[data-lang="go"] .k {
  color: #00add8 !important;
}

/* JavaScript特殊关键字 */
.highlight[data-lang="javascript"] .k,
.highlight[data-lang="js"] .k {
  color: #f7df1e !important;
}

/* Python特殊关键字 */
.highlight[data-lang="python"] .k {
  color: #3776ab !important;
}

/* ===== 内联代码样式 ===== */
.post-content code:not(.highlight code) {
  background: #f6f8fa !important;
  color: #d73a49 !important;
  padding: 0.2em 0.4em;
  border: 1px solid #e1e4e8 !important;
  border-radius: 4px;
  font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace; /* 等宽字体 */
  font-size: 0.85em;
  font-weight: 400;
  letter-spacing: 0;
  white-space: nowrap; /* 内联代码不换行 */
}

/* ===== 响应式设计 ===== */
@media (max-width: 768px) {
  .highlight pre {
    padding: 1.5rem 1rem;
    font-size: 14px;
    line-height: 1.6;
  }
  
  .highlight .lnt,
  .highlight .ln {
    margin-right: 1rem;
    padding-right: 0.5rem;
    width: 2.5rem;
    font-size: 12px;
  }
  
  .post-content code:not(.highlight code) {
    font-size: 0.85em;
    padding: 0.15em 0.3em;
  }
}

@media (max-width: 480px) {
  .highlight pre {
    padding: 1rem 0.8rem;
    font-size: 13px;
    line-height: 1.5;
  }
  
  .highlight .lnt,
  .highlight .ln {
    margin-right: 0.8rem;
    padding-right: 0.4rem;
    width: 2rem;
    font-size: 11px;
  }
}

/* ===== 语言标签 ===== */
.highlight::before {
  content: attr(data-lang);
  position: absolute;
  top: 0.8rem;
  right: 1rem;
  background: rgba(36, 41, 47, 0.1);
  color: rgba(36, 41, 47, 0.7);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ===== 复制按钮区域预留 ===== */
.highlight {
  padding-top: 2.5rem;
}

.highlight pre {
  padding-top: 1.5rem;
}

/* ===== 确保代码格式正确显示 ===== */
.highlight .lntd:last-child {
  width: 100%;
}

.highlight .lntd:last-child code,
.highlight .lntd:last-child pre {
  white-space: pre !important;
  word-wrap: normal !important;
  word-break: normal !important;
  overflow-x: auto;
  tab-size: 4 !important;
  -moz-tab-size: 4 !important;
}

/* 修复可能的样式冲突 */
.highlight * {
  white-space: inherit !important;
  word-wrap: inherit !important;
  word-break: inherit !important;
}

.highlight .line {
  display: block;
  white-space: pre !important;
  word-wrap: normal !important;
  word-break: normal !important;
}

/* 确保代码行正确换行 */
.highlight br {
  display: none !important; /* 隐藏可能的br标签 */
}

/* 代码块内的span元素保持内联 */
.highlight span {
  white-space: inherit !important;
}

/* 强制所有代码相关元素保持格式 */
.highlight .lntable,
.highlight .lntable * {
  white-space: pre !important;
  word-wrap: normal !important;
  word-break: normal !important;
  tab-size: 4 !important;
  -moz-tab-size: 4 !important;
}
