/* Pipsly languages (shared/js/i18n.js): the globe button, the picker, fonts per script, right-to-left.
   Edit the copy in shared/css, then run:  node scripts/sync-shared.mjs */

/* the site waits a moment for its words (never longer than 1.2 s) */
html.i18n-wait body { opacity: 0; }
html body { transition: opacity .2s var(--ease-out); }

/* ---- scripts without Latin letters: system fonts that have them; no italics or letter-spacing that break them ---- */
:root:lang(zh-Hans) { --font: Inter, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Noto Sans CJK SC", sans-serif; }
:root:lang(zh-Hant) { --font: Inter, "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", "Noto Sans CJK TC", sans-serif; }
:root:lang(ja) { --font: Inter, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, "Noto Sans JP", sans-serif; }
:root:lang(ko) { --font: Inter, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif; }
:root:lang(th) { --font: Inter, Thonburi, "Leelawadee UI", "Noto Sans Thai", Tahoma, sans-serif; }
:root:lang(ar) { --font: Inter, "SF Arabic", "Geeza Pro", "Segoe UI", "Noto Sans Arabic", Tahoma, sans-serif; }
:root:lang(hi) { --font: Inter, "Kohinoor Devanagari", "Nirmala UI", "Noto Sans Devanagari", Mangal, sans-serif; }
:root:is(:lang(zh-Hans), :lang(zh-Hant), :lang(ja), :lang(ko), :lang(th), :lang(ar), :lang(hi)) { --font-display: var(--font); }
:root:is(:lang(zh-Hans), :lang(zh-Hant), :lang(ja), :lang(ko), :lang(th), :lang(ar), :lang(hi)) :is(h1, h2, h3) em { font-style: normal; }
:root:is(:lang(ar), :lang(hi), :lang(th)) body :not(.num):not(.num *) { letter-spacing: 0 !important; }
:root:is(:lang(zh-Hans), :lang(zh-Hant), :lang(ja), :lang(ko)) body { word-break: normal; line-break: strict; }

/* numbers, prices and account numbers always read left to right, also inside Arabic text */
[dir="rtl"] .num, [dir="rtl"] input[inputmode="decimal"], [dir="rtl"] input[inputmode="numeric"] { direction: ltr; unicode-bidi: isolate; }
[dir="rtl"] .num { text-align: inherit; }
[dir="rtl"] .seg-pill { left: auto; right: 3px; transform: translateX(calc(var(--i) * -100%)); }

/* ---- the globe button ---- */
.lang-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 12px; border-radius: var(--r-pill);
  border: 1px solid var(--line-2); background: rgba(10, 10, 10, .42); color: var(--fg); font: 600 13px/1 var(--font); letter-spacing: .04em;
  cursor: pointer; -webkit-tap-highlight-color: transparent; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  transition: transform var(--t-fast) var(--ease-out), border-color var(--t-base) var(--ease-out), background var(--t-base) var(--ease-out); }
.lang-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; flex: none; }
.lang-btn:hover { border-color: rgba(255, 255, 255, .28); background: rgba(26, 28, 31, .7); }
.lang-btn:active { transform: scale(var(--press)); }
.lang-btn:focus-visible, .lg button:focus-visible, .lg input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- the picker: a bottom sheet on phones, a popover on computers ---- */
.lg-wrap { position: fixed; inset: 0; z-index: 2147483000; }
.lg-wrap[hidden] { display: none; }
.lg-scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); opacity: 0; transition: opacity var(--t-slow) var(--ease-out); }
.lg-wrap:not(.lg-sheet) .lg-scrim { background: transparent; }
.lg-wrap.lg-in .lg-scrim { opacity: 1; }
.lg { position: absolute; width: min(340px, calc(100vw - 24px)); max-height: min(520px, calc(100dvh - 24px)); display: flex; flex-direction: column;
  border-radius: 18px; border: 1px solid var(--line-2); color: var(--fg); font-family: var(--font);
  background: linear-gradient(180deg, rgba(30, 32, 35, .96), rgba(14, 15, 17, .97)); box-shadow: 0 24px 70px rgba(0, 0, 0, .6), inset 0 1px 0 rgba(255, 255, 255, .06);
  backdrop-filter: blur(18px) saturate(1.2); -webkit-backdrop-filter: blur(18px) saturate(1.2);
  opacity: 0; transform: translate3d(0, -6px, 0) scale(.97); transition: opacity var(--t-base) var(--ease-out), transform var(--t-slow) var(--ease-out); }
.lg-wrap.lg-in .lg { opacity: 1; transform: none; }
.lg-wrap.lg-sheet .lg { left: 0; right: 0; bottom: 0; top: auto; width: auto; max-height: min(82dvh, 640px); border-radius: 22px 22px 0 0; border-bottom: 0;
  padding-bottom: var(--safe-b); opacity: 1; transform: translate3d(0, 104%, 0); transition: transform 420ms var(--ease-out); }
.lg-wrap.lg-sheet.lg-in .lg { transform: none; }
.lg-grab { display: none; width: 38px; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .22); margin: 10px auto 0; flex: none; }
.lg-wrap.lg-sheet .lg-grab { display: block; }
.lg-head { display: flex; align-items: center; gap: 10px; padding: 14px 14px 6px 18px; flex: none; }
.lg-head h2 { margin: 0; flex: 1; font: 600 17px/1.2 var(--font); letter-spacing: -.01em; }
.lg-globe svg { width: 20px; height: 20px; fill: none; stroke: var(--chrome); stroke-width: 1.5; display: block; }
.lg-x { width: 36px; height: 36px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .06); color: var(--fg-2); display: grid; place-items: center; cursor: pointer; }
.lg-x svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.lg-search { position: relative; display: block; margin: 6px 14px 8px; flex: none; }
.lg-search svg { position: absolute; inset-inline-start: 12px; top: 50%; width: 17px; height: 17px; transform: translateY(-50%); fill: none; stroke: var(--muted); stroke-width: 1.7; stroke-linecap: round; pointer-events: none; }
.lg-search input { width: 100%; box-sizing: border-box; height: 44px; padding: 0 12px; padding-inline-start: 38px; border-radius: 12px;
  border: 1px solid var(--line-2); background: var(--bg-sunk); color: var(--fg); font: 16px/1.2 var(--font); outline: none; -webkit-appearance: none; appearance: none; }
.lg-search input::-webkit-search-cancel-button { filter: invert(1) grayscale(1) opacity(.6); }
.lg-search input:focus { border-color: rgba(255, 255, 255, .3); }
.lg-list { list-style: none; margin: 0; padding: 2px 8px 10px; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.lg-list li { margin: 0; }
.lg-list button { width: 100%; min-height: 50px; display: grid; grid-template-columns: 1fr auto 22px; align-items: center; gap: 10px; padding: 8px 12px;
  border: 0; border-radius: 12px; background: transparent; color: var(--fg); text-align: start; cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: background var(--t-base) var(--ease-out), transform var(--t-fast) var(--ease-out); }
.lg-list button:hover, .lg-list button:focus-visible { background: rgba(255, 255, 255, .055); }
.lg-list button:active { transform: scale(.985); }
.lg-name { font: 500 16px/1.25 var(--font); overflow-wrap: anywhere; }
.lg-en { font: 13px/1.2 var(--font); color: var(--muted); white-space: nowrap; }
.lg-check { width: 20px; height: 20px; fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 24; stroke-dashoffset: 24; opacity: 0; transition: stroke-dashoffset var(--t-slow) var(--ease-out), opacity var(--t-fast) linear; }
.lg-list li.lg-on button { background: rgba(255, 255, 255, .08); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .1); }
.lg-list li.lg-on .lg-name { font-weight: 650; }
.lg-list li.lg-on .lg-check { stroke-dashoffset: 0; opacity: 1; }
.lg-list li.lg-busy .lg-check { opacity: 1; stroke-dasharray: 8 16; animation: lgSpin .8s linear infinite; transform-origin: 50% 50%; }
.lg-list li.lg-fail button { animation: lgNo .36s var(--ease-out); }
.lg-none { padding: 18px 12px; color: var(--muted); font-size: 14px; text-align: center; }
@keyframes lgSpin { to { transform: rotate(360deg); } }
@keyframes lgNo { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
@media (prefers-reduced-motion: reduce) {
  .lg, .lg-wrap.lg-sheet .lg { transform: none !important; transition: opacity var(--t-base) linear; }
  .lg-wrap.lg-sheet .lg { opacity: 0; }
  .lg-wrap.lg-sheet.lg-in .lg { opacity: 1; }
  .lg-check, .lg-list button { transition: none; }
  .lg-list li.lg-busy .lg-check { animation: none; }
}
