/*
 * RTL-only layer. Load AFTER the existing design-system stylesheets.
 * Activation belongs to the document renderer: <html dir="rtl">.
 * Every selector is root-gated; dir="ltr" and an absent dir attribute match
 * nothing here, including the utilities. This file registers no RTL locale.
 *
 * Grid/flex item order follows inherited document direction. Do not reverse
 * the DOM or use row-reverse as well: that would reverse the reading order twice.
 * Logical overrides replace legacy physical insets/padding only in RTL.
 * Existing !important overrides require matching importance in a few places.
 *
 * Bidi safety: isolate mixed-language identifiers with <bdi dir="auto"> or
 * an explicit dir="ltr"/dir="rtl" and the utilities below. These rules do
 * not escape HTML, remove Unicode controls, or validate user text. Those are
 * renderer/input responsibilities. Never use bidi-override for editorial text.
 * Media elements, covers, posters and logos are not reflected here. Directional
 * icons are explicitly marked. Curated decorative hero background reflections
 * are handled separately in rtl-hero-composition.css; lettered art stays intact.
 */

/* Latin display tracking breaks connected Arabic/Persian letterforms and
 * crowds Hebrew headings.  Change type rhythm only, not sizes, containers,
 * grid order, or media.  Latin identifiers with an explicit LTR direction
 * retain their existing typography.
 */
html[dir="rtl"] :is(h1, h2, h3, h4, h5, h6, p, li, dt, dd, label, legend, button, input, select, textarea, .portal-link, .portal-dropdown-heading, .portal-language-menu a, .lang-current, .editorial-kicker, .academic-kicker, .concept-eyebrow):not([dir="ltr"]) {
  letter-spacing: normal !important;
}

html[dir="rtl"] :is(h1, h2, h3, h4, h5, h6):not([dir="ltr"]) {
  line-height: 1.35 !important;
}

/* Catalogue counters now use native-script edition labels. Latin display
 * tracking must not separate the connected Arabic/Persian caption glyphs.
 */
html[dir="rtl"] .works-hero-stats > span:not([dir="ltr"]) {
  letter-spacing: normal !important;
}

html[dir="rtl"] :is(.portal-link, .portal-language-menu a, .lang-current, .portal-dropdown-heading, .editorial-kicker, .academic-kicker, .concept-eyebrow, button, label, legend):not([dir="ltr"]) {
  line-height: 1.5 !important;
}

html[dir="rtl"] :is(.editorial-copy, .dialogue-manuscript, .reading-body, .detail-body) :is(p, li, dd):not([dir="ltr"]) {
  line-height: 1.85 !important;
}

/* Existing semantic tags provide isolation. The post-localization renderer
 * also isolates complete Latin parentheses in mixed-script news with bdi.
 * Explicit dir values remain browser-owned and are never overridden here.
 */
html[dir="rtl"] :is([dir="auto"], [dir="ltr"], [dir="rtl"]):not(html, body) {
  unicode-bidi: isolate;
}

/* Text alignment is logical; central logos and button labels remain untouched. */
html[dir="rtl"] :is(.portal-dropdown, .portal-language-menu, .lang-dd),
html[dir="rtl"] :is(.event-row, .event-detail, .event-meta),
html[dir="rtl"] :is(.dialogue-article, .dialogue-manuscript, .dialogue-card > a),
html[dir="rtl"] :is(.reading-body, .detail-body, .book-detail-main) {
  text-align: start;
}

html[dir="rtl"] :is(.event-detail, .dialogue-card > a, .book-detail-hero-inner) > * {
  min-inline-size: 0;
}

/* The author photograph has deliberate blank space beside a right-side
 * portrait. Keep the copy in that space; do not reflect the photograph.
 * Its text still follows RTL within the unchanged content column.
 */
html[dir="rtl"] .author-poster .poster-page-hero-copy {
  margin-inline-start: auto;
  margin-inline-end: 0;
}

html[dir="rtl"] :is(.events-source-order > span, .footer-meta) {
  text-align: end;
}

html[dir="rtl"] .dialogue-card time {
  text-align: end;
  unicode-bidi: isolate;
}

/* A Latin brand remains LTR inside the native RTL reading column. */
html[dir="rtl"] body.portal .portal-home-hero .hero-copy h1{
 direction:ltr;text-align:right;line-height:1.12!important;
 font-family:"Iowan Old Style","Palatino Linotype","Book Antiqua",Georgia,"Times New Roman",serif!important;
}
html[dir="rtl"] :is(.hero-learn,.home-shortcuts .shortcut-arrow){unicode-bidi:isolate}
html[dir="rtl"] .topic-book-meta>span{direction:rtl;text-align:start}
html[dir="rtl"] .topic-book-meta bdi{unicode-bidi:isolate}
html[dir="rtl"] .works-hero-stats :is(span,b){text-align:right}
/* Translated captions may precede a numeral in prose; the visual metric still
   places its number above its caption, consistently across the six cells. */
html[dir="rtl"] body.portal .works-hero-stats>span{
 display:flex!important;flex-direction:column;font-size:12px!important;
}
html[dir="rtl"] .works-hero-stats>span>b{order:-1}

@media(min-width:901px){
 /* Right-side portraits leave a left-side field for copy. Keep that field,
    with right-aligned native text, instead of covering the person's face. */
 html[dir="rtl"] body.portal.books-page .works-hero>:is(h1,p,.works-hero-stats){
  width:52%!important;max-width:620px!important;margin-left:0!important;margin-right:auto!important;
  text-align:right;
 }
 /* Topics uses a different photo, with the portrait on the left. */
 html[dir="rtl"] body.portal.topics-redesigned .editorial-hero>:is(h1,p,.editorial-kicker){
  max-width:640px!important;margin-left:auto!important;margin-right:0!important;
  text-align:right;
 }
}

/* A language name may itself be LTR; it must not reorder adjacent labels. */
html[dir="rtl"] :is(.portal-language-menu a, .lang-dd a, .event-date-stamp) {
  unicode-bidi: isolate;
}

html[dir="rtl"] :is(.portal-language-menu, .lang-dd) {
  inset-inline-start: auto !important;
  inset-inline-end: 0 !important;
}

html[dir="rtl"] .portal-language-menu a.active::after {
  inset-inline-start: auto;
  inset-inline-end: 14px;
}

html[dir="rtl"] .portal-dropdown > a {
  border-inline-end: 0;
  border-inline-start: 1px solid transparent;
}

html[dir="rtl"] .portal-dropdown > a:is(:hover, :focus-visible) {
  border-inline-start-color: var(--xm-gold, #c3913e);
}

/* Do not reverse event grid columns: CSS Grid already follows dir="rtl". */
html[dir="rtl"] .event-detail {
  padding-inline-start: 0;
  padding-inline-end: 22px;
}

html[dir="rtl"] .event-evidence::before {
  margin-inline-start: 0;
  margin-inline-end: 8px;
}

html[dir="rtl"] .dialogue-read b {
  margin-inline-start: 8px;
  margin-inline-end: 0;
}

html[dir="rtl"] .dialogue-pagination a {
  text-align: start;
}

/* Move reading anchors to inline-start while retaining room for the number. */
html[dir="rtl"] .reading-body p {
  padding-inline-start: 48px !important;
  padding-inline-end: 0 !important;
}

html[dir="rtl"] .reading-body .reading-focus {
  padding-inline-start: 48px !important;
  padding-inline-end: 22px !important;
}

html[dir="rtl"] .context-index {
  inset-inline-start: 0;
  inset-inline-end: auto;
  unicode-bidi: isolate;
}

html[dir="rtl"] .reading-focus .context-index {
  inset-inline-start: 16px;
}

html[dir="rtl"] :is(.reading-access, .dialogue-unavailable) {
  border-inline-end: 0;
  border-inline-start: 3px solid var(--xm-gold, #c3913e);
}

html[dir="rtl"] .dialogue-source-notice {
  border-inline-end: 1px solid rgba(190, 137, 42, .36);
  border-inline-start: 3px solid var(--xm-gold, #c3913e);
}

html[dir="rtl"] :is(.dialogue-manuscript, .reading-body) :is(ul, ol) {
  padding-inline-start: 1.5em;
  padding-inline-end: 0;
}

/* Tables keep semantic DOM order. Identifier/code runs opt into LTR below. */
html[dir="rtl"] :is(.table-wrap, .book-detail-main, .detail-wrap) :is(th, td),
html[dir="rtl"] form :is(label, legend, input, textarea, select) {
  text-align: start;
}

html[dir="rtl"] :is(.table-wrap, .book-detail-edition) {
  min-inline-size: 0;
  max-inline-size: 100%;
  overflow-x: auto;
}

/* The full-bleed development plan uses a legacy LEFT negative margin.
 * Move that margin to the reading-order start in RTL; keep its full width,
 * scrollable table, and original desktop/mobile composition unchanged.
 */
html[dir="rtl"] .poster-page-body > .plan-section {
  margin-inline-start: calc(50% - 50vw) !important;
  margin-inline-end: 0 !important;
}

html[dir="rtl"] .plan-table :is(th, td) {
  text-align: start;
}

/* The shared, full-width conceptual diagram is centered with a legacy
 * physical left margin plus a negative translation. RTL needs the opposite
 * centering offset, not a mirrored image or a smaller diagram. */
html[dir="rtl"] .civilization-model {
  margin-inline-end: 0;
  margin-inline-start: 50%;
  transform: translateX(50%);
}

html[dir="rtl"] :is(code, pre, input[type="email"], input[type="url"], input[type="tel"], input[type="number"]):not([dir]) {
  direction: ltr;
  unicode-bidi: isolate;
  text-align: start;
}

/* Utilities intentionally have no effect on any current LTR document. */
html[dir="rtl"] .i18n-bidi-isolate {
  unicode-bidi: isolate;
}

html[dir="rtl"] .i18n-ltr {
  direction: ltr;
  unicode-bidi: isolate;
  text-align: start;
}

html[dir="rtl"] .i18n-rtl {
  direction: rtl;
  unicode-bidi: isolate;
  text-align: start;
}

/* Opt in only on the arrow glyph/SVG itself, never a card or media wrapper.
 * Individual scale composes with an existing hover transform rather than
 * replacing it. Embedded raster images and known media wrappers are excluded.
 */
html[dir="rtl"] :is(span, i, svg).i18n-directional-icon:not(.book-cover, .book-detail-cover, .book-detail-edition-cover, .dialogue-poster, .event-place):not(:has(img, picture, video, canvas, iframe, image, .book-cover, .book-detail-cover, .book-detail-edition-cover, .dialogue-poster, .event-place)) {
  display: inline-block;
  scale: -1 1;
}

@media (min-width: 901px) {
  /* The shared desktop layer centers each panel on its own trigger and
   * clamps it with --nav-shift in viewport coordinates. In RTL, inline-end
   * is the same physical left anchor; media and panel content are not flipped.
   */
  html[dir="rtl"] :is(.portal-dropdown, .portal-dropdown-right) {
    inset-inline-start: auto !important;
    inset-inline-end: 50% !important;
  }

  html[dir="rtl"] .portal-dropdown > a {
    padding-inline-start: var(--portal-dropdown-indent, 16px) !important;
    padding-inline-end: 16px !important;
  }

  html[dir="rtl"] .portal-dropdown-heading {
    margin-inline-start: var(--portal-dropdown-indent, 16px) !important;
    margin-inline-end: 16px !important;
  }
}

@media (max-width: 900px) {
  html[dir="rtl"] .portal-nav-inner.nav-eleven .portal-home {
    inset-inline-start: 62px !important;
    inset-inline-end: auto !important;
  }

  html[dir="rtl"] .portal-nav .menu-toggle {
    inset-inline-start: var(--i18n-nav-edge, 12px) !important;
    inset-inline-end: auto !important;
  }

  html[dir="rtl"] .portal-nav .portal-language {
    inset-inline-start: auto !important;
    inset-inline-end: var(--i18n-nav-edge, 12px) !important;
  }

  html[dir="rtl"] :is(.portal-dropdown, .portal-dropdown-right) {
    inset-inline: auto !important;
    padding-inline-start: 14px;
    padding-inline-end: 0;
    border-inline-end: 0;
    border-inline-start: 1px solid rgba(214, 173, 85, .24);
  }

  html[dir="rtl"] .portal-dropdown-heading {
    margin-inline-start: 11px;
    margin-inline-end: 0;
  }

  html[dir="rtl"] .footer-meta {
    text-align: center;
  }
}

@media (max-width: 820px) {
  html[dir="rtl"] .event-detail {
    padding-inline-end: 6px;
  }

  html[dir="rtl"] .events-source-order > span {
    text-align: start;
  }
}

@media (max-width: 760px) {
  html[dir="rtl"] .dialogue-card time {
    text-align: start;
  }
}

@media (max-width: 680px) {
  html[dir="rtl"] .reading-body p {
    padding-inline-start: 36px !important;
  }

  html[dir="rtl"] .reading-body .reading-focus {
    padding-inline-start: 42px !important;
  }
}

/* A personal name remains one reading unit in Arabic headings. */
.i18n-author-name { white-space: nowrap; }
