/* pperl-rtl.css — keep code containers LTR on RTL locales.
 *
 * Sphinx sets <html dir="rtl"> for Arabic/Hebrew, which is correct
 * for prose but wrong for code: source code is universally LTR
 * regardless of the reader's natural language. Without these
 * overrides, fenced code blocks, inline backtick code, regex tables,
 * and Sphinx's highlight/literal containers all render right-to-left,
 * mirroring brackets, breaking indentation cues, and confusing every
 * reader who has ever read program source.
 *
 * Scope: applied unconditionally — these selectors target code, not
 * prose, so they're a no-op on LTR locales (browser default is ltr).
 * Kept in one file so disabling RTL-code-LTR is a one-line revert.
 *
 * `unicode-bidi: isolate` prevents an LTR code span from disturbing
 * the surrounding RTL paragraph's bidi run boundaries. `text-align:
 * left` overrides the inherited `text-align: right` that RTL pages
 * apply to block elements.
 */

pre,
pre[class*="language-"],
.highlight,
.highlight pre,
div.highlight,
.literal-block,
.literal-block-wrapper,
.code-block,
div[class*="highlight-"] {
    direction:      ltr !important;
    text-align:     left !important;
    unicode-bidi:   isolate;
}

/* Inline code: <code>, <kbd>, <samp>, <var>, and Sphinx's literal /
 * notranslate spans. These are inline so we don't force text-align;
 * just lock direction so brackets, sigils, and operators read in
 * source order. */
code,
kbd,
samp,
var,
tt,
.docutils.literal,
span.pre,
.notranslate {
    direction:      ltr;
    unicode-bidi:   isolate;
}

/* Sphinx's copybutton and language label sit on the right of code
 * blocks by default. Under RTL they'd flip to the left, which is
 * inconsistent with the LTR content they're attached to. Keep them
 * on the right of the code block they decorate. */
html[dir="rtl"] button.copybtn {
    right:          0.4em;
    left:           auto;
}

/* Tables that are pure code (regex spec, operator precedence, format
 * specifier reference) should render LTR in their entirety. Sphinx
 * tags these via the `code-table` class on some pages, but most rely
 * on cell-content classes. The cell-level rules above already cover
 * most cases via <code> children; this rule catches the edge case of
 * cells whose first child is a literal block. */
table.code-table,
table.docutils:has(td > pre) {
    direction:      ltr;
    text-align:     left;
}
