/*
 * gp-menu/menu.css — 頁首主選單（SPEC_menu-grouping.md 6.2 六項）
 * 由 mu-plugin gp-menu.php 全站載入。所有選擇器都從 #masthead（站頂頁首）開始，不碰頁首以外的元素。
 *
 * 權重：本檔排在站上行內 <style>（baiyu-single-post、palyul-color-a11y、wp-custom-css）之前，
 * 那幾段有 !important（例：palyul-color-a11y 的 a:hover 金色、baiyu-single-post 的目前所在金底線）。
 * 要蓋掉的屬性一律 id 層級權重＋!important；只在本檔新增、站上沒人寫的屬性不加 !important。
 *
 * 顏色只用站上既有變數：--cp #8B1A1A（選單字色）、--gp-bg #F7F4EF。
 */

#masthead {
	--gpm-ink: var(--cp, #8b1a1a);
	--gpm-bar: 3px;
}

/* ---------- 1. 桌機（Astra 桌機頁首，≥922）：頂層一列，不斷行 ----------
 * 頁首格線原本兩欄都是 auto，右欄（選單）分到的寬度跟著左欄 logo 區浮動；改成 logo 取內容寬、選單取其餘，
 * 並禁止頂層換行。4 項頂層總寬約 430px，922 寬時左欄 logo 296px＋選單 430px＝726px，小於可用 882px（實測見 README）。 */
#masthead #ast-desktop-header .site-primary-header-wrap .ast-builder-grid-row {
	grid-template-columns: auto minmax(0, 1fr) !important;
}
#masthead #ast-desktop-header .site-header-primary-section-right {
	justify-content: flex-end;
}
#masthead #ast-desktop-header #ast-hf-menu-1 {
	flex-wrap: nowrap;
}
#masthead #ast-desktop-header #ast-hf-menu-1 > .menu-item > .menu-link {
	white-space: nowrap;
}

/* ---------- 3a. 桌機下拉箭頭：可點範圍 44×44（Astra 原本約 30×80，寬度不夠） ----------
 * 箭頭在頂層連結裡面；觸控點箭頭只展開不跳頁（Astra 4.14 的 frontend.js 已處理），滑鼠移上去就展開。
 * 箭頭框往右吃掉連結的右內距，頂層項目總寬不變多。 */
#masthead #ast-desktop-header .main-header-menu > .menu-item-has-children > .menu-link .ast-header-navigation-arrow:not(#_) {
	display: inline-flex;
	align-items: center;
	justify-content: flex-start;
	box-sizing: border-box;
	width: 44px;
	height: 44px;
	padding: 0 0 0 6px !important;
	margin: 0 calc(-1 * var(--gpm-pad-r, 16px)) 0 0 !important;
	line-height: 1;
}
#masthead #ast-desktop-header .main-header-menu > .menu-item > .menu-link {
	--gpm-pad-r: 16px;
}

/* ---------- 5. 滑過：字維持選單字色（白底 9.3:1），加底線；不用站上 a:hover 的金色 #9E7B3C（3.9:1） ---------- */
#masthead .main-header-menu .menu-item > .menu-link:hover:not(#_),
#masthead .main-header-menu .menu-item > .menu-link:focus-visible:not(#_) {
	color: var(--gpm-ink) !important;
	text-decoration: underline;
	text-decoration-thickness: 1px;
	text-underline-offset: 0.3em;
}
#masthead .main-header-menu .menu-item:hover > .ast-menu-toggle:not(#_),
#masthead .main-header-menu .ast-menu-toggle:hover:not(#_) {
	color: var(--gpm-ink) !important;
}

/* ---------- 6. 下拉面板強調色：Astra 預設藍 #046BD2 → 本站選單字色 ---------- */
#masthead .main-header-menu .sub-menu:not(#_) {
	border-top-color: var(--gpm-ink) !important;
}
#masthead .main-header-menu .ast-menu-toggle:not(#_) {
	color: var(--gpm-ink) !important;
}

/* ---------- 4. 目前所在：除了顏色，再加字重 600 ＋ 一條選單字色的標記線 ----------
 * 桌機頂層：連結底邊一條 3px 線（取代站上 baiyu-single-post 的 2px 金底線：金色對白底只有 2.3:1）。
 * 下拉子項、手機抽屜：左側一條 3px 線。 */
#masthead .main-header-menu .menu-item.current-menu-item > .menu-link:not(#_),
#masthead .main-header-menu .menu-item.current-menu-ancestor > .menu-link:not(#_) {
	color: var(--gpm-ink) !important;
	font-weight: 600;
	border-bottom: 0 !important;
}
#masthead #ast-desktop-header .main-header-menu > .menu-item.current-menu-item > .menu-link:not(#_),
#masthead #ast-desktop-header .main-header-menu > .menu-item.current-menu-ancestor > .menu-link:not(#_) {
	box-shadow: inset 0 calc(-1 * var(--gpm-bar)) 0 var(--gpm-ink);
}
#masthead #ast-desktop-header .main-header-menu .sub-menu .menu-item.current-menu-item > .menu-link:not(#_),
#masthead #ast-mobile-header .main-header-menu .menu-item.current-menu-item > .menu-link:not(#_),
#masthead #ast-mobile-header .main-header-menu .menu-item.current-menu-ancestor > .menu-link:not(#_) {
	box-shadow: inset var(--gpm-bar) 0 0 var(--gpm-ink);
}

/* ---------- 2. 手機抽屜：每列可點高度 48px（≥44）；子項縮排 ----------
 * Astra 原本每列 43.8px。 */
#masthead #ast-mobile-header .main-header-menu .menu-item > .menu-link:not(#_) {
	display: flex;
	align-items: center;
	min-height: 48px;
	line-height: 1.5 !important;
	padding-top: 0 !important;
	padding-bottom: 0 !important;
	border-bottom: 0 !important;
}
#masthead #ast-mobile-header .main-header-menu .sub-menu .menu-item > .menu-link:not(#_) {
	padding-left: 36px !important;
}
/* 目前所在列、展開中的上層列：不加底色（fix1 必修 1、2）。目前所在靠字重 600＋左側 3px 線；展開靠箭頭轉向＋子項出現。 */
#masthead #ast-mobile-header .main-header-menu .menu-item.current-menu-item > .menu-link:not(#_),
#masthead #ast-mobile-header .main-header-menu .menu-item.current-menu-ancestor > .menu-link:not(#_),
#masthead #ast-mobile-header .main-header-menu .menu-item > .ast-menu-toggle:not(#_),
#masthead #ast-mobile-header .main-header-menu .menu-item:hover > .ast-menu-toggle:not(#_) {
	background-color: transparent !important;
}

/* ---------- 3b. 手機展開鈕：可點範圍 48×48（Astra 原本 50×43.8） ---------- */
#masthead #ast-mobile-header .main-header-menu .menu-item-has-children > .ast-menu-toggle:not(#_) {
	box-sizing: border-box;
	width: 48px;
	height: 48px;
	line-height: 48px !important;
	padding: 0 !important;
	display: flex;
	align-items: center;
	justify-content: center;
}

/* ---------- fix2：手機抽屜子選單箭頭，收合朝下、展開朝上 ----------
 * 跟按鈕的 aria-expanded 同步（Astra 的 JS 點擊時會改這個屬性），不靠點擊事件另外切換。
 * Astra 自己的轉向規則只寫給舊版 ::before 字型圖示與 .main-header-bar-navigation，套不到抽屜裡的 svg。
 * 桌機下拉箭頭不在 #ast-mobile-header 底下，維持朝下。 */
#masthead #ast-mobile-header .main-header-menu .ast-menu-toggle svg:not(#_) {
	transform: none !important;
	transition: transform 200ms ease;
}
#masthead #ast-mobile-header .main-header-menu .ast-menu-toggle[aria-expanded="true"] svg:not(#_) {
	transform: rotate(180deg) !important;
}

/* ---------- fix1：手機頁首與抽屜不出現 Astra 預設藍（#046BD2、#045CB4）與淡藍（#F0F5FA） ----------
 * Astra 的手機頁首顏色多半讀這三個變數；在手機頁首範圍內換成本站色／不加底色，個別部位再逐條寫死。 */
#masthead #ast-mobile-header {
	--ast-global-color-0: var(--gpm-ink);
	--ast-global-color-1: var(--gpm-ink);
	--ast-global-color-5: transparent;
}
/* 漢堡鈕（打開後變「×」）：圖示用選單字色、不要框、可點範圍 ≥44×44（Astra 在 769–921 只有 41.88） */
#masthead #ast-mobile-header .menu-toggle.main-header-menu-toggle:not(#_) {
	color: var(--gpm-ink) !important;
	border: 0 !important;
	background: transparent !important;
	box-sizing: border-box;
	min-width: 44px;
	min-height: 44px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}
#masthead #ast-mobile-header .menu-toggle.main-header-menu-toggle svg:not(#_),
#masthead #ast-mobile-header .menu-toggle.main-header-menu-toggle svg *:not(#_) {
	fill: currentColor !important;
}
/* 滑鼠或手指點完不留外框；鍵盤焦點才顯示（下一條） */
#masthead #ast-mobile-header :is(.menu-toggle, .ast-menu-toggle):focus:not(#_) {
	outline: none !important;
}
#masthead #ast-mobile-header :is(.menu-toggle, .ast-menu-toggle):focus-visible:not(#_) {
	outline: 2px solid var(--gpm-ink) !important;
	outline-offset: -2px;
}
/* 抽屜下緣：照抄頁首下緣那組收邊（金線＋淡陰影），讀者看得出選單在這裡結束 */
#masthead #ast-mobile-header .ast-mobile-header-content:not(#_) {
	box-shadow: 0 1px 0 0 var(--cg, #c9a060), 0 2px 8px 0 rgba(44, 36, 32, 0.06); /* 頁首 .ast-primary-header-bar 現值（2026-11-18 量） */
}

/* 鍵盤焦點：箭頭與展開鈕不是 <a>，站上的 a:focus-visible 外框管不到，補一樣的外框 */
#masthead .main-header-menu .ast-header-navigation-arrow:focus-visible:not(#_),
#masthead .main-header-menu .ast-menu-toggle:focus-visible:not(#_) {
	outline: 2px solid var(--gpm-ink) !important;
	outline-offset: -2px;
	border-radius: 2px;
}

@media (prefers-reduced-motion: reduce) {
	#masthead .main-header-menu .menu-link:not(#_),
	#masthead #ast-mobile-header .main-header-menu .ast-menu-toggle svg:not(#_) {
		transition: none !important;
	}
}
