/* =====================================================================
 * site-i18n : 右上语言切换器 + 多语言排版适配
 * 与 i18n.js 同目录；两站共用同一份，样式取中性半透明以兼容明暗两套主题
 * ===================================================================== */

/* ---------------------------------------------
 * 注意：这里曾用 `html.i18n-pending body{visibility:hidden}` 做防闪烁，
 * 已移除。原因：一旦脚本异常或主线程被占死，隐藏类不会被摘掉，整站白屏，
 * 而兜底 setTimeout 恰恰排不上队——用「可用性」换「不闪一下中文」不划算。
 * 词典是同源静态文件，闪现只有 1 帧，可以接受。
 * i18n-pending 现在只作为状态标记存在，不产生任何隐藏效果。
 * --------------------------------------------- */

.i18n-switch {
  --i18n-fg: #334155;
  --i18n-bg: rgba(255, 255, 255, .88);
  --i18n-bd: rgba(15, 23, 42, .16);
  --i18n-hover: rgba(47, 111, 224, .10);
  --i18n-menu: #ffffff;
  --i18n-shadow: 0 18px 44px -14px rgba(15, 23, 42, .32);
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  margin: 0 10px 0 12px;
  vertical-align: middle;
  z-index: 1200;
  color: var(--i18n-fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Microsoft YaHei", "Hiragino Sans", "Noto Sans", sans-serif;
  font-size: 13px;
  line-height: 1.2;
  -webkit-text-size-adjust: 100%;
}
.i18n-switch * { box-sizing: border-box; }

.i18n-switch-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  max-width: 190px;
  padding: 0 11px;
  border: 1px solid var(--i18n-bd);
  border-radius: 999px;
  background: var(--i18n-bg);
  color: inherit;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: border-color .2s, background .2s, box-shadow .2s;
}
.i18n-switch-btn:hover { border-color: rgba(47, 111, 224, .55); }
.i18n-switch-btn:focus-visible { outline: 2px solid #2f6fe0; outline-offset: 2px; }
.i18n-switch-btn > svg { width: 15px; height: 15px; flex: 0 0 auto; }
.i18n-switch-btn .i18n-caret { width: 12px; height: 12px; opacity: .65; }
.i18n-switch-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 116px;
}

.i18n-switch-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 192px;
  max-height: min(360px, 70vh);
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--i18n-bd);
  border-radius: 14px;
  background: var(--i18n-menu);
  box-shadow: var(--i18n-shadow);
  z-index: 2000;
  -webkit-overflow-scrolling: touch;
}
.i18n-switch-menu [role="option"] {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}
.i18n-switch-menu [role="option"]:hover,
.i18n-switch-menu [role="option"]:focus-visible { background: var(--i18n-hover); outline: none; }
.i18n-opt-check { opacity: 0; color: #2f6fe0; font-weight: 700; }
.i18n-switch-menu [aria-selected="true"] .i18n-opt-check { opacity: 1; }

/* 找不到页头容器时的兜底：固定右上 */
.i18n-switch.i18n-fixed { position: fixed; top: 14px; right: 16px; margin: 0; z-index: 9999; }

@media (prefers-color-scheme: dark) {
  .i18n-switch {
    --i18n-fg: #e6edf7;
    --i18n-bg: rgba(20, 28, 44, .84);
    --i18n-bd: rgba(255, 255, 255, .20);
    --i18n-hover: rgba(120, 170, 255, .16);
    --i18n-menu: #151d2c;
    --i18n-shadow: 0 18px 44px -14px rgba(0, 0, 0, .7);
  }
}

/* ---------------- 多语言排版适配 ---------------- */
/* 拉丁语系：长复合词允许折行，避免撑破固定宽卡片；只在必要时断词 */
html[lang="en"] body, html[lang="en-US"] body,
html[lang="fr"] body, html[lang="it"] body, html[lang="es"] body {
  overflow-wrap: break-word;
}

/* 日/韩：补上系统字形，避免回退到中文字形导致的字形差异 */
html[lang="ja"] body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN",
               "Hiragino Sans", "Yu Gothic", "Meiryo", "Noto Sans JP", sans-serif;
}
html[lang="ko"] body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
               "Malgun Gothic", "Noto Sans KR", sans-serif;
}
/* 简繁中文、日韩：行高略放宽，横向压缩的字更耐看 */
html[lang="zh-TW"] body, html[lang="ja"] body, html[lang="ko"] body { line-height: 1.6; }

@media (max-width: 760px) {
  .i18n-switch { margin-left: 6px; margin-right: 6px; }
  .i18n-switch-btn { height: 32px; padding: 0 9px; }
  .i18n-switch-label { max-width: 76px; }
  .i18n-switch.i18n-fixed { top: 10px; right: 10px; }
}

/* ================= 页头与按钮的多语言容纳 ================= */
/* 拉丁语系译文视觉宽度约为中文 1.8–2.2 倍，页头最容易先崩：收紧字号与间距 */
html[data-i18n-script="latin"] header .hd { gap: 20px; }
html[data-i18n-script="latin"] nav.main { gap: 16px; }
html[data-i18n-script="latin"] .nav-link { font-size: 13.5px; letter-spacing: -.01em; }
html[data-i18n-script="latin"] .nav-links { gap: clamp(10px, 1.8vw, 22px); }
html[data-i18n-script="latin"] .nav-links a { font-size: 12.5px; }

/* 按钮/胶囊文字过长时允许换行，避免溢出容器；仍保持居中 */
html[data-i18n-script="latin"] .pill,
html[data-i18n-script="latin"] .btn { white-space: normal; text-align: center; line-height: 1.25; }

/* 自我介绍气泡原本 nowrap，拉丁语系必然溢出 */
html[data-i18n-script="latin"] .mascot-bubble { white-space: normal; max-width: min(520px, 86vw); }

/* 二维码标题保留单行省略，但放宽可读宽度 */
html[data-i18n-script="latin"] .ft-qr-item .t { max-width: 120px; }

/* 导航与切换器争位：中等屏只留图标，给菜单让出空间 */
@media (max-width: 1400px) {
  .i18n-switch-label { display: none; max-width: 0; }
  .i18n-switch-btn { padding: 0 9px; gap: 4px; }
}
@media (max-width: 760px) {
  html[data-i18n-script="latin"] header .hd { gap: 14px; }
  html[data-i18n-script="latin"] nav.main { gap: 14px; }
  .i18n-switch { margin-left: 4px; margin-right: 4px; }
  .i18n-switch-btn { height: 30px; }
}
