/* =====================================================================================================================
   NeuroShrub — language, script and direction support.
   Loaded last on every page. <html> carries lang, dir and data-script (latin, cyrillic, arabic, hebrew, hans, hant,
   japanese, korean, devanagari, bengali, thai). Fonts are OFL families served from this site (css/fonts/*.css, files under
   lib/fontsource; never a third-party font host): base.css on every page plus the active language's script stylesheet
   (see ScriptFonts), with system fallbacks that cover every glyph. Chinese, Japanese and Korean use the system CJK fonts
   (Windows, macOS/iOS, Android/ChromeOS, Linux names in that order); no CJK web font is shipped.
   ===================================================================================================================== */

/* ---------- Font stacks per writing system ---------- */
html[data-script="cyrillic"] {
    --ai-font-display: "Exo 2", "Chakra Petch", "Segoe UI", system-ui, sans-serif;
}
html[lang="ar"] {
    --ai-font-body: "Noto Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
    --ai-font-display: "Noto Kufi Arabic", "Noto Sans Arabic", "Segoe UI", Tahoma, sans-serif;
}
html[lang="fa"] {
    --ai-font-body: "Vazirmatn", "Noto Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
    --ai-font-display: "Vazirmatn", "Noto Sans Arabic", "Segoe UI", Tahoma, sans-serif;
}
html[lang="ur"] {
    --ai-font-body: "Noto Nastaliq Urdu", "Noto Sans Arabic", "Segoe UI", Tahoma, sans-serif;
    --ai-font-display: "Noto Sans Arabic", "Noto Nastaliq Urdu", "Segoe UI", Tahoma, sans-serif;
}
html[data-script="hebrew"] {
    --ai-font-body: "Noto Sans Hebrew", "Segoe UI", Arial, system-ui, sans-serif;
    --ai-font-display: "Rubik", "Noto Sans Hebrew", "Segoe UI", Arial, sans-serif;
}
/* CJK: system fonts only. Each stack names the platform UI font (macOS/iOS, Windows), then the Noto/Source Han CJK families
   that Android, ChromeOS and Linux install under either name, then the generic families. Latin text inside CJK pages uses the
   same fonts (they include Latin glyphs designed to match). */
html[data-script="hans"] {
    --ai-font-body: "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", "Source Han Sans SC", "Source Han Sans CN", system-ui, sans-serif;
    --ai-font-display: "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", "Source Han Sans SC", system-ui, sans-serif;
}
html[data-script="hant"] {
    --ai-font-body: "PingFang TC", "Microsoft JhengHei UI", "Microsoft JhengHei", "Noto Sans CJK TC", "Noto Sans TC", "Source Han Sans TC", "Source Han Sans TW", system-ui, sans-serif;
    --ai-font-display: "PingFang TC", "Microsoft JhengHei UI", "Microsoft JhengHei", "Noto Sans CJK TC", "Noto Sans TC", "Source Han Sans TC", system-ui, sans-serif;
}
html[data-script="japanese"] {
    --ai-font-body: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", "Noto Sans CJK JP", "Noto Sans JP", "Source Han Sans JP", system-ui, sans-serif;
    --ai-font-display: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", "Noto Sans CJK JP", "Noto Sans JP", "Source Han Sans JP", system-ui, sans-serif;
}
html[data-script="korean"] {
    --ai-font-body: "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans CJK KR", "Noto Sans KR", "Source Han Sans KR", "Nanum Gothic", system-ui, sans-serif;
    --ai-font-display: "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans CJK KR", "Noto Sans KR", "Source Han Sans KR", "Nanum Gothic", system-ui, sans-serif;
}
html[data-script="devanagari"] {
    --ai-font-body: "Noto Sans Devanagari", "Nirmala UI", "Mangal", system-ui, sans-serif;
    --ai-font-display: "Rajdhani", "Noto Sans Devanagari", "Nirmala UI", sans-serif;
}
html[data-script="bengali"] {
    --ai-font-body: "Noto Sans Bengali", "Nirmala UI", "Vrinda", system-ui, sans-serif;
    --ai-font-display: "Noto Sans Bengali", "Nirmala UI", sans-serif;
}
html[data-script="thai"] {
    --ai-font-body: "Noto Sans Thai", "Leelawadee UI", "Tahoma", system-ui, sans-serif;
    --ai-font-display: "Chakra Petch", "Noto Sans Thai", "Leelawadee UI", sans-serif;
}
/* Bootstrap reads its own variables; keep them in step with the theme tokens. */
html:not([data-script="latin"]) {
    --bs-body-font-family: var(--ai-font-body);
    --bs-font-sans-serif: var(--ai-font-body);
}

/* ---------- Case and tracking ----------
   Uppercase labels and wide letter spacing belong to Latin and Cyrillic. Scripts without letter case, and scripts whose
   letters join or stack (Arabic, Devanagari, Bengali, Thai), keep their natural shapes: no tracking, no forced case. */
html:not([data-script="latin"]):not([data-script="cyrillic"]) * {
    letter-spacing: normal !important;
    text-transform: none !important;
}
/* Tiny uppercase labels are sized for Latin capitals; give complex scripts a readable minimum. */
html:not([data-script="latin"]):not([data-script="cyrillic"]) :is(.ai-kicker, .ai-specs dt, .hud-label, .ai-level__label, .kpi-label,
    .admin-nav-heading, .ai-tier, .ns-loader__word, .contract__ref, .footer-heading, .wallet-tag, .badge, .small, small) {
    font-size: max(.78rem, 1em);
}
html[data-script="hans"], html[data-script="hant"], html[data-script="japanese"], html[data-script="korean"] {
    line-break: strict;
    word-break: normal;
}
html[data-script="hans"] body, html[data-script="hant"] body, html[data-script="japanese"] body, html[data-script="korean"] body { line-height: 1.7; }
html[data-script="devanagari"] body, html[data-script="bengali"] body, html[data-script="thai"] body { line-height: 1.75; }
html[lang="ur"] body { line-height: 2.05; }
html[lang="ur"] :is(h1, h2, h3, h4, .h1, .h2, .h3, .h4, .display-1, .display-2, .display-3, .display-4) { line-height: 1.75; }
html[data-script="arabic"] :is(h1, h2, h3, h4, .h1, .h2, .h3, .h4), html[data-script="devanagari"] :is(h1, h2, h3, h4) { line-height: 1.45; }

/* The product name is a Latin wordmark in every language. */
.brand-word, [lang="en"].brand-word { font-family: "Chakra Petch", "Segoe UI", system-ui, sans-serif; letter-spacing: .03em !important; }

/* Long words (German, Russian) must wrap instead of overflowing cards and buttons. */
.card, .ai-resource, .contract, .lang-option, .btn, .nav-link, .dropdown-item, td, th, .ai-toast { overflow-wrap: break-word; }

/* ---------- Right-to-left ---------- */
/* Technical values stay left-to-right on RTL pages: addresses, hashes, codes, emails, URLs, numbers. */
[dir="rtl"] :is(code, kbd, samp, pre, .font-monospace, .ltr, input[type="email"], input[type="url"], input[type="number"],
    input[inputmode="decimal"], input[inputmode="numeric"], .addr, .tx-hash, .referral-code) {
    direction: ltr;
    unicode-bidi: isolate;
}
[dir="rtl"] :is(input[type="email"], input[type="url"], input[type="number"], .ltr-input) { text-align: start; }
/* Directional icons point the reading direction. Logos, art and the AI core are never mirrored. */
[dir="rtl"] :is(.bi-arrow-right, .bi-arrow-left, .bi-chevron-right, .bi-chevron-left, .bi-arrow-right-short, .bi-arrow-left-short,
    .bi-box-arrow-right, .bi-box-arrow-in-right, .bi-arrow-right-circle, .bi-caret-right-fill, .bi-reply, .bi-send)::before {
    display: inline-block;
    transform: scaleX(-1);
}
[dir="rtl"] .toast-container.end-0 { right: auto !important; left: 0 !important; }
[dir="rtl"] .form-select { background-position: left .75rem center; }
[dir="rtl"] .btn-close { margin-inline-start: auto; margin-inline-end: 0; }

/* ---------- Language picker ---------- */
.lang-button { display: inline-flex; align-items: center; gap: .35rem; font-family: var(--ai-font-display); font-weight: 600; letter-spacing: .04em; }
.lang-modal .modal-content { background: var(--ai-panel-elevated); border: 1px solid var(--ai-border); }
.lang-picker__search { position: relative; margin-bottom: 1rem; }
.lang-picker__search .bi-search { position: absolute; inset-inline-start: .8rem; top: 50%; transform: translateY(-50%); color: var(--ai-text-muted); pointer-events: none; }
.lang-picker__search .form-control { padding-inline-start: 2.3rem; }
.lang-group + .lang-group { margin-top: 1.1rem; }
.lang-group__title { font-family: var(--ai-font-display); font-size: .74rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--ai-violet-soft); margin-bottom: .5rem; }
.lang-group__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: .45rem; }
.lang-option {
    position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: .05rem; width: 100%;
    padding: .55rem .8rem; text-align: start; color: var(--ai-text); background: rgba(13, 9, 24, .6);
    border: 1px solid var(--ai-border-soft, var(--ai-border)); border-radius: 4px; transition: border-color .15s, background-color .15s;
}
.lang-option:hover, .lang-option:focus-visible { border-color: var(--ai-violet-soft); background: rgba(124, 58, 237, .14); outline: none; }
.lang-option:focus-visible { box-shadow: 0 0 0 2px var(--ai-violet-soft); }
.lang-option.is-current { border-color: var(--ai-violet-bright); background: rgba(124, 58, 237, .22); }
.lang-option__native { font-weight: 600; font-size: 1rem; }
.lang-option__local { font-size: .78rem; color: var(--ai-text-muted); }
.lang-option__check { position: absolute; inset-inline-end: .65rem; top: 50%; transform: translateY(-50%); color: var(--ai-violet-soft); }
.lang-option[hidden], .lang-group[hidden] { display: none; }
.lang-page { max-width: 54rem; }
@media (max-width: 575.98px) {
    .lang-group__grid { grid-template-columns: 1fr 1fr; }
}

/* ---------- Legal translation notice ---------- */
.legal-translation-note { font-size: .86rem; border: 1px dashed var(--ai-border); padding: .6rem .85rem; color: var(--ai-text-secondary); }
