/* Language picker, right-to-left support, per-script typography and text-expansion guards.
   Shared by index.html, learn.html and score.html (the pages keep their own layout CSS). */

/* ---------- language picker (built by js/i18n.js into <div data-lang-picker>) ---------- */
.lang { position: relative; flex: none; }
.lang-btn { display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; background: transparent; color: var(--muted); font: 500 .78rem var(--f-mono); cursor: pointer; white-space: nowrap; transition: color .15s, border-color .15s; }
.lang-btn:hover, .lang-btn[aria-expanded="true"] { color: var(--text); border-color: var(--muted); }
.lang-caret { transition: transform .15s; }
.lang-btn[aria-expanded="true"] .lang-caret { transform: rotate(180deg); }
.lang-menu { position: absolute; inset-block-start: calc(100% + 8px); inset-inline-end: 0; z-index: 40; margin: 0; padding: 6px; list-style: none; width: 260px; max-width: calc(100vw - 24px); max-height: min(70vh, 440px); overflow-y: auto; overscroll-behavior: contain;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 24px 60px -12px rgba(0,0,0,.75), inset 0 1px 0 rgba(255,255,255,.05); }
.lang-menu[hidden] { display: none; }
.lang-menu a { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 12px; border-radius: 10px; color: var(--text); text-decoration: none; font: 500 .95rem/1.3 var(--f-body); }
.lang-menu a:hover { background: var(--panel-2); }
.lang-menu a:focus-visible { background: var(--panel-2); outline-offset: -2px; }
.lang-menu a[aria-current] { color: var(--thread); }
.lang-tick { opacity: 0; }
.lang-menu a[aria-current] .lang-tick { opacity: 1; }
/* when the header navigation does not fit (long translations), js/i18n.js collapses it like on a phone */
nav.main.is-collapsed { display: none; }
nav.main.is-collapsed ~ .lang { margin-inline-start: auto; }
@media (max-width: 560px) { .lang-btn { height: 34px; padding: 0 10px; gap: 6px; } }

.app-note { margin-top: 18px; color: var(--muted); font-size: .9rem; max-width: 52ch; margin-inline: auto; text-wrap: balance; }

/* ---------- text expansion: translations can run ~40% longer than English ---------- */
h1, h2, h3, h4 { overflow-wrap: break-word; hyphens: auto; }
p, li, dd, dt, summary, .caption, .cap { overflow-wrap: break-word; }
.btn, .pg-btn, .pg-pill, .pg-rec, .room, .chips li, .terms span, .tag, .chip { max-width: 100%; }
.btn, .pg-btn, .pg-pill { text-align: center; }
.cta .btn { justify-content: center; }
nav.main a { white-space: nowrap; }
.btn.sm, .bar > .btn { white-space: nowrap; flex: none; }

/* ---------- right-to-left (ar, ur ...). Pitch and time stay left to right inside the instruments ---------- */
.pads, .pads4, .strip, .sheet, .notation, .pg-keys, .pg-seq, .pg-padgrid, .pg-drawbars, .lane, .roll, pre.code, pre.raw, .scrub, .meter, .pg-meter { direction: ltr; }
[dir="rtl"] .pad span, [dir="rtl"] .pad kbd { direction: ltr; }
[dir="rtl"] .lang-menu a { text-align: right; }
/* Labels that are often Latin names ("8-Beat Pop", "Vienna Waltz · 168 BPM") take their direction from their own text,
   so a leading number is not moved to the end in RTL pages. */
[dir="rtl"] :is(.pg-pill, .pg-seg button, .track .meta, .track .code, .facts b, .sw b, .chips li) { unicode-bidi: plaintext; }
/* "0:00 / 0:24" is a time readout: keep it in reading order. */
[dir="rtl"] .work-title p:not(.where) { direction: ltr; unicode-bidi: isolate; text-align: right; }

/* ---------- scripts that need room and must not be letter-spaced ---------- */
:lang(ar) *, :lang(ur) *, :lang(fa) *, :lang(hi) *, :lang(bn) *, :lang(ta) *, :lang(te) *, :lang(si) *, :lang(th) *, :lang(am) * { letter-spacing: 0 !important; }
:lang(ar) body, :lang(ur) body, :lang(hi) body, :lang(bn) body, :lang(ta) body, :lang(te) body, :lang(si) body, :lang(th) body, :lang(am) body { line-height: 1.8; }
:lang(ar) :is(h1, h2, h3), :lang(ur) :is(h1, h2, h3), :lang(hi) :is(h1, h2, h3), :lang(bn) :is(h1, h2, h3), :lang(ta) :is(h1, h2, h3), :lang(te) :is(h1, h2, h3), :lang(si) :is(h1, h2, h3), :lang(th) :is(h1, h2, h3), :lang(am) :is(h1, h2, h3) { line-height: 1.35; }
:lang(ur) body { line-height: 2.1; }
:lang(ur) :is(h1, h2, h3) { line-height: 1.8; }
/* the tiny mono labels are Latin by design; other scripts fall back to the script font */
:lang(ar) .eyebrow, :lang(ur) .eyebrow { text-transform: none; }

/* ---- header Discord pill: stays visible on phones (icon only); takes the auto margin whenever the nav is hidden ---- */
.community-link { flex: none; display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font: 500 .78rem var(--f-mono); text-decoration: none; white-space: nowrap; transition: color .15s, border-color .15s; }
.community-link:hover { color: var(--text); border-color: var(--muted); }
nav.main.is-collapsed ~ .community-link { margin-inline-start: auto; }
nav.main.is-collapsed ~ .community-link ~ .lang, nav.main.is-collapsed ~ .community-link ~ .btn { margin-inline-start: 0; }
@media (max-width: 760px) { .bar > nav.main ~ .community-link { margin-inline-start: auto; } .bar > .community-link ~ .lang, .bar > .community-link ~ .btn { margin-inline-start: 0; } }
@media (max-width: 560px) { .community-link { height: 34px; padding: 0 10px; } .community-link span { display: none; } }
