/*
 * Small-screen readability layer. Loaded last on every page.
 *
 * The desktop design uses very small type for labels, captions and footers.
 * On phones and tablets that text became hard to read (some of it under 9px),
 * so these rules set a minimum size for it and fix a few layouts that broke
 * at narrow widths. Desktop (above 1100px) is untouched.
 */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Long words, emails and URLs wrap instead of pushing the page sideways. */
p, li, td, th, dd, figcaption, .l, label {
  overflow-wrap: break-word;
}

/* Stats without an icon (Insights page) have no icon column to fill. */
.stat:not(:has(> .ico)) {
  grid-template-columns: minmax(0, 1fr);
}

/* ───────────── Tablets and small laptops (≤1100px) ───────────── */
@media (max-width: 1100px) {
  html body .eyebrow,
  body.homepage .eyebrow,
  body.homepage .hero .eyebrow {
    font-size: .72rem;
  }
  body .principle-label { font-size: .7rem; }
  body .principle-index { font-size: .56rem; }
  body .scroll-cue { font-size: .75rem; }
  body #principle-detail { font-size: .75rem; }
  body .hero-caption .scene-note { font-size: .7rem; }
  body .hero-device figcaption { font-size: .62rem; }

  body.homepage .hero .btn { font-size: .82rem; }
  body.homepage .stat .l { font-size: .84rem; }
  body.homepage .step-n { font-size: .75rem; }
  body.homepage .process-grid p { font-size: .86rem; }
  body .callout,
  body.homepage .callout { font-size: .86rem; }

  html body ul.checkrow strong,
  html body ul.checkrow span { font-size: .84rem; }

  html body footer.site p,
  html body footer.site a,
  html body footer.site li,
  body.homepage footer.site p,
  body.homepage footer.site a { font-size: .84rem; }

  /* Mobile menu items: bigger text and tap targets. */
  html body nav.main a,
  html body nav.main .navlink,
  html body nav.main .langtoggle { font-size: .95rem; }

  body.insights-page .toc a { font-size: .8rem; }
  body.insights-page .stat span,
  body.insights-page .stat .l { font-size: .85rem; }
  body.insights-page th { font-size: .72rem; }
  body.insights-page td { font-size: .86rem; }
  body.insights-page .sources li { font-size: .85rem; }
  body.insights-page sup a,
  body.insights-page sup { font-size: .72rem; }

  body.admin-page td { font-size: .84rem; }
  body.admin-page th { font-size: .7rem; }
  body.admin-page .pill { font-size: .72rem; }
}

/* ───────────── Phones (≤767px) ───────────── */
@media (max-width: 767px) {
  html body .eyebrow,
  body.homepage .eyebrow,
  body.homepage .hero .eyebrow {
    font-size: .75rem;
  }

  /* Hero */
  body.homepage .hero .lede {
    font-size: 1rem;
    line-height: 1.7;
  }
  body.homepage .hero .btn {
    font-size: .9rem;
    min-height: 48px;
  }
  body .hero-principles { width: 116px; }
  html[dir=rtl] body .hero-principles { width: 116px; }
  body .principle { padding: 12px; }
  body .principle-label { font-size: .72rem; line-height: 1.3; }
  body .principle-index { font-size: .62rem; }
  body .hero-device figcaption { font-size: .7rem; }
  body .scroll-cue { font-size: .78rem; }
  body #principle-detail { font-size: .78rem; }

  /* Stat band under the hero */
  body.homepage .stat .n { font-size: 1.1rem; }
  body.homepage .stat .l { font-size: .92rem; }

  /* Section intros and body copy */
  body.homepage .lede,
  body.homepage .prose p,
  body.homepage #about .card p,
  body.homepage #benefits .card p {
    font-size: 1rem;
  }

  /* "Four steps": one column on phones so each step has room to breathe. */
  body.homepage .process-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 32px;
  }
  body.homepage .step-n { font-size: .8rem; }
  body.homepage .process-grid h3 { font-size: 1.1rem; }
  body.homepage .process-grid p { font-size: .95rem; }
  body .callout,
  body.homepage .callout { font-size: .95rem; }

  /* Trust cards and check list */
  body.homepage #trust .card h3 { font-size: 1.08rem; }
  body.homepage #trust .card p { font-size: .95rem; }
  html body ul.checkrow strong { font-size: .95rem; }
  html body ul.checkrow span { font-size: .9rem; }

  /* Partner CTA band */
  body.homepage .cta-band p { font-size: 1rem; }
  body.homepage .cta-band h2 { font-size: clamp(2.3rem, 10vw, 3rem); }

  /* Footer */
  html body footer.site p,
  html body footer.site a,
  html body footer.site li,
  body.homepage footer.site p,
  body.homepage footer.site a { font-size: .92rem; }
  html body footer.site strong { font-size: 1rem; }
  html body footer.site .legal,
  html body footer.site .legal p { font-size: .82rem; line-height: 1.6; }


  /* Forms: 16px inputs stop iOS from zooming in on focus. */
  html body input,
  html body select,
  html body textarea {
    font-size: 16px;
  }
  html body label,
  html body.partner-page .field label,
  html body.admin-page .field label { font-size: .9rem; }
  html body .tabs button,
  html body.partner-page .tabs button,
  html body.admin-page .tabs button { font-size: .9rem; }

  /* Partner page */
  body.partner-page .partner-intro p { font-size: 1rem; }

  /* Pages whose header has no burger menu (Insights): let the links wrap
     under the logo instead of overflowing the screen. */
  header.site:not(:has(.burger)) .bar {
    flex-wrap: wrap;
    row-gap: 8px;
    padding-block: 12px;
  }
  header.site:not(:has(.burger)) nav.main {
    flex: 1 1 100%;
    gap: 4px;
    border: 0;
    background: transparent;
    box-shadow: none;
  }
  header.site:not(:has(.burger)) nav.main a,
  header.site:not(:has(.burger)) nav.main .navlink {
    padding: 10px 12px;
    font-size: .9rem;
  }

  /* Insights page */
  body.insights-page .hero h1 { font-size: clamp(2.2rem, 10vw, 3rem); }
  body.insights-page .toc a { font-size: .85rem; padding: 10px 14px; }
  body.insights-page section.band .lede { font-size: 1.02rem; }
  body.insights-page .prose p { font-size: 1rem; }
  body.insights-page .stat {
    padding: 20px 4px;
    border-inline-end: 0;
    border-bottom: 1px solid #94662935;
  }
  body.insights-page .stat:last-child { border-bottom: 0; }
  body.insights-page .stat .n { font-size: 1.8rem; }
  body.insights-page .stat span,
  body.insights-page .stat .l { font-size: .92rem; }
  body.insights-page .sources { grid-template-columns: 1fr; }
  body.insights-page .sources li { font-size: .9rem; }
  body.insights-page sup a,
  body.insights-page sup { font-size: .75rem; }

  /* Insights tables become stacked cards: one card per row, each value
     labelled with its column heading (data-label is set by insights.js). */
  body.insights-page .tablewrap {
    border: 0;
    background: transparent;
    overflow: visible;
  }
  body.insights-page .tablewrap table,
  body.insights-page .tablewrap tbody,
  body.insights-page .tablewrap tr,
  body.insights-page .tablewrap td {
    display: block;
    width: 100%;
  }
  body.insights-page .tablewrap table {
    border: 0;
    background: transparent;
    overflow: visible;
  }
  body.insights-page .tablewrap thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
  body.insights-page .tablewrap tr {
    margin-bottom: 12px;
    border: 1px solid #d9ad6855;
    border-radius: 12px;
    background: #fffcf7;
    padding: 6px 16px;
  }
  body.insights-page .tablewrap td {
    padding: 10px 0;
    font-size: .95rem;
  }
  body.insights-page .tablewrap td:last-child { border-bottom: 0; }
  body.insights-page .tablewrap td:first-child {
    font-weight: 600;
    color: #800020;
  }
  body.insights-page .tablewrap td[data-label]:not(:first-child)::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 2px;
    font-size: .72rem;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: #946629;
  }

  /* Admin table keeps its sideways scroll, with readable text. */
  body.admin-page td { font-size: .9rem; }
}

/* ───────────── Very small phones (≤380px) ───────────── */
@media (max-width: 380px) {
  body .hero-principles { width: 104px; }
  html[dir=rtl] body .hero-principles { width: 104px; }
  body .principle-label { font-size: .68rem; }
  html body .eyebrow { letter-spacing: .1em; }
}

/* ───────────── Arabic ───────────── */
/* Arabic letters sit smaller than Latin at the same size, so on phones and
   tablets the whole Arabic page is scaled up slightly (all rem sizes follow). */
@media (max-width: 1100px) {
  html[lang="ar"] { font-size: 106.25%; }
}
@media (max-width: 767px) {
  html[lang="ar"] { font-size: 109.375%; }
}

/* Letter-spacing pulls joined Arabic letters apart; keep it off. */
html[lang="ar"] body .eyebrow,
html[lang="ar"] body.homepage .eyebrow,
html[lang="ar"] body .principle-label,
html[lang="ar"] body .btn,
html[lang="ar"] body th,
html[lang="ar"] body.insights-page .tablewrap td[data-label]::before {
  letter-spacing: 0;
}

/* Hero card labels wrap instead of being cut off at the card edge. */
html body .principle-label {
  white-space: normal;
  overflow-wrap: break-word;
  overflow: visible;
  text-overflow: clip;
}
@media (max-width: 767px) {
  html[lang="ar"] body .principle-label { line-height: 1.45; }
  /* Room under the big number so it never touches the small index (01/02/03). */
  html body .principle { padding-bottom: 26px; }
}
