/* YFSystem Contextual Site Translator —— 前台语言切换菜单
 *
 * 每条规则都带上切换器自己的 id。切换器要落在别人的主题里，周围是什么样式
 * 事先不知道：只用类名的话，主题里一条 .some-menu a { display: block } 就能
 * 把条目的 flex 压掉，条目一退回块级，旗帜和语言名就成了普通行内内容，再
 * 继承上主题的 text-align，每行的起点还各不相同。id 是插件自己输出的，
 * 特异性够高，主题盖不过；要自定义外观的人用 id 一样能盖过它。
 */

#yfcst-language-switch {
	position: fixed;
	top: 12px;
	right: 12px;
	z-index: 99999;
	font-size: 13px;
	line-height: 1.4;
	text-align: start;
	cursor: move;
	user-select: none;
}

#yfcst-language-switch[hidden] {
	display: none;
}

/* 挂进主题容器后就不再浮动，跟着版式走。relative 而不是 static：菜单要相对
   切换器定位，外层是 static 的话它会去找更外面的祖先，对齐和 z-index 都不作数 */
#yfcst-language-switch.is-docked {
	position: relative;
	top: auto;
	right: auto;
	cursor: default;
	display: inline-block;
}

#yfcst-language-switch .yfcst-switcher-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	width: auto;
	margin: 0;
	padding: 7px 12px;
	border: 1px solid rgba(0, 0, 0, .12);
	border-radius: 4px;
	background: #fff;
	color: #1d2327;
	font: inherit;
	line-height: 1.4;
	text-align: start;
	text-transform: none;
	cursor: pointer;
	box-shadow: 0 1px 3px rgba(0, 0, 0, .12);
}

#yfcst-language-switch.is-docked .yfcst-switcher-btn {
	box-shadow: none;
}

#yfcst-language-switch .yfcst-switcher-btn:hover {
	background: #f6f7f7;
}

#yfcst-language-switch .yfcst-switcher-caret {
	font-size: 10px;
	opacity: .6;
}

/* 旗帜图标：高度按原图比例走，不同国旗高度不一，写死会变形 */
#yfcst-language-switch .yfcst-switcher-flag {
	display: inline-block;
	width: 22px;
	height: auto;
	max-width: none;
	margin: 0;
	padding: 0;
	vertical-align: middle;
	border: 0;
	border-radius: 2px;
	box-shadow: none;
	flex: 0 0 auto;
}

/* 菜单自己也要有 z-index：主题容器里的层叠上下文未必轮得到外层那条 */
#yfcst-language-switch .yfcst-switcher-menu {
	display: none;
	position: absolute;
	z-index: 99999;
	top: calc(100% + 4px);
	/* 与按钮左对齐：按钮上的当前语言和菜单里的条目就在同一列上 */
	left: 0;
	/* 宽度按最长的那一项走。下面的 overflow-y 让菜单成了滚动容器，滚动容器的
	   最小内容宽度算作 0，绝对定位元素的收缩宽度也就不再看内容，只会退到按钮
	   那么宽，长一点的语言名被挤出一条横向滚动条。所以显式要 max-content，
	   再用 max-width 兜住极端情况，够不着的那部分省略号收尾。 */
	width: max-content;
	min-width: 100%;
	max-width: min(280px, calc(100vw - 24px));
	max-height: 320px;
	overflow-x: hidden;
	overflow-y: auto;
	/* 语言多到要竖向滚动时，经典滚动条（Windows 上是 15px）会从算好的宽度里
	   抢走一条，内容被挤出去就又冒出一条横向滚动条。预留出这条位置，宽度里
	   就一并算上了；浏览器不认这个属性时，上面的 overflow-x 兜底。 */
	scrollbar-gutter: stable;
	margin: 0;
	padding: 0;
	list-style: none;
	background: #fff;
	border: 1px solid rgba(0, 0, 0, .12);
	border-radius: 4px;
	box-shadow: 0 4px 12px rgba(0, 0, 0, .15);
}

#yfcst-language-switch.is-open .yfcst-switcher-menu {
	display: block;
}

/* 右边放不下整个菜单时（默认位置就在右上角）改成右对齐，向左展开 */
#yfcst-language-switch.is-flipped .yfcst-switcher-menu {
	left: auto;
	right: 0;
}

#yfcst-language-switch .yfcst-switcher-item {
	display: flex;
	align-items: center;
	justify-content: flex-start;
	/* 左内边距和图标间距跟按钮一致，菜单展开后旗帜与语言名接着按钮那一列往下走。
	   text-align 是给主题的继承值兜底的：万一 flex 没站住，行内内容也从头排起 */
	gap: 6px;
	width: auto;
	margin: 0;
	padding: 8px 12px;
	color: #1d2327;
	font: inherit;
	text-align: start;
	text-decoration: none;
	text-transform: none;
	white-space: nowrap;
	border: 0;
}

/* 语言名超出菜单最大宽度时省略，不要顶出横向滚动条。
   flex 子项默认 min-width:auto 不肯收缩，得显式放开。 */
#yfcst-language-switch .yfcst-switcher-item > span {
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
}

#yfcst-language-switch .yfcst-switcher-item:hover,
#yfcst-language-switch .yfcst-switcher-item:focus {
	background: #f0f0f1;
	color: #135e96;
	text-decoration: none;
}

#yfcst-language-switch .yfcst-switcher-item.is-active {
	font-weight: 600;
	background: #f6f7f7;
}

@media screen and (max-width: 768px) {
	/* 小屏不给拖，固定在角落，免得挡住内容又找不回来 */
	#yfcst-language-switch:not(.is-docked) {
		top: auto !important;
		left: auto !important;
		right: 10px !important;
		bottom: 10px;
		cursor: default;
	}

	#yfcst-language-switch:not(.is-docked) .yfcst-switcher-menu {
		top: auto;
		bottom: calc(100% + 4px);
	}
}
