/*
 * 复刻页补丁层 —— 只做四件事：
 * 1. 让平台切换的分组容器在布局上"透明"，不打断原站 .download-app / .download-img 的 flex 结构
 * 2. 补齐原站由 Vue 运行时注入、静态页拿不到的一点收尾样式
 * 3. 多语言相关：首屏防闪烁、当前语言高亮、RTL 兜底
 * 4. 移动端抽屉菜单（汉堡按钮 → 整屏菜单 → 语言切换在最后一项）
 * 规则一律排在原站 CSS 之后加载，保证覆盖生效。
 */

/* 平台分组容器：不产生盒子，子元素直接参与父级 flex */
.platform-panel {
  display: contents;
}

/* 分组容器被 JS 置为 none 时，优先级要压过 display:contents */
.platform-panel[style*="display: none"] {
  display: none !important;
}

/* 描述区的站点地址：原站由 JS 填入当前域名，这里保证不换行挤压 */
.description-content .website .text[data-site-url] {
  white-space: nowrap;
}

/* ───────────────────────── 多语言 ───────────────────────── */

/*
 * 首屏防闪烁：识别出非中文时先藏内容，等 i18n.js 把文本替换完再显示。
 * head 里的预置脚本会在 1500ms 后兜底摘掉这个类，脚本失效也不会白屏。
 */
html.i18n-pending body {
  visibility: hidden;
}

/* 语言菜单当前项高亮 */
.nav-children-item.locale-active,
.nav-children-item .locale-active {
  color: #2980fe;
  font-weight: 600;
}

/* 语言项可点击 / 可键盘聚焦 */
.nav-children-item [data-locale] {
  cursor: pointer;
}

/* 大菜单里的语言格：15 种语言按 5 列排，避免挤成两行 */
.navbar-wrap-child-content-wrap .navbar-wrap-child-item:last-child .nav-child-right {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px 12px;
}

/* 语言名较长时（Bahasa Indonesia / Bahasa Melayu）不折行 */
.nav-children-item .nav-text {
  white-space: nowrap;
}

/*
 * RTL（乌尔都语）：原站 CSS 里已有 [dir=rtl] 规则，
 * 这里只兜底几个静态页特有的内联布局，避免文字压到图标上。
 */
[dir="rtl"] .description-content .website .text[data-site-url],
[dir="rtl"] .version-text {
  direction: ltr;
  unicode-bidi: embed;
}

[dir="rtl"] .download-title,
[dir="rtl"] .download-text {
  text-align: right;
}

/* 语言下拉：15 项在窄屏上会超出视口，给它一个最大高度可滚动 */
.navbar-tab-list .nav-title.nav-language .nav-children-wrap {
  max-height: 60vh;
  overflow-y: auto;
}

/* ══════════════════════════════════════════════════════════════════
   移动端抽屉菜单
   ──────────────────────────────────────────────────────────────────
   原站结构：右上角汉堡（三个杠）→ 点开整屏抽屉 → 语言是抽屉里最后一项。
   静态页里 <tp-mini-navbar> 是 Vue 组件、快照里没有内容，
   所以抽屉换成静态 HTML（.tp-drawer）由 index.html 直接输出。
   ══════════════════════════════════════════════════════════════════ */

/* ── 右上角汉堡按钮 ──────────────────────────────────────────── */

/* 原站 `.mini-navbar-header div{flex:1}` 会把右侧撑开，这里定宽贴右 */
.mini-navbar-header .menu-status {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex: 0 0 auto;
}

[dir="ltr"] .mini-navbar-header .menu-status { margin-right: 15px; }
[dir="rtl"] .mini-navbar-header .menu-status { margin-left: 15px; }

.tp-menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;              /* 44px 是最小舒适点击区 */
  height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-23, #3a3b3d);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.tp-menu-btn svg {
  display: block;
  pointer-events: none;
}

/* 默认显示三个杠，抽屉打开时换成 X */
.tp-menu-btn .tp-menu-close { display: none; }
body.tp-drawer-open .tp-menu-btn .tp-menu-bars { display: none; }
body.tp-drawer-open .tp-menu-btn .tp-menu-close { display: block; }

/* ── 抽屉本体 ────────────────────────────────────────────────── */

.tp-drawer {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100000;            /* 压过原站 .isFixed 的 99999 */
  background: var(--bg-1, #fff);
  color: var(--color-23, #3a3b3d);
  overflow: hidden;
  -webkit-overflow-scrolling: touch;
}

.tp-drawer.tp-drawer--open {
  display: block;
}

/* 抽屉容器自己接收焦点（脚本 focus 用），不要画焦点环 */
.tp-drawer:focus {
  outline: none;
}

/* 打开抽屉时锁住页面滚动 */
body.tp-drawer-open {
  overflow: hidden;
}

/* 每个面板都是一屏，子面板从右侧滑入 */
.tp-drawer-panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-1, #fff);
  transform: translateX(100%);
  transition: transform .26s cubic-bezier(.4, 0, .2, 1);
  will-change: transform;
}

.tp-drawer-panel--active {
  transform: translateX(0);
}

/* 子面板滑入时，根面板往左让一截，形成层级感 */
.tp-drawer-panel--behind {
  transform: translateX(-24%);
}

/* ── 焦点样式：鼠标点出来不画焦点环，键盘 Tab 才画 ─────────────── */

.tp-drawer :focus {
  outline: none;
}

.tp-drawer :focus-visible {
  outline: 2px solid #2980fe;
  outline-offset: 2px;
  border-radius: 8px;
}

/* 抽屉头部图标按钮不需要圆角焦点框 */
.tp-drawer .tp-drawer-close:focus-visible,
.tp-drawer .tp-drawer-back:focus-visible,
.tp-drawer .tp-menu-btn:focus-visible {
  outline-offset: -2px;
  border-radius: 10px;
}

/* ── 面板头部：logo + 关闭 / 返回 + 标题 ─────────────────────── */

.tp-drawer-head {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  height: 64px;
  padding: 0 16px;
  gap: 12px;
}

.tp-drawer-logo {
  width: 156px;
  height: auto;
  display: block;
}

.tp-drawer-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin: 0 0 0 auto;
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-23, #3a3b3d);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

[dir="rtl"] .tp-drawer-close {
  margin: 0 auto 0 0;
}

.tp-drawer-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-23, #3a3b3d);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.tp-drawer-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--color-23, #3a3b3d);
}

/* ── 菜单列表 ────────────────────────────────────────────────── */

.tp-drawer-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px 16px 32px;
  -webkit-overflow-scrolling: touch;
}

.tp-drawer-item {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  min-height: 56px;
  padding: 10px 0;
  margin: 0;
  border: 0;
  border-radius: 10px;
  background: none;
  font-family: inherit;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.3;
  text-align: start;
  text-decoration: none;
  color: var(--color-23, #3a3b3d);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.tp-drawer-item:active {
  background: rgba(41, 128, 254, .06);
}

/* 图标固定 24px，不参与压缩 */
.tp-drawer-ico {
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  color: var(--color-23, #3a3b3d);
}

.tp-drawer-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 右侧箭头 */
.tp-drawer-arrow {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  color: var(--color-17, #c0c3c6);
}

.tp-drawer-arrow svg {
  width: 18px;
  height: 18px;
}

[dir="rtl"] .tp-drawer-arrow svg {
  transform: scaleX(-1);
}

/* 子面板里字号略小，条目更密 */
.tp-drawer-body--sub .tp-drawer-item {
  min-height: 52px;
  font-size: 16px;
  font-weight: 500;
}

/* 语言项：当前语言高亮 + 勾 */
.tp-drawer-item--lang {
  font-weight: 500;
}

.tp-drawer-item--lang.locale-active {
  color: #2980fe;
  font-weight: 600;
}

/* ── 暗黑模式开关 ────────────────────────────────────────────── */

.tp-drawer-item--switch {
  cursor: pointer;
}

.tp-switch {
  position: relative;
  flex: 0 0 auto;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: #e5e5ea;
  transition: background .2s ease;
}

.tp-switch i {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
  transition: transform .2s ease;
}

[dir="rtl"] .tp-switch i {
  left: auto;
  right: 3px;
}

.tp-drawer-item--switch[aria-checked="true"] .tp-switch {
  background: #2980fe;
}

.tp-drawer-item--switch[aria-checked="true"] .tp-switch i {
  transform: translateX(20px);
}

[dir="rtl"] .tp-drawer-item--switch[aria-checked="true"] .tp-switch i {
  transform: translateX(-20px);
}

/* ── 暗色主题下的抽屉配色 ────────────────────────────────────── */

html[theme="dark"] .tp-drawer,
html[theme="dark"] .tp-drawer-panel {
  background: var(--bg-1, #0b0b0c);
}

html[theme="dark"] .tp-switch {
  background: #3a3a3c;
}

/* 抽屉只在移动/窄屏导航下有意义（原站 ≤1300px 才显示 mini-nav） */
@media screen and (min-width: 1301px) {
  .tp-drawer {
    display: none !important;
  }
}

/* 小屏收紧一点间距 */
@media screen and (max-width: 420px) {
  .tp-drawer-head { height: 58px; padding: 0 14px; }
  .tp-drawer-logo { width: 140px; }
  .tp-drawer-body { padding: 6px 14px 28px; }
  .tp-drawer-item { font-size: 16px; min-height: 52px; gap: 14px; }
}

@media (max-width: 768px) {
  .navbar-wrap-child-content-wrap .navbar-wrap-child-item:last-child .nav-child-right {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
