/*
 Theme Name: 2025-sub
 Template: twentytwentyfive
 Version: 1.2.3
 Description: GEO 双语站子主题 —— 语言中间件 + 多 CPT 架构（plugin / docs）。基于 Twenty Twenty-Five。
 Requires at least: 6.7
 Tested up to: 6.8
*/

/*
 变更记录 / Changelog
 -------------------
 1.2.3 (2026-11-01)
   - **修硬伤**：`Template:` 头原写成 `twenty-twenty-five`（带连字符），而 WordPress 官方父主题
     目录名是 `twentytwentyfive`（无连字符）。`Template:` 必须填父主题的**目录名**，
     写错会导致后台「上传主题」时提示「缺少父主题 twenty-twenty-five」、子主题无法启用。
     同时修 templates/404.html 与 templates/single-docs.html 里 4 处
     `wp:template-part {"theme":"twenty-twenty-five"}` → `twentytwentyfive`，
     否则 header / footer 部件取不到（页面会缺头缺尾）。
   - 说明：Twenty Twenty-Five 之前历代默认主题同样是无连字符目录名
     (twentytwentyone / twentytwentytwo / twentytwentythree / twentytwentyfour)。
 1.2.2 (2026-11-01)
   - 新增「静默记忆」：无 maple_lang_pref Cookie 时，把当前页实际渲染的语言写入 Cookie。
     解决「从搜索结果直达单篇 → 页面已是英文 → 点 logo 回 / 又被问一次语言」这一环；
     仅在该用户从未表达过选择时写一次，绝不用 IP / Accept-Language 猜测。
     三个禁区不写：站点首页 /（选择页）、404、搜索页（/?s= 无语言前缀、语言不可信）。
   - 修正 §4 maple_current_lang()：英文内容分类归档（/category/geo-en/ 这类无 /en/ 前缀的 URL）
     原先被误判为 zh，现按 slug 的 `-en` 后缀识别为 en。影响 <html lang>、hreflang 与语言记忆。
   - 后台设置页「五、URL 结构 · 首页」补充静默记忆说明。
 1.2.1 (2026-11-01)
   - 修正后台设置页（外观 → 2025-sub 设置）两处与方案 E 冲突/过期说明：
     ① 「三、必填配置 · 静态首页」原文要求选「最新文章」，与方案 E 矛盾——照做会让 /
        变成默认语言博客列表、语言选择卡永不出现在。改为：一个静态页面 → 选「语言选择」页。
     ② 「四、可用简码」表由 6 个补到 10 个（补 [maple_lang_chooser] / [maple_search] /
        [maple_docs_tree] / [maple_doc_plugin_card]），并注明 chooser 只能放在 / 静态首页。
   - 无任何前端逻辑改动，仅后台文案与文档同步。
 1.2.0 (2026-10-26)
   - 新增「方案 E」语言入口：根路径 / 改为语言选择落地页，放 [maple_lang_chooser] 短码
     （两个大按钮：中文 / English）；访客点选写 maple_lang_pref Cookie 并跳对应首页。
   - 新增 §9.2：仅按 Cookie 的 / 快捷跳转（老用户跳过选择页），不做 IP 地理重定向
     （违反 Google 指引且误判多）。彻底弃用原 Cloudflare Worker 首页分流（见 functions.php 注释）。
   - 新增样式：.maple-lang-chooser / .maple-lang-card（双卡居中、响应式、hover 抬升）。
 1.1.0 (2026-10-23)
   - 新增文档中心（docs）：templates/single-docs.html 三列模板 ——
     左 [maple_docs_tree] 文档树 | 中 正文 | 右 [maple_doc_plugin_card] 插件卡；
     <782px 由 WP 块列自动纵向堆叠。
     文档树 = 当前语种整个文档结构：父文档当分类/章节、子文档当文章，支持多级，
     当前项与祖先链高亮（.is-current / .is-ancestor）。
   - 新增 docs → plugin 归属：post meta `_maple_doc_plugin`（存 plugin 文章 ID）
     + docs 编辑页侧边下拉。插件卡调用该 plugin 的 标题 / 缩略图 / 摘要；
     文档未指定插件时整块不显示。
   - 分类承载沿用 docs 自身层级（hierarchical CPT），不新增分类法。
 1.0.1 (2026-10-20)
   - 修复 §12 Query Loop 自动语言过滤硬伤：原实现一律注入 language 分类法，
     而该分类法未注册给 post，导致文章列表被过滤成空。现按 post_type 分流
     （post → category 的 zh/en；plugin / docs / page → language；混合 → OR）。
     开关默认值由「关」改为「开」，所有内容 loop 默认区分语言。
   - 404 改为单文件双语模板：废弃 404-zh.html / 404-en.html 双文件写法
     （区块主题下 resolve_block_template() 只按 slug '404' 解析，语言模板
     永远不会被加载；新版 WP 还会被直接 include 成裸 HTML 而破版）。
     templates/404.html 现为唯一 404 模板，可见文案用 [maple_t] 按语言切换。
   - GA4 Measurement ID 改为后台填写（不再写死 G-XXXXXXXXXX），留空即静默。
 1.0.0
   - 首个版本：语言分类法 / plugin+docs CPT / 关联翻译 meta / hreflang /
     搜索隔离 / 语言切换与双语文字短码 / 大菜单 / 404 / GA4+GDPR。
*/

/* 语言切换导航：纯文字、克制、无国旗 emoji */
.maple-lang-switch {
	display: inline-flex;
	align-items: center;
	gap: 0.5em;
	font-size: 0.9em;
	line-height: 1;
}
.maple-lang-switch a {
	text-decoration: none;
	color: inherit;
}
.maple-lang-switch a:hover {
	text-decoration: underline;
}
.maple-lang-switch [aria-current="true"] {
	font-weight: 700;
	opacity: 1;
}
.maple-lang-switch .disabled,
.maple-lang-switch span:not([aria-current]) {
	opacity: 0.5;
}

/* 语言选择落地页（方案 E）：两个大按钮，居中、响应式 */
.maple-lang-chooser {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 1.25rem;
	margin: 2.5rem 0;
}
.maple-lang-card {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	min-width: 180px;
	min-height: 150px;
	padding: 1.5rem 2rem;
	border: 1px solid rgba(0, 0, 0, 0.12);
	border-radius: 14px;
	text-decoration: none;
	color: inherit;
	background: #fff;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
	transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.maple-lang-card:hover,
.maple-lang-card:focus-visible {
	transform: translateY(-4px);
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
	border-color: #1a73e8;
	outline: none;
}
.maple-lang-card-flag {
	font-size: 2rem;
	font-weight: 700;
	line-height: 1.1;
}
.maple-lang-card-sub {
	margin-top: 0.4rem;
	font-size: 0.95rem;
	opacity: 0.7;
}
@media (max-width: 480px) {
	.maple-lang-chooser {
		flex-direction: column;
		align-items: stretch;
	}
	.maple-lang-card {
		min-width: 0;
		min-height: 0;
	}
}

/* ===== Maple Mega Menu（§14，零插件） ===== */
.maple-nav {
	position: relative;
	display: flex;
	flex-wrap: wrap;
	list-style: none;
	margin: 0;
	padding: 0;
}
.maple-nav > li {
	position: relative;
}
/* 大菜单项：自身不参与定位，让面板相对整个 .maple-nav 撑满（方案 A 全宽栏） */
.maple-nav > li.menu-item-mega {
	position: static;
}
.maple-nav a {
	display: block;
	padding: 10px 14px;
	text-decoration: none;
}

/* 普通下拉（非大菜单） */
.maple-nav li.menu-item-has-children > ul.sub-menu {
	position: absolute;
	left: 0;
	top: 100%;
	min-width: 200px;
	background: #fff;
	border: 1px solid #e2e2e2;
	box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
	display: none;
	list-style: none;
	margin: 0;
	padding: 6px 0;
	z-index: 999;
}
.maple-nav li.menu-item-has-children:hover > ul.sub-menu,
.maple-nav li.menu-item-has-children:focus-within > ul.sub-menu {
	display: block;
}
.maple-nav ul.sub-menu a {
	padding: 8px 16px;
}

/* 大菜单面板（方案 A：相对 .maple-nav 全宽，不写死宽度） */
.maple-mega-panel {
	position: absolute;
	left: 0;
	right: 0;
	top: 100%;
	background: #fff;
	border: 1px solid #e2e2e2;
	box-shadow: 0 10px 30px rgba(0, 0, 0, 0.10);
	padding: 24px 32px;
	display: none;
	z-index: 999;
}
.maple-nav li.menu-item-mega:hover > .maple-mega-panel,
.maple-nav li.menu-item-mega:focus-within > .maple-mega-panel,
.maple-nav li.menu-item-mega.is-open > .maple-mega-panel {
	display: block;
}

/* 回退多列链接 */
.maple-mega-panel > ul {
	display: flex;
	gap: 32px;
	flex-wrap: wrap;
	list-style: none;
	margin: 0;
	padding: 0;
}
.maple-mega-panel > ul > li {
	min-width: 160px;
}
.maple-mega-panel > ul > li a {
	padding: 6px 0;
}

/* 图案内列标题 */
.maple-mega-col-title {
	margin: 0 0 8px;
	font-size: 14px;
}

/* 移动端：大菜单/下拉 改为点按展开（手风琴） */
@media (max-width: 768px) {
	.maple-nav {
		flex-direction: column;
	}
	.maple-nav li.menu-item-has-children > ul.sub-menu,
	.maple-mega-panel {
		position: static;
		display: none;
		width: 100%;
		min-width: 0;
		box-shadow: none;
		border: none;
		padding: 4px 0 4px 16px;
	}
	.maple-nav li.menu-item-has-children.is-open > ul.sub-menu,
	.maple-nav li.menu-item-mega.is-open > .maple-mega-panel {
		display: block;
	}
	.maple-mega-panel > ul {
		flex-direction: column;
		gap: 6px;
	}
}

/* 404 文章列表（[maple_latest_posts] / [maple_popular_posts]） */
.maple-posts-list {
	list-style: none;
	margin: 0;
	padding: 0;
}
.maple-posts-list li {
	padding: 8px 0;
	border-bottom: 1px solid #eee;
	font-size: 15px;
	line-height: 1.5;
}
.maple-posts-list li:last-child {
	border-bottom: none;
}
.maple-posts-list a {
	color: #1d1d1d;
	text-decoration: none;
}
.maple-posts-list a:hover {
	color: #2271b1;
	text-decoration: underline;
}

/* ===== GA4 Cookie 同意弹窗（§16，双语） ===== */
.maple-cookie-banner {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 1000;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 14px 20px;
	background: #1d1d1d;
	color: #fff;
	font-size: 14px;
	box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.18);
}
.maple-cookie-banner[hidden] {
	display: none;
}
.maple-cookie-msg {
	margin: 0;
	flex: 1 1 240px;
}
.maple-cookie-actions {
	display: flex;
	gap: 8px;
}
.maple-cookie-btn {
	border: 1px solid #fff;
	background: transparent;
	color: #fff;
	padding: 7px 16px;
	border-radius: 4px;
	cursor: pointer;
	font-size: 14px;
}
.maple-cookie-btn:hover {
	background: rgba(255, 255, 255, 0.12);
}
.maple-cookie-accept {
	background: #2271b1;
	border-color: #2271b1;
}
.maple-cookie-accept:hover {
	background: #135e96;
}

/* ===== 搜索框（§8：默认按语言 + 文章类型下拉） ===== */
.maple-search-form {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	align-items: center;
}
.maple-search-form input[type="search"] {
	flex: 1 1 200px;
	min-width: 160px;
	padding: 9px 12px;
	border: 1px solid #ccc;
	border-radius: 4px;
	font-size: 14px;
}
.maple-search-form .maple-search-type {
	padding: 9px 10px;
	border: 1px solid #ccc;
	border-radius: 4px;
	font-size: 14px;
	background: #fff;
}
.maple-search-form button {
	padding: 9px 18px;
	border: 1px solid #2271b1;
	background: #2271b1;
	color: #fff;
	border-radius: 4px;
	cursor: pointer;
	font-size: 14px;
}
.maple-search-form button:hover {
	background: #135e96;
}

/* 默认搜索表单（Search 块走 get_search_form 注入的下拉）也对齐一点 */
.search-form .maple-search-type,
form[role="search"] .maple-search-type {
	margin-left: 6px;
}
@media (max-width: 600px) {
	.maple-search-form {
		flex-direction: column;
		align-items: stretch;
	}
	.maple-search-form .maple-search-type,
	.maple-search-form button {
		width: 100%;
	}
}


/* =========================================================
 * 文档中心（docs）：左(文档树) | 中(正文) | 右(插件卡)
 * 移动端纵向堆叠由 WP 块列自带（<782px flex-direction:column）
 * ======================================================= */
.maple-docs-layout {
	gap: 32px;
	align-items: flex-start;
}
.maple-docs-col-tree,
.maple-docs-col-plugin {
	position: sticky;
	top: 24px;
}

/* 左侧文档树 */
.maple-docs-tree-title {
	margin: 0 0 12px;
	font-size: 13px;
	font-weight: 600;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	opacity: 0.6;
}
.maple-docs-tree ul {
	list-style: none;
	margin: 0;
	padding: 0;
}
.maple-docs-tree .maple-docs-level-1,
.maple-docs-tree .maple-docs-level-2,
.maple-docs-tree .maple-docs-level-3,
.maple-docs-tree .maple-docs-level-4 {
	margin-left: 10px;
	padding-left: 10px;
	border-left: 1px solid #e2e2e2;
}
.maple-docs-item > a {
	display: block;
	padding: 5px 8px;
	border-radius: 4px;
	font-size: 14px;
	line-height: 1.45;
	text-decoration: none;
}
.maple-docs-item > a:hover {
	background: #f2f2f2;
}
.maple-docs-item.is-ancestor > a {
	font-weight: 600;
}
.maple-docs-item.is-current > a {
	font-weight: 700;
	background: #eef4ff;
	color: #1a4fa0;
}

/* 右侧插件卡 */
.maple-doc-plugin {
	border: 1px solid #e2e2e2;
	border-radius: 8px;
	padding: 16px;
}
.maple-doc-plugin-label {
	margin: 0 0 10px;
	font-size: 12px;
	font-weight: 600;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	opacity: 0.6;
}
.maple-doc-plugin-thumb-link {
	display: block;
	margin-bottom: 10px;
}
.maple-doc-plugin-thumb {
	display: block;
	width: 100%;
	height: auto;
	border-radius: 6px;
}
.maple-doc-plugin-title {
	margin: 0 0 8px;
	font-size: 16px;
	line-height: 1.35;
}
.maple-doc-plugin-title a {
	text-decoration: none;
}
.maple-doc-plugin-excerpt {
	margin: 0;
	font-size: 13px;
	line-height: 1.6;
	opacity: 0.85;
}

/* 中等屏取消吸顶，避免遮挡正文 */
@media (max-width: 900px) {
	.maple-docs-col-tree,
	.maple-docs-col-plugin {
		position: static;
	}
}

/* ===== Maple Header 布局修复（v1.2.3 补丁，匹配真实渲染结构） =====
   真实渲染：<header class="wp-block-template-part"> 直接包含
   <ul class="maple-nav"> 与 <nav class="maple-lang-switch">，
   无 .maple-header 包裹层，故此前针对该类的样式无效。 */
header.wp-block-template-part {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem 1.5rem;
	padding: 0.75rem clamp(1rem, 5vw, 3rem);
	border-bottom: 1px solid rgba(0, 0, 0, 0.1);
	background: #fff;
}
header.wp-block-template-part .maple-nav {
	margin: 0;
	align-items: center;
}
.maple-lang-switch {
	margin-left: auto;
}
.maple-nav a:hover {
	background: rgba(0, 0, 0, 0.06);
	border-radius: 6px;
}
@media (max-width: 720px) {
	header.wp-block-template-part {
		justify-content: flex-start;
	}
	.maple-lang-switch {
		margin-left: 0;
	}
}
