/* 微信浏览器兼容性修复 */

/* 修复微信浏览器下的字体渲染问题 */
* {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* 修复微信浏览器下的触摸事件问题 */
body {
  -webkit-tap-highlight-color: transparent;
}

/* 优化微信浏览器下的滚动性能 */
#R-body-inner,
#R-sidebar {
  -webkit-overflow-scrolling: touch;
}

/* 修复微信浏览器下的flex布局问题 */
.flex-block-wrapper {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
}

/* 确保topbar内容在一行显示 */
#R-topbar .topbar-wrapper {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  align-items: center;
}

/* 优化面包屑和翻页按钮的布局 */
#R-topbar .topbar-breadcrumbs {
  flex-grow: 1;
  min-width: 0;
}

/* 确保翻页按钮区域始终显示在右侧 */
#R-topbar .topbar-area-end {
  flex-shrink: 0;
  margin-left: auto;
}

/* 修复微信浏览器下的固定定位问题 */
#R-topbar,
#R-sidebar {
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

/* 修复微信浏览器下的媒体查询问题 */
@media screen and (max-width: 47.999rem) {
  /* 确保在小屏幕上正确显示 */
  #R-body {
    margin-inline-start: 0 !important;
    position: relative;
    z-index: 1;
  }
  
  /* 修复小屏幕上的菜单显示 */
  #R-sidebar {
    transform: translateX(-100%);
    -webkit-transform: translateX(-100%);
  }
  
  /* 显示菜单按钮 */
  #navshow {
    display: block;
  }

  /* 侧边栏弹出样式 */
  body.sidebar-flyout #R-sidebar {
    transform: translateX(0);
    -webkit-transform: translateX(0);
  }
  
  /* 微信浏览器特定修复 */
  body.mobile-support #R-sidebar {
    z-index: 1000;
    transform: translateX(-100%) !important;
    -webkit-transform: translateX(-100%) !important;
    transition: transform 0.3s ease;
    opacity: 1 !important;
    background-color: #fff;
  }
  
  body.mobile-support.sidebar-flyout #R-sidebar {
    transform: translateX(0) !important;
    -webkit-transform: translateX(0) !important;
  }
}

/* 修复微信浏览器下的点击延迟问题 */
a,
button,
input,
select,
textarea {
  -webkit-tap-highlight-color: transparent;
}

/* 修复微信浏览器下的图片渲染问题 */
/* 图片溢出修复 - 确保所有图片都能适应屏幕宽度 */
img {
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  image-rendering: -webkit-optimize-contrast;
  max-width: 100% !important;
  height: auto !important;
  display: block;
}

/* 特别处理文章中的图片 */
#R-body img,
article img {
  max-width: 100% !important;
  height: auto !important;
  width: auto !important;
}

/* 卡片容器中的图片修复 */
.card-container .card-image img {
  max-width: 100% !important;
  height: auto !important;
}

/* 移动端图片特别处理 */
@media screen and (max-width: 47.999rem) {
  /* 确保所有图片在移动设备上都适应屏幕宽度 */
  img,
  #R-body img,
  article img,
  .card-container .card-image img {
    max-width: 100% !important;
    height: auto !important;
    width: auto !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }
  
  /* 防止图片容器溢出 */
  figure,
  .card-image,
  .card-container .card-image {
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden;
  }
}

/* 修复微信浏览器下的CSS变量兼容性 */
:root {
  --INTERNAL-MAIN-BG-color: var(--INTERNAL-MAIN-BG-color, #ffffff);
  --INTERNAL-MAIN-TEXT-color: var(--INTERNAL-MAIN-TEXT-color, #333333);
  --INTERNAL-MAIN-LINK-color: var(--INTERNAL-MAIN-LINK-color, #0366d6);
}

/* 列表页中列表项的颜色设置为蓝色 */
article ul > li,
article ol > li {
  color: #1890ff;
}

/* 文章内容页中的超级链接设置为蓝色 */
article a {
  color: #1890ff !important;
}

article a:hover,
article a:active,
article a:focus {
  color: #40a9ff !important;
}

/* 确保卡片标题中的链接也应用蓝色 */
.card-container .card-title a {
  color: #1890ff !important;
}

/* 修复微信浏览器下的CSS动画性能 */
.default-animation {
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  transition: all 0.35s ease;
}

/* 防止内容溢出屏幕的通用规则 */
article,
#R-body-inner {
  overflow-x: hidden;
}

/* 确保文本能够换行 */
p,
div,
span,
a,
li {
  overflow-wrap: break-word;
  word-break: break-word;
  max-width: 100%;
}

/* 长单词和URL的特殊处理 */
p,
div,
span,
a {
  word-break: break-all;
}

/* 移动端文本溢出修复 */
@media screen and (max-width: 47.999rem) {
  /* 防止文字溢出 */
  article {
    overflow-wrap: break-word;
    word-break: break-word;
  }
  
  /* 确保内容容器不会溢出 */
  .flex-block-wrapper {
    width: 100% !important;
    max-width: 100% !important;
  }
}
