/**
 * 文章页增强样式：左侧「分享 + 返回」竖列、侧边栏文章目录。
 *
 * 只作用于普通文章详情页（body.single-post），其他页面零影响。
 *
 * ── 结构 ──────────────────────────────────────────────────────────
 *   .main（桌面端 flex）
 *     ├ .entry-share-rail   左侧竖列（sticky 到视口中部）
 *     └ .entry              正文 + 页脚 + 相关文章
 *   aside.sidebar
 *     ├ .entry-toc          文章目录
 *     └ .widget …           原有小工具
 *
 * ── 两个必须知道的坑（踩过，别再改回去）────────────────────────────
 * ① JS 把 .entry-share 搬进 rail 之后，.entry-share / .entry-share-item 的
 *    display 会被计算成 block（flex item 的 blockify），父主题的
 *    align-items / justify-content 全部失效，图标会缩到圆形的左上角外。
 *    → 这里对这两个元素**显式重写 display:flex + 居中**，不能省。
 * ② 分享块默认在文末。若 CSS 直接把它 display:none，JS 一旦没跑就永久丢图标。
 *    → 一律挂在 body.entrava-share-in-rail 上（JS 搬运成功后由 JS 加类），
 *      搬失败时分享仍在文末，功能不丢。
 *
 * @package Entrava_Child
 */

/* ==========================================================================
   一、左侧竖列（仅桌面 ≥992）
   ========================================================================== */
@media (min-width: 992px) {

	/* .main 由「块」改为「两列 flex」：左分享列 + 右正文 */
	body.single-post .wrap > .main {
		display: flex;
		align-items: flex-start;
		gap: 20px;
	}

	body.single-post .wrap > .main > .entry {
		flex: 1 1 auto;
		min-width: 0;
	}

	/* 默认隐藏：只有 JS 搬运成功（body 带类）才出现，避免 JS 失效时白占 62px */
	body.entrava-share-in-rail .entry-share-rail {
		display: flex;
		flex-direction: column;
		align-items: center;
		flex: 0 0 62px;
		width: 62px;
		position: sticky;
		/* 262 ≈ 整列高度的一半，让图标组停在视口垂直中部 */
		top: calc(50vh - 162px);
		z-index: 2;
	}

	body.entrava-share-in-rail .entry-share-rail__title {
		font-size: 10.5px;
		line-height: 1;
		letter-spacing: 0.14em;
		text-transform: uppercase;
		font-weight: 700;
		color: #a3a9b1;
		margin-bottom: 20px;
	}

	/* 搬进来的父主题原生分享块：横向 flex 改纵向 */
	body.entrava-share-in-rail .entry-share-rail .entry-share {
		display: flex;
		flex-direction: column;
		align-items: center;
		flex-wrap: nowrap;
		gap: 14px;
		margin: 0;
		padding: 0;
		line-height: 1;
		width: auto;
	}

	/* 原生的「Share to:」文案由 rail 自己的 FOLLOW 标题代替 */
	body.entrava-share-in-rail .entry-share-rail .entry-share-title {
		display: none;
	}

	/* 圆形图标：覆盖父主题的 32×32 方形带边框 */
	body.entrava-share-in-rail .entry-share-rail .entry-share-item {
		display: flex;
		align-items: center;
		justify-content: center;
		flex-shrink: 0;
		width: 40px;
		height: 40px;
		border: 1px solid #e4e7eb;
		border-radius: 50%;
		background: #fff;
		color: #5b626b;
		transition: color 0.2s, border-color 0.2s;
	}

	body.entrava-share-in-rail .entry-share-rail .entry-share-item:hover {
		border-color: var(--theme-color, #ea5706);
		color: var(--theme-color, #ea5706);
	}

	/* 图标本体：父主题 .wpcom-icon 是 inline-block + svg 1em，这里统一 16px 并居中 */
	body.entrava-share-in-rail .entry-share-rail .entry-share-item .wpcom-icon {
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 16px;
		line-height: 1;
		margin: 0;
		opacity: 1;
	}

	body.entrava-share-in-rail .entry-share-rail .entry-share-item svg {
		width: 16px;
		height: 16px;
		vertical-align: 0;
	}

	/* 分隔线 */
	body.entrava-share-in-rail .entry-share-rail__divider {
		width: 26px;
		height: 1px;
		background: #e4e7eb;
		margin: 22px 0 20px;
	}

	/* 返回列表 */
	body.entrava-share-in-rail .entry-share-rail__back {
		display: flex;
		flex-direction: column;
		align-items: center;
		gap: 9px;
		text-decoration: none;
		color: #5b626b;
		font-size: 11px;
		line-height: 1.3;
		text-align: center;
		transition: color 0.2s;
	}

	body.entrava-share-in-rail .entry-share-rail__back:hover {
		color: var(--theme-color, #ea5706);
	}

	body.entrava-share-in-rail .entry-share-rail__back svg {
		width: 24px;
		height: 24px;
		color: var(--theme-color, #ea5706);
	}

	/* 搬走之后文末那份不再显示（挂在 body 类上，搬失败则保留） */
	body.entrava-share-in-rail .entry-footer .entry-share {
		display: none;
	}
}

/* --------------------------------------------------------------------------
   1.1 微信扫码分享弹层（左栏，≥992）

   背景（父主题现状，2026-11-15 线上实测）：
     · 父主题 main.js 内置 jQuery.fn.qrcode，Share.init() 会给
       `a[data-share="wechat"]` 自动插入
       `.share-wx-wrap > .j-share-qrcode(canvas 256×256) + 「微信扫码分享」`；
     · 但「显示」规则只写了 `.action .action-share-item:hover .share-wx-wrap`，
       `.entry-share-item` 这一支恒为 opacity:0 + pointer-events:none
       ⇒ 在正文 / 左栏点微信，什么都不发生；
     · 位置是「图标正上方居中」（left:50%; margin-left:-81px; bottom:50px），
       实测 1000px 视口时弹层左边跑到 -20px，被视口裁掉。

   所以这里只改「位置 + 显示 + 二维码比例」，二维码内容仍由父主题生成
   （默认取 og:url，取不到才用 location.href），我们一个像素都不自己画。
   -------------------------------------------------------------------------- */
@media (min-width: 992px) {

	body.entrava-share-in-rail .entry-share-rail .entry-share-wechat {
		cursor: pointer;
	}

	/* 改为「图标右侧弹出」：左栏贴着容器左边缘，往上弹在 992–1200 会被视口裁掉；
	   右侧是正文区，160px 宽永远放得下。 */
	body.entrava-share-in-rail .entry-share-rail .entry-share-item .share-wx-wrap {
		left: calc(100% + 14px);
		right: auto;
		top: 50%;
		bottom: auto;
		/* 父主题用 margin-left:-81px 做水平居中，这里必须清掉 */
		margin: 0 !important;
		transform: translateY(-50%) translateX(-4px);
		transition: opacity 0.18s ease-out, transform 0.18s ease-out;
	}

	/* 父主题的三角箭头指向下方（bottom:-16px），改到右侧弹出后方向不对，直接去掉 */
	body.entrava-share-in-rail .entry-share-rail .entry-share-item .share-wx-wrap::before,
	body.entrava-share-in-rail .entry-share-rail .entry-share-item .share-wx-wrap::after {
		display: none;
	}

	/* 两条显示路径：鼠标悬停 / 点击后常驻（JS 加 .is-wx-open）。
	   刻意不写 `:focus-within` —— 实测点击后 a 会保持 focus，规则会把弹层顶在
	   opacity:1，导致「再点一次」关不掉（开关语义失效）；键盘用户走 Enter → click
	   同一条路径，配合下面的 :focus-visible 描边即可。 */
	body.entrava-share-in-rail .entry-share-rail .entry-share-wechat:hover .share-wx-wrap,
	body.entrava-share-in-rail .entry-share-rail .entry-share-wechat.is-wx-open .share-wx-wrap {
		opacity: 1;
		pointer-events: auto;
		transform: translateY(-50%) translateX(0);
	}

	body.entrava-share-in-rail .entry-share-rail .entry-share-wechat:focus-visible {
		outline: 2px solid var(--theme-color, #ea5706);
		outline-offset: 3px;
	}

	/* 二维码必须是正方形：父主题给 canvas 的是 width:100% + height:auto + padding:10px 10px 0，
	   线上实测渲染成 160×150（竖向压扁 6%），扫码头识别率会掉。
	   改成「留白放在容器上 + 画布 1:1」。 */
	body.entrava-share-in-rail .entry-share-rail .j-share-qrcode {
		display: block;
		box-sizing: border-box;
		padding: 10px;
	}

	body.entrava-share-in-rail .entry-share-rail .j-share-qrcode canvas {
		display: block;
		box-sizing: border-box;
		width: 100%;
		height: auto;
		padding: 0;
		aspect-ratio: 1 / 1;
	}

	body.entrava-share-in-rail .entry-share-rail .share-wx-wrap > span:last-child {
		display: block;
		padding: 0 0 10px;
	}
}

/* --------------------------------------------------------------------------
   1.2 微信扫码分享弹层（页脚版：移动端 <992，或桌面搬运失效时）

   页脚那排分享图标是 flex 一行（<992 下 28×28、gap 8），父主题把弹层写死在
   「图标正上方居中」：bottom:50px + left:50% + margin-left:-81px。
   在页脚这种位置会命中两种出界 —— 贴顶（弹层 184px 高，往上顶出视口顶部）、
   靠左右两端（162px 宽，居中后越过视口边）。
   所以这里的 left/top 全部交给 JS 算（article.js 的 placeWx()），CSS 只负责清掉
   父主题的定位与箭头、以及显示时机。
   -------------------------------------------------------------------------- */

body:not( .entrava-share-in-rail ) .entry-footer .entry-share-wechat {
	cursor: pointer;
}

body:not( .entrava-share-in-rail ) .entry-footer .entry-share-item .share-wx-wrap {
	left: 0;
	top: 0;
	right: auto;
	bottom: auto;
	/* 父主题用它做水平居中，JS 会写内联 left/top，这里必须清掉 margin */
	margin: 0 !important;
	transform: none;
	z-index: 20;
	transition: opacity 0.18s ease-out;
}

body:not( .entrava-share-in-rail ) .entry-footer .entry-share-item .share-wx-wrap::before,
body:not( .entrava-share-in-rail ) .entry-footer .entry-share-item .share-wx-wrap::after {
	display: none;
}

/* 只有「真能 hover」的设备才给 hover 显示：手机 tap 后 :hover 会粘住，
   会让「再点一次收起」失效（同左栏 :focus-within 那个坑）。 */
@media ( hover: hover ) and ( pointer: fine ) {
	body:not( .entrava-share-in-rail ) .entry-footer .entry-share-wechat:hover .share-wx-wrap {
		opacity: 1;
		pointer-events: auto;
	}
}

body:not( .entrava-share-in-rail ) .entry-footer .entry-share-wechat.is-wx-open .share-wx-wrap {
	opacity: 1;
	pointer-events: auto;
}

/* 无 hover 设备（手机 / 平板）：页脚版**只认** .is-wx-open。
   2026-11-16 实测踩到的坑：tap 一次展开后焦点会留在图标这个 <a> 上
   （`document.activeElement` = `.entry-share-wechat`），父主题对 `:focus` /
   `:focus-within` 也给了 `opacity:1`，于是「再点一次」虽然已经把
   `.is-wx-open` 摘掉（aria-expanded=false），弹层**视觉上仍然挂着**，
   用户会以为按钮失灵。桌面不受影响（鼠标一移开 hover 就消失）。
   修法：在手势设备上把「未展开」状态的显示全部压掉，显示入口只剩 JS 的类。 */
@media ( hover: none ), ( pointer: coarse ) {
	body:not( .entrava-share-in-rail ) .entry-footer .entry-share-wechat:not( .is-wx-open ) .share-wx-wrap {
		opacity: 0;
		pointer-events: none;
	}
}

/* 二维码同样要正方形（父主题会把 256 方图压成 160×150） */
body:not( .entrava-share-in-rail ) .entry-footer .entry-share-item .j-share-qrcode {
	display: block;
	box-sizing: border-box;
	padding: 10px;
}

body:not( .entrava-share-in-rail ) .entry-footer .entry-share-item .j-share-qrcode canvas {
	display: block;
	box-sizing: border-box;
	width: 100%;
	height: auto;
	padding: 0;
	aspect-ratio: 1 / 1;
}

body:not( .entrava-share-in-rail ) .entry-footer .entry-share-item .share-wx-wrap > span:last-child {
	display: block;
	padding: 0 0 10px;
}

/* ==========================================================================
   二、文章目录（侧边栏内）
   ========================================================================== */

.entry-toc {
	margin: 0 0 28px;
	padding: 0 0 24px;
	border-bottom: 1px solid #eceef1;
}

.entry-toc__title {
	font-size: 12px;
	line-height: 1;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	font-weight: 700;
	color: #98a0a9;
	margin: 0 0 14px;
}

.entry-toc__list {
	list-style: none;
	margin: 0;
	padding: 0;
	font-size: 14px;
	line-height: 1.45;
	/* 目录过长时自己滚动，避免撑坏侧边栏的 sticky */
	max-height: calc(100vh - 320px);
	overflow: auto;
}

.entry-toc__list::-webkit-scrollbar {
	width: 4px;
}

.entry-toc__list::-webkit-scrollbar-thumb {
	background: #dfe3e8;
	border-radius: 2px;
}

.entry-toc__list li {
	margin: 0;
}

/* 左侧竖线：每项一段，紧挨着连成整条；未激活浅灰、激活主题色 */
.entry-toc__list a {
	display: block;
	padding: 8px 0 8px 14px;
	border-left: 2px solid #e7e9ec;
	color: #5b626b;
	text-decoration: none;
	transition: color 0.15s, border-color 0.15s;
}

.entry-toc__list a:hover {
	color: #111;
	border-left-color: #c9ced4;
}

.entry-toc__list a.is-active {
	color: var(--theme-color, #ea5706);
	border-left-color: var(--theme-color, #ea5706);
	font-weight: 600;
}

.entry-toc__num {
	color: #b3b9c1;
	margin-right: 7px;
	font-variant-numeric: tabular-nums;
}

.entry-toc__list a.is-active .entry-toc__num {
	color: var(--theme-color, #ea5706);
}

/* H3 缩进 */
.entry-toc__list .is-h3 a {
	padding-left: 28px;
	font-size: 13px;
}

/* ==========================================================================
   三、跳转不遮挡（sticky header 是 72px，留 24px 呼吸）
   ========================================================================== */

/* 只在「用户没要求减少动效」时平滑滚动（可访问性）。
   注意：本文件只在文章详情页入队，所以这条 html 规则的影响面就只有该页；
   本站头部 80→72 收缩 + 锚点吸顶那套 JS 已有「停稳强制校准」（1.122），
   程序化滚动变成动画不会让它失准。 */
@media (prefers-reduced-motion: no-preference) {
	html {
		scroll-behavior: smooth;
	}
}

body.single-post .entry-content h2,
body.single-post .entry-content h3 {
	scroll-margin-top: 96px;
}

/* ==========================================================================
   四、移动端 / 平板：目录与左侧列都不出现，分享保持父主题原样（文末）
   ========================================================================== */

/* --------------------------------------------------------------------------
   4.1 正文表格窄屏横向滑动（2026-11-15 实测补）
   父主题对 .wp-block-table 只给了 display:block 之外的默认样式，
   实测 390 宽下 overflow-x = visible、table 被压到 360px 宽：
   三列规格表每格只剩 4–5 个字符一行，一格竖排 8 行，可读性崩掉；
   而 document.scrollWidth 仍等于 clientWidth ⇒ 不会横向溢出，只能靠肉眼发现。
   做法：给「包住表格的 figure」横向滚动 + 给 table 一个最小宽度，
   手机上滑表格而不是压表格；页面本身仍不横向滚动。
   -------------------------------------------------------------------------- */
@media (max-width: 991px) {
	body.single-post .entry-content .wp-block-table,
	body.single-post .entry-content figure.wp-block-table {
		overflow-x: auto;
		-webkit-overflow-scrolling: touch;
	}

	/* 最小宽度只给「包在可滚容器里的表」。
	   别写成 .entry-content table —— 万一是老式（无 figure 包裹）的裸表格，
	   加了 min-width 却没有滚动容器，就把整页撑出横向滚动条了（比原问题更糟）。 */
	body.single-post .entry-content .wp-block-table table {
		min-width: 560px;
		/* 表格自己滚，别让 margin 把边框裁掉一半 */
		margin-bottom: 0;
	}
}

@media (max-width: 991px) {
	.entry-toc {
		display: none;
	}

	/* 双保险：万一父主题以后不再隐藏侧边栏，这里也不让它出现 */
	body.single-post .entry-share-rail {
		display: none;
	}

	body.single-post .entry-content h2,
	body.single-post .entry-content h3 {
		scroll-margin-top: 76px;
	}
}

/* ==========================================================================
   六、作者署名（元信息行 + 文末作者卡片，v1.127）
   ==========================================================================
   数据来源全部是 WordPress 用户资料（昵称 / 简介 / 头像），见
   inc/article-author.php 与 templates/entry-meta.php、templates/author-box.php。
   这里只负责呈现：作者名可点、作者卡片是「浅底 + 细边」的收束块。
   ========================================================================== */

/* 6.1 元信息行里的「By 作者」 */
.entry-meta .entry-author {
	display: inline-flex;
	align-items: baseline;
	gap: 5px;
}

.entry-meta .entry-author__by {
	color: #98a0a9;
}

.entry-meta .entry-author__link {
	font-weight: 600;
	color: inherit;
	text-decoration: none;
}

.entry-meta .entry-author__link:hover,
.entry-meta .entry-author__link:focus-visible {
	color: var(--theme-color, #ea5706);
}

/* 6.2 文末作者卡片 */
.entry-author-box {
	display: flex;
	align-items: flex-start;
	gap: 18px;
	margin: 34px 0 0;
	padding: 22px;
	border: 1px solid #eceef1;
	border-radius: 6px;
	background: #fafbfc;
}

.entry-author-box__avatar {
	flex: 0 0 auto;
}

.entry-author-box__avatar img {
	display: block;
	width: 64px;
	height: 64px;
	border-radius: 50%;
	background: #fff;
	object-fit: cover;
}

.entry-author-box__body {
	min-width: 0;
}

.entry-author-box__eyebrow {
	margin: 0 0 4px;
	font-size: 11px;
	line-height: 1;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	font-weight: 700;
	color: #98a0a9;
}

.entry-author-box__name {
	margin: 0 0 8px;
	font-size: 17px;
	font-weight: 700;
	line-height: 1.3;
}

.entry-author-box__name a {
	color: #1a1d21;
	text-decoration: none;
}

.entry-author-box__name a:hover,
.entry-author-box__name a:focus-visible {
	color: var(--theme-color, #ea5706);
}

.entry-author-box__bio {
	margin: 0 0 10px;
	font-size: 15px;
	line-height: 1.6;
	color: #5b626b;
}

.entry-author-box__more {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	font-size: 13px;
	font-weight: 600;
	color: var(--theme-color, #ea5706);
	text-decoration: none;
}

.entry-author-box__more:hover,
.entry-author-box__more:focus-visible {
	text-decoration: underline;
}

@media (max-width: 480px) {
	.entry-author-box {
		flex-direction: column;
		gap: 12px;
		padding: 18px;
	}

	.entry-author-box__avatar img {
		width: 56px;
		height: 56px;
	}
}
