/* 从右往左的语言 (fa / ar, <html dir="rtl">, 见 utils/siteLocale.ts)。
   布局本身靠逻辑属性 (margin-inline-start 等) 自动翻转, 这里只放逻辑属性管不到的部分; 只在 [dir="rtl"] 下生效,
   简繁英与其他从左往右的语言不受影响。 */

/* 字体: Google Sans 没有阿拉伯字母, 阿拉伯字母用自托管的 Noto Sans Arabic (app.vue 按语言加载, 只含阿拉伯字母子集);
   字体未到之前或加载失败时用系统字体 (Windows Tahoma / Segoe UI, macOS / iOS Geeza Pro)。结果卡 .ip-overview 自己写了字体栈, 一并覆盖 */
[dir="rtl"] body,
html[dir="rtl"] .ip-overview {
  font-family: "Google Sans", "Noto Sans Arabic", Tahoma, "Segoe UI", "Geeza Pro", "Noto Naskh Arabic", -apple-system, BlinkMacSystemFont, sans-serif;
}

/* 有方向含义的图标 (前进 / 返回 / 外链箭头) 镜像; 上下方向与刷新类图标不动 */
[dir="rtl"] :is(.fa-arrow-right, .fa-arrow-left, .fa-chevron-right, .fa-chevron-left, .fa-angle-right, .fa-angle-left,
  .fa-angles-right, .fa-angles-left, .fa-caret-right, .fa-caret-left, .fa-arrow-right-long, .fa-arrow-left-long,
  .fa-arrow-up-right-from-square, .fa-arrow-right-from-bracket, .fa-arrow-right-to-bracket, .fa-share, .fa-reply) {
  transform: scaleX(-1);
}

/* IP、CIDR、域名、命令、代码一律按从左往右显示, 不被周围的波斯语 / 阿拉伯语打乱顺序 (如 1.2.3.0/24 被排成 24/1.2.3.0) */
[dir="rtl"] :is(code, kbd, samp, pre, .font-mono, .mono, [translate="no"]) {
  direction: ltr;
  unicode-bidi: isolate;
}
[dir="rtl"] pre {
  text-align: start;
}

/* 输入框里的 IP / 域名 / 邮箱同样从左往右输入 */
[dir="rtl"] :is(input[type="email"], input[type="url"], input[inputmode="url"], input[inputmode="numeric"], input[name*="ip" i], input[placeholder*="."]) {
  direction: ltr;
  text-align: end;
}

/* 数轴、刻度、时间线、路径图: 刻度与标记用内联 left:% / px 定位, 按数值从小到大从左往右画,
   整块保持从左往右 (与常见的阿拉伯语 / 波斯语图表一致), 否则 flex 色段翻转而刻度不翻、两者对不上 */
[dir="rtl"] :is(.grade-scale, .ipr-ruler, .rd-axis, .k-ticks, .plv-score__bar, .ocard__tl, .otl, .bpg, .score-track, .purity-trend__chart) {
  direction: ltr;
}

/* 截断显示的单行数据 (机构名、ASN 名称、主机名) 多是英文: 按内容首个强字符定方向,
   避免 "NTT America, Inc." 在从右往左的单元格里显示成 ".NTT America, Inc" */
[dir="rtl"] .truncate {
  unicode-bidi: plaintext;
}

/* 日语、韩语、泰语的字体 (按 <html lang>, 见 utils/siteLocale.ts)。
   全站字体栈在 Google Sans 之后接的是简体中文字体 (main.css), 日语页的汉字会显示成中文字形、韩文落到不合适的回退字体;
   日语、韩语在 Google Sans (拉丁字母、数字) 之后换成该语言的系统字体。
   泰文用自托管的 Noto Sans Thai (app.vue 按语言加载, 只含泰文子集), 放在 Google Sans 前面, 否则泰文会用 Google Sans 自带的泰文字形;
   拉丁字母和数字仍落到 Google Sans; 结果卡 .ip-overview 自己写了字体栈, 一并覆盖。其他语言不受影响。 */
html:lang(ja) body {
  font-family: "Google Sans", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", Meiryo, "Noto Sans JP", "Noto Sans CJK JP", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html:lang(ko) body {
  font-family: "Google Sans", "Apple SD Gothic Neo", "Malgun Gothic", "맑은 고딕", "Noto Sans KR", "Noto Sans CJK KR", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html:lang(th) body,
html:lang(th) .ip-overview {
  font-family: "Noto Sans Thai", "Google Sans", Thonburi, "Leelawadee UI", Leelawadee, Tahoma, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
