/* 站内自定义样式
   _config.stellar.yml 的 inject.head_end 引用了本文件。
   只保留主题没做、或者本项目特意改掉的部分；改完记得 npx hexo clean 再构建。 */

/* ==========================================================================
   一、九宫格缩略图：{% gallery size:nine %}
   固定 3 列，格子随容器宽度缩放，单格最高 240px；图片脱离文档流，
   避免原图尺寸或懒加载后的固有高度撑开网格。保留 fancybox 分组。
   ========================================================================== */
.tag-plugin.gallery.grid-box[size="nine"] {
  --gallery-max-height: 240px;
  --gallery-gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-gap: var(--gallery-gap);
}

.tag-plugin.gallery.grid-box[size="nine"] .grid-cell {
  position: relative;
  width: 100%;
  min-width: 0;
  min-height: 0;
  max-height: var(--gallery-max-height);
  aspect-ratio: 1;
  overflow: hidden;
}

.tag-plugin.gallery.grid-box[size="nine"] .grid-cell img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-height: 100%;
  object-fit: cover;
  object-position: center;
}

/* 手机截图：按「单格高度 × 宽高比 × 3 列 + 两段间距」限制整组宽度，
   格子与图片比例一致，避免高度封顶后留下宽大的空白背景。 */
.tag-plugin.gallery.grid-box[size="nine"][aspect_ratio="phone"] {
  width: 100%;
  max-width: calc(var(--gallery-max-height) * 27 / 19.5 + var(--gallery-gap) * 2);
  margin-inline: auto;
}

.tag-plugin.gallery.grid-box[size="nine"][aspect_ratio="phone"] .grid-cell {
  aspect-ratio: 9 / 19.5;
}

.tag-plugin.gallery.grid-box[size="nine"][aspect_ratio="phone"] .grid-cell img {
  object-fit: contain;
}

@media (max-width: 640px) {
  .tag-plugin.gallery.grid-box[size="nine"] {
    --gallery-gap: 4px;
  }

  .tag-plugin.gallery.grid-box[size="nine"] .grid-cell,
  .tag-plugin.gallery.grid-box[size="nine"] img {
    border-radius: 4px;
  }
}

/* 文章配图靠左；不改封面、行内表情和图库内部的裁切方式。 */
article.md-text.content img:not(.inline, .tag-plugin img),
article.md-text.content .tag-plugin.image .image-bg,
article.md-text.content .tag-plugin.image .image-bg img,
article.md-text.content .tag-plugin.gallery.grid-box[size="nine"][aspect_ratio="phone"] {
  margin-left: 0;
  margin-right: auto;
}

article.md-text.content .tag-plugin.image .image-bg {
  align-items: flex-start;
}

article.md-text.content .tag-plugin.image > .image-meta {
  justify-content: flex-start;
}

/* ==========================================================================
   二、文章详情页横幅
   2.1 顶部标签行：轻量天青色标签
   2.2 发布于 / 更新于：常显 + 绝对时间
   2.3 无封面图时改为紧凑横幅
   ========================================================================== */
:root {
  --post-tag-color: #007f82;
  --post-tag-background: rgba(0, 206, 209, 0.12);
  --post-tag-hover: rgba(0, 206, 209, 0.22);
}

.article.banner .content .top .article-tags.banner-tags {
  justify-content: flex-start;
  align-items: center;
  width: 100%;
  margin: 2px 0;
  padding: 0;
  gap: 2px 6px;
  line-height: 1.6;
}

.article.banner .content .top .article-tags.banner-tags .banner-tags-label {
  padding: 2px 0;
  margin-right: 6px;
  color: var(--text-banner-theme, var(--text-banner));
  white-space: nowrap;
}

.article.banner .content .top .article-tags.banner-tags a.tag {
  display: inline-flex;
  align-items: center;
  margin: 4px 0;
  padding: 0 8px 0 0;
  border: 0;
  border-radius: 4px;
  background: var(--post-tag-background, #f0e8ff);
  box-shadow: none;
  color: var(--post-tag-color);
  font-size: inherit;
  opacity: 1;
  text-decoration: none;
  transition: color 180ms ease, background-color 180ms ease;
}

.article.banner .content .top .article-tags.banner-tags a.tag svg {
  width: 0.85em;
  height: 0.5em;
  color: inherit;
  opacity: 1;
}

.article.banner .content .top .article-tags.banner-tags a.tag:hover {
  background: var(--post-tag-hover);
}

.article-tags a.tag {
  color: var(--post-tag-color);
  background: var(--post-tag-background);
}

.article-tags a.tag:hover,
.article-tags a.tag:focus-visible {
  color: var(--post-tag-color);
  background: var(--post-tag-hover);
}

.article.banner .banner-tags a.tag:focus-visible {
  outline: 2px solid var(--theme);
  outline-offset: 2px;
}

/* 主题默认把「更新于」做成 hover 才出现，这里常显并固定绝对时间 */
.article.banner .content .top .post-dates {
  align-items: baseline;
  flex-wrap: wrap;
}

.article.banner .content .top .post-dates .text {
  padding: 2px 0;
  visibility: visible;
}

.article.banner .content .top .post-dates time {
  margin-left: 4px;
}

.article.banner .content .top .post-dates .sep {
  margin: 0 8px;
  opacity: 0.5;
}

.article.banner .content .top .post-dates .sep:before {
  content: '|';
}

/* 无封面图：标题紧跟标签与日期，不再被 min-height + margin-top:auto 顶到底部 */
.article.banner .content:not(:has(img.bg)) {
  min-height: 0;
}

.article.banner .content:not(:has(img.bg)) .bottom,
.article.banner .content:not(:has(img.bg)) .bottom.only-title {
  padding-top: 0;
  padding-bottom: 0;
}

/* 标题内边距由主题更长的选择器链给出，这里用同样长度覆盖，避免 12px 空档 */
.site-shell .article.banner .content:not(:has(img.bg)) .bottom.only-title .title {
  padding: 0.125rem 0;
  margin: 0.25rem 0 1rem;
}

@media (max-width: 640px) {
  .article.banner .content .top .article-tags.banner-tags {
    flex-wrap: wrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  .article.banner .content .top .article-tags.banner-tags a.tag {
    transition: none;
  }
}

/* 较新／较早文章：仅将标题链接从主题的五级标题字号降到正文字号。 */
#read-next > .body > .item > a {
  font-size: var(--fs-content-base);
}

/* ==========================================================================
   三、右栏：分类索引、标签云、目录与最新文章
   ========================================================================== */
#rightbar-region .category-index-widget .widget-body {
  padding: 8px;
  border: 1px solid var(--block-border);
  border-radius: 12px;
  background: var(--card);
}

#rightbar-region .category-index-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

#rightbar-region .category-index-list-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  color: var(--text-p2);
}

#rightbar-region .category-index-list-link {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 8px;
  border-radius: 6px;
  color: inherit;
  overflow-wrap: anywhere;
}

#rightbar-region .category-index-list-link::before {
  content: '';
  flex: 0 0 16px;
  height: 16px;
  margin-right: 8px;
  background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='black' stroke-width='1.5' d='M3 7a2 2 0 0 1 2-2h5l2 2h7a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z'/%3E%3C/svg%3E") center / contain no-repeat;
}

#rightbar-region .category-index-list-count {
  padding-right: 8px;
  font-size: 0.875rem;
}

#rightbar-region .category-index-list-count::before { content: '('; }
#rightbar-region .category-index-list-count::after { content: ')'; }

#rightbar-region .category-index-list-link:hover {
  background: var(--block);
  color: var(--theme);
}

#rightbar-region .tagcloud .widget-body {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  padding: 8px var(--gap-base);
}

:root {
  --theme: #00CED1; /* 主题色：天青色 */
}

/* 标签云样式 */
#rightbar-region .tagcloud a.tag {
  margin: 0;
  padding: 2px 0;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

#rightbar-region .tagcloud a.tag:hover {
  color: var(--theme);
}

/* 首页文章标题：双层青草绿水面波浪，hover 时错速流动。 */
.post-list .post-card .post-title {
  position: relative;
  isolation: isolate;
  text-decoration: none;
}

.post-list .post-card .post-title::before,
.post-list .post-card .post-title::after {
  content: '';
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0;
  transition: opacity 220ms ease;
}

/* 主浪在底部保留连续浅天青色水面，波峰约达标题高度的一半。 */
.post-list .post-card .post-title::before {
  height: 0.5lh;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 96 16' preserveAspectRatio='none'%3E%3Cpath d='M0 6 C10 6 14 2 24 2 S40 6 48 6 S62 10 72 10 S86 6 96 6 L97 6 V17 H-1 V6Z' fill='%2300CED1' fill-opacity='.55'/%3E%3Cpath d='M-1 6 H0 C10 6 14 2 24 2 S40 6 48 6 S62 10 72 10 S86 6 96 6 H97' fill='none' stroke='%23E0FFFF' stroke-opacity='.78'/%3E%3C/svg%3E") repeat-x left bottom / 96px 100%,
    linear-gradient(to top, rgba(0, 206, 209, .28), rgba(0, 206, 209, .18) 42%, transparent);
}

/* 第二层细浪稍低、稍快，随主浪往复滚动。 */
.post-list .post-card .post-title::after {
  height: 0.38lh;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 72 12' preserveAspectRatio='none'%3E%3Cpath d='M0 6 C8 6 11 3 19 3 S30 6 37 6 S46 8 53 8 S64 6 72 6 L73 6 V13 H-1 V6Z' fill='%2300CED1' fill-opacity='.62'/%3E%3Cpath d='M-1 6 H0 C8 6 11 3 19 3 S30 6 37 6 S46 8 53 8 S64 6 72 6 H73' fill='none' stroke='%23E0FFFF' stroke-opacity='.84' stroke-width='.8'/%3E%3C/svg%3E") repeat-x left bottom / 72px 100%;
}

.post-list .post-card:hover .post-title::before,
.post-list .post-card:focus-visible .post-title::before,
.post-list .post-card:focus-within .post-title::before {
  opacity: 1;
  animation: title-sea-swell 2.8s linear infinite;
}

.post-list .post-card:hover .post-title::after,
.post-list .post-card:focus-visible .post-title::after,
.post-list .post-card:focus-within .post-title::after {
  opacity: .9;
  animation: title-sea-ripple 1.9s linear infinite;
}

@keyframes title-sea-swell {
  to { background-position-x: -96px; }
}

@keyframes title-sea-ripple {
  to { background-position-x: -72px; }
}

@media (prefers-reduced-motion: reduce) {
  .post-list .post-card:hover .post-title::before,
  .post-list .post-card:focus-visible .post-title::before,
  .post-list .post-card:focus-within .post-title::before,
  .post-list .post-card:hover .post-title::after,
  .post-list .post-card:focus-visible .post-title::after,
  .post-list .post-card:focus-within .post-title::after {
    animation: none;
  }
}


#rightbar-region :is(.category-index-list-link, .tagcloud a.tag):focus-visible {
  outline: 2px solid var(--theme);
  outline-offset: 2px;
}

/* 目录排在右栏最上方 */
#rightbar-region .widgets .widget-wrapper.toc {
  margin-top: 0;
  padding-top: 0;
}

#rightbar-region .widget-wrapper.toc .toc a.toc-link {
  color: var(--text-p2);
  opacity: 1;
}

#rightbar-region .widget-wrapper.toc .toc .toc-text {
  white-space: normal;
  overflow-wrap: anywhere;
}

#rightbar-region .widget-wrapper.toc .toc a.toc-link:is(:hover, .active) {
  color: var(--theme);
}

#rightbar-region .widget-wrapper:is(.toc, .latest-posts) .widget-footer {
  flex: 0 0 auto;
  margin-top: 12px;
  padding-top: 8px;
}

#rightbar-region .latest-posts .widget-footer {
  position: relative;
  color: var(--text-p2);
}

#rightbar-region .latest-posts .widget-footer::before {
  content: '';
  position: absolute;
  inset: 0 var(--gap-base) auto;
  height: 1px;
  background: var(--block-border);
}

#rightbar-region .latest-posts .widget-footer a {
  display: flex;
  align-items: center;
  color: inherit;
  font-size: 14px;
  padding: 8px var(--gap-base);
  border-radius: var(--border-bar, 8px);
}

#rightbar-region .latest-posts .widget-footer a:hover {
  color: var(--text);
}

#rightbar-region .latest-posts .widget-footer .ui-icon {
  --ui-icon-size: 16px;
  margin-right: 8px;
}

@media screen and (max-width: 1180px) {
  #rightbar-region .latest-posts .widget-footer a {
    background: var(--block);
  }

  #rightbar-region .latest-posts .widget-footer a + a {
    margin-top: 4px;
  }
}

/* 44px 保证触控与键盘的点击面积 */
#rightbar-region .widget-wrapper:is(.toc, .latest-posts) .widget-footer a {
  box-sizing: border-box;
  min-height: 44px;
}

#rightbar-region .widget-wrapper.toc .widget-footer .ui-icon {
  color: inherit;
  opacity: 1;
}

#rightbar-region .widget-footer a:focus-visible {
  outline: 2px solid var(--theme);
  outline-offset: 2px;
}

/* 文章页右栏：目录 + 最新文章整列吸顶
   主题只让 .widget-instance--toc 单独 sticky，排在它下面的组件会随页面滚走；
   这里把整列 .widgets 改成 sticky，两个模块作为整体固定在视口内。
   内容高于可用高度时（长目录）右栏内部滚动，避免把下面的模块顶出屏幕。
   用 body 的页面类型限定范围，不影响首页 / 归档页的右栏组件。 */
@media screen and (min-width: 1181px) {
  body[data-page-layout='post'] #rightbar-region .site-region__viewport > .widgets {
    position: sticky;
    top: var(--rightbar-sticky-offset);
    flex: 0 0 auto;
    height: auto;
    max-height: var(--rightbar-panel-height);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }

  /* 吸顶交给整列承载，目录自身不再单独 sticky，避免两层定位打架 */
  body[data-page-layout='post'] #rightbar-region .widget-instance--toc {
    position: static;
    top: auto;
    z-index: auto;
  }
}

/* ==========================================================================
   四、左栏底部：GitHub / RSS / 邮件 + 折叠按钮
   展开态：三个入口靠左、折叠按钮靠右，同占一行；
   收起态（竖条）：四个图标自上而下竖排。
   「设置」入口主题写死在模板里没有开关，只能在样式层隐掉。
   ========================================================================== */
#leftbar-region .site-region__settings {
  display: none;
}

#leftbar-region .site-region__footer {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

#leftbar-region .site-region__footer-actions {
  flex: 1 1 auto;
  min-width: 0;
}

#leftbar-region .site-region__footer-actions .social-wrap {
  gap: 4px;
  justify-content: flex-start;
}

#leftbar-region .site-region__footer-actions .social {
  width: 24px;
  height: 24px;
  justify-content: center;
  border-radius: 10px;
  /* 不要底色，只留图标轮廓；36px 仍是点击热区 */
  color: var(--text-p1);
  background: transparent;
  /* 主题的 ui-interactive 会加一层内高光/底色，这里一起清掉 */
  box-shadow: none;
  filter: none;
  transition: color 180ms ease;
}

#leftbar-region .site-region__footer-actions .social .ui-icon {
  --ui-icon-size: 20px;
}

/* 主题给社交图标加了 50% 透明，去掉胶囊底后要补回实色，轮廓才清晰 */
#leftbar-region .site-region__footer-actions .social svg {
  opacity: 1;
}

/* hover / 键盘聚焦只换颜色：关掉主题的鼠标光斑，避免又出现一块浅色底 */
#leftbar-region .site-region__footer-actions .social > .card-hover__spotlight {
  display: none;
}

#leftbar-region .site-region__footer-actions .social:hover,
#leftbar-region .site-region__footer-actions .social:focus-visible {
  color: var(--theme);
}

/* 收起成竖条：主题会隐藏所有非 rail 组件，这里把两个入口救回来并改竖排 */
html[data-leftbar-state="collapsed"] .site-shell:not([data-drawer="leftbar"])
  #leftbar-region .site-region__footer {
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

html[data-leftbar-state="collapsed"] .site-shell:not([data-drawer="leftbar"])
  #leftbar-region .widget-instance--actions {
  display: block;
  width: var(--leftbar-rail-width);
  margin-inline: auto;
}

html[data-leftbar-state="collapsed"] .site-shell:not([data-drawer="leftbar"])
  #leftbar-region .site-region__footer-actions .social-wrap {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
}

/* ==========================================================================
   五、暗色主题的标签配色
   ========================================================================== */
:root[data-theme="dark"] {
  --post-tag-color: #55e4e6;
  --post-tag-background: rgba(0, 206, 209, 0.18);
  --post-tag-hover: rgba(0, 206, 209, 0.3);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --post-tag-color: #55e4e6;
    --post-tag-background: rgba(0, 206, 209, 0.18);
    --post-tag-hover: rgba(0, 206, 209, 0.3);
  }
}

/* ==========================================================================
   六、界面字体、右栏标题与短页面页脚
   ========================================================================== */

/* 全站字体：西文 Times New Roman，中文优先使用系统宋体。 */
:root {
  --site-font-family: "Times New Roman", SimSun, "Songti SC", "Source Han Serif SC", "Noto Serif SC", serif;
}

button, input, select, textarea,
.mermaid svg text, .mermaid svg foreignObject {
  font-family: var(--site-font-family);
}

.article-banner-wrap {
  margin: 0 14px;
}

/* 主题默认将小组件标题设为 30% 不透明度，提高分类与标签云标题辨识度。 */
#rightbar-region .widget-wrapper.category-index-widget .widget-header > .name,
#rightbar-region .widget-wrapper.tagcloud .widget-header > .name {
  color: var(--text-p1);
  opacity: 0.85;
}
.widgets .widget-wrapper .widget-header {
  padding-left: 4px!important;
}

.site-region--rightbar .widgets .widget-instance + .widget-instance > .widget-wrapper {
  margin-top: 0;
}

/* 主栏在短页面仍占满可视高度，将版权页脚自然推至内容区下方。 */
.site-main {
  display: flex;
  flex-direction: column;
}

.site-main > .page-footer {
  margin-top: auto;
}

#rightbar-region .category-index-list-link {
  min-height: 32px;
}

.widget-instance--tagcloud {
  margin: 16px 0;
}

/* 保留供顶部横幅使用的标签数据，只隐藏普通文章的文末标签行。 */
body[data-page-layout="post"] .site-main > article.md-text.content + .article-tags {
  display: none;
}

.article-share {
  padding: 0;
}

.article-footer {
  margin: 0;
  padding: 10px 20px;
}

.article-footer .body p {
  margin: 0;
}

.related-wrap {
  margin-top: 2em;
  margin-bottom: 0;
}

#comments {
  margin: 2em 0;
}

.cap.theme {
  color: unset;
}

.giscus-frame {
  margin: 0!important;
}
