/**
 * i18n 语言切换器样式。
 * 之前由 i18n.js 通过 createElement("style") 动态注入；
 * 但 CSP `style-src 'self'` 不带 `unsafe-inline`，浏览器会静默丢弃。
 * 改成静态 CSS 文件由各 HTML 显式 <link>，符合 self 源策略。
 */

.i18n-switcher {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 12px;
}

body > header:first-child {
  padding-right: 92px;
}

.i18n-switcher-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--px-border, #cbd3cc);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  color: var(--px-ink, #151916);
  cursor: pointer;
  line-height: 1;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.i18n-switcher-btn:hover {
  border-color: var(--px-primary, #163f2d);
  background: #ffffff;
  color: var(--px-primary, #163f2d);
}

.i18n-switcher-btn svg {
  width: 13px;
  height: 13px;
  opacity: 0.8;
}

.i18n-switcher-caret {
  font-size: 10px;
  opacity: 0.7;
}

.i18n-switcher-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 128px;
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--px-border, #cbd3cc);
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(12px);
  box-shadow: var(--px-shadow, 0 8px 28px rgba(21, 25, 22, 0.08));
  display: none;
}

.i18n-switcher[data-open="true"] .i18n-switcher-menu {
  display: block;
}

.i18n-switcher-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border-radius: 6px;
  border: 0;
  background: transparent;
  color: var(--px-ink, #151916);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.i18n-switcher-item:hover {
  background: var(--px-bg, #f5f7f4);
  color: var(--px-primary, #163f2d);
}

.i18n-switcher-item[aria-current="true"] {
  color: var(--px-accent, #dd4f37);
}

.i18n-switcher-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0;
}

.i18n-switcher-item[aria-current="true"] .i18n-switcher-dot {
  opacity: 1;
}

/**
 * i18n cloak: 仅在切换语言瞬间避免出现"先英后中"的闪烁；JS 动态注入因 CSP 失效。
 * 这里改用 [data-i18n-cloak] 选择器：i18n.js 在 documentElement 上加属性，
 * 1.2s 后移除（无论 i18n 加载是否完成都不再卡）。
 */
html[data-i18n-cloak="1"] body {
  opacity: 0 !important;
}

@media (max-width: 480px) {
  .i18n-switcher {
    top: 12px;
    right: 12px;
  }
}
