/* ==========================================================================
   North African Origins — design system
   Implements DESIGN.md. If you change a rule here, change DESIGN.md in the
   same commit.

   Legacy note: css/styles.css still serves the pages not yet migrated to this
   system. It is deleted when the last page moves over.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */

:root {
    /* Amazigh flag palette. Contrast figures in DESIGN.md.
       Sea, mountain and yaz are dual-role: they fill a block AND set text.
       Sand is a fill only — it never carries white and never sets type. */
    --paper: #FFFCF5;
    /* Type on a colour ground. Fixed white — the counterpart of the four fills. */
    --on-colour: #FFFFFF;
    --paper-sunk: #F6F1E6;
    --ink: #16130F;
    --ink-quiet: #57504A;

    --sea: #1746C4;
    --mountain: #0B7A41;
    --yaz: #D11810;
    --sand: #FFC61E;

    /* Type */
    --font-display: "Bricolage Grotesque", "Archivo", system-ui, sans-serif;
    --font-body: "Instrument Sans", system-ui, -apple-system, sans-serif;
    --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;
    --font-tifinagh: "Noto Sans Tifinagh", var(--font-display);

    --t-xs: 0.75rem;
    --t-sm: 0.875rem;
    --t-body: 1.0625rem;
    --t-lead: clamp(1.15rem, 0.95rem + 0.9vw, 1.45rem);
    --t-h3: clamp(1.3rem, 1.1rem + 1vw, 1.7rem);
    --t-h2: clamp(1.9rem, 1.3rem + 2.6vw, 3rem);
    --t-h1: clamp(2.5rem, 1.2rem + 5.6vw, 5rem);
    --t-mega: clamp(3.2rem, 1rem + 9.5vw, 8rem);

    /* Space */
    --gap: clamp(1rem, 0.7rem + 1.4vw, 1.75rem);
    --band-y: clamp(3rem, 2rem + 4vw, 6rem);
    --container: 1180px;

    /* Form language: flat and hard-edged. The only radius on the site. */
    --radius-dot: 50%;
    --rule: 2px solid var(--ink);
}

/* --------------------------------------------------------------------------
   2. Base
   -------------------------------------------------------------------------- */

*,
*::before,
*::after { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: var(--t-body);
    line-height: 1.65;
    font-synthesis-weight: none;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

img,
svg { max-width: 100%; }

img { height: auto; }

a { color: var(--sea); }

a:hover { text-decoration-thickness: 2px; }

::selection {
    background: var(--sand);
    color: var(--ink);
}

/* --------------------------------------------------------------------------
   3. Typography
   -------------------------------------------------------------------------- */

h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 800;
    line-height: 1.02;
    letter-spacing: -0.03em;
    text-wrap: balance;
    /* A single long word at display size is wider than a 320px container —
       "Microgeographical" at 40px overflowed a real page. Display type must be
       allowed to break, or the whole document scrolls sideways on a phone. */
    overflow-wrap: break-word;
    margin: 0 0 0.5em;
}

h1 { font-size: var(--t-h1); letter-spacing: -0.045em; }
h2 { font-size: var(--t-h2); letter-spacing: -0.035em; }
h3 { font-size: var(--t-h3); }
h4 { font-size: 1.05rem; letter-spacing: -0.02em; }

p { margin: 0 0 1em; }

.prose { max-width: 68ch; }

.prose > p:last-child { margin-bottom: 0; }

.lead {
    font-size: var(--t-lead);
    line-height: 1.45;
    max-width: 40ch;
}

.kicker {
    font-family: var(--font-mono);
    font-size: var(--t-xs);
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    margin: 0 0 0.9rem;
    display: block;
}

/* Haplogroup notation, dates, identifiers. */
.hg {
    font-family: var(--font-mono);
    font-size: 0.92em;
    font-weight: 600;
    letter-spacing: -0.02em;
    white-space: nowrap;
}

.yaz-mark {
    font-family: var(--font-tifinagh);
    line-height: 1;
    font-weight: 400;
}

/* --------------------------------------------------------------------------
   4. Layout
   -------------------------------------------------------------------------- */

.container {
    width: min(100% - 2.5rem, var(--container));
    margin-inline: auto;
}

.band {
    padding-block: var(--band-y);
    background: var(--paper);
}

.band--sunk     { background: var(--paper-sunk); }
.band--sea      { background: var(--sea); }
.band--mountain { background: var(--mountain); }
.band--yaz      { background: var(--yaz); }
.band--sand     { background: var(--sand); }
.band--ink      { background: var(--ink); }
.band--tight    { padding-block: clamp(2rem, 1.4rem + 2.4vw, 3.25rem); }

/* Sea, mountain, yaz and ink grounds carry white type. */
.band--sea,
.band--mountain,
.band--yaz,
.band--ink {
    color: var(--on-colour);
}

.band--sea a,
.band--mountain a,
.band--yaz a,
.band--ink a { color: var(--on-colour); }

/* Sand carries ink — never white. */
.band--sand { color: var(--ink); }
.band--sand a { color: var(--ink); }

/* --------------------------------------------------------------------------
   5. The stripe — the site's one ornament.
   Irregular widths, after the striated Ait Moussa tahaikt. Do not even them out.
   -------------------------------------------------------------------------- */

.stripe {
    height: 12px;
    border: 0;
    margin: 0;
    background: linear-gradient(90deg,
        var(--sea) 0 6%, var(--sand) 6% 10%, var(--ink) 10% 12%,
        var(--yaz) 12% 21%, var(--paper) 21% 24%, var(--mountain) 24% 33%,
        var(--sand) 33% 39%, var(--sea) 39% 43%, var(--yaz) 43% 46%,
        var(--mountain) 46% 57%, var(--sand) 57% 62%, var(--ink) 62% 64%,
        var(--sea) 64% 73%, var(--yaz) 73% 78%, var(--sand) 78% 85%,
        var(--mountain) 85% 91%, var(--sea) 91% 100%);
}

.stripe--tall { height: 20px; }

/* --------------------------------------------------------------------------
   6. Header, nav, footer
   -------------------------------------------------------------------------- */

.site-header {
    background: var(--paper);
    border-bottom: var(--rule);
}

.site-header__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding-block: 0.85rem;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    text-decoration: none;
    color: var(--ink);
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 1.05rem;
    letter-spacing: -0.03em;
}

.brand__mark {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    background: var(--yaz);
    color: var(--on-colour);
    font-family: var(--font-tifinagh);
    font-size: 1.15rem;
    line-height: 1;
}

.nav {
    background: var(--ink);
    border-bottom: var(--rule);
}

.nav__list {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    margin: 0;
    padding: 0;
    list-style: none;
}

.nav__link {
    display: block;
    padding: 0.85rem 1.1rem;
    color: var(--on-colour);
    text-decoration: none;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: -0.01em;
    min-height: 48px;
    display: flex;
    align-items: center;
}

.nav__link:hover { background: var(--sea); }

.nav__link[aria-current="page"] {
    background: var(--sand);
    color: var(--ink);
}

.breadcrumb {
    font-size: var(--t-sm);
    color: var(--ink-quiet);
    padding-block: 0.9rem;
}

.breadcrumb a { color: var(--ink-quiet); }

.site-footer {
    background: var(--ink);
    color: var(--on-colour);
    padding-block: clamp(2.5rem, 2rem + 2vw, 4rem);
}

.site-footer a { color: var(--on-colour); }

.site-footer__grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr));
    gap: var(--gap);
}

.site-footer h2 {
    font-size: 0.8rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-family: var(--font-mono);
    font-weight: 600;
    margin-bottom: 0.8rem;
}

.site-footer ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 0.4rem;
    font-size: var(--t-sm);
}

.site-footer__base {
    margin-top: 2.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.25);
    font-size: var(--t-sm);
    color: rgba(255, 255, 255, 0.75);
}

/* --------------------------------------------------------------------------
   7. Buttons — square, solid, 48px floor
   -------------------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 48px;
    padding: 0.75rem 1.4rem;
    background: var(--ink);
    color: var(--paper);
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -0.01em;
    text-decoration: none;
    border: 2px solid var(--ink);
    cursor: pointer;
    transition: transform 0.12s ease, background-color 0.12s ease;
}

.btn:hover {
    background: var(--sea);
    border-color: var(--sea);
    transform: translateX(3px);
}

.btn--ghost {
    background: transparent;
    color: var(--ink);
}

.btn--ghost:hover {
    background: var(--ink);
    color: var(--paper);
    border-color: var(--ink);
}

/* On colour grounds the button inverts to paper. */
.band--sea .btn,
.band--mountain .btn,
.band--yaz .btn,
.band--ink .btn {
    background: var(--paper);
    color: var(--ink);
    border-color: var(--paper);
}

.band--sea .btn:hover,
.band--mountain .btn:hover,
.band--yaz .btn:hover,
.band--ink .btn:hover {
    background: var(--sand);
    border-color: var(--sand);
    color: var(--ink);
}

/* --------------------------------------------------------------------------
   8. Blocks, stats, doors
   -------------------------------------------------------------------------- */

.block {
    padding: clamp(1.25rem, 1rem + 1.4vw, 2.25rem);
    background: var(--paper-sunk);
    color: var(--ink);
}

.block--sea      { background: var(--sea); color: var(--on-colour); }
.block--mountain { background: var(--mountain); color: var(--on-colour); }
.block--yaz      { background: var(--yaz); color: var(--on-colour); }
.block--sand     { background: var(--sand); color: var(--ink); }
.block--ink      { background: var(--ink); color: var(--on-colour); }

.block--sea a,
.block--mountain a,
.block--yaz a,
.block--ink a { color: var(--on-colour); }

.block h2,
.block h3 { margin-top: 0; }

/* Stats — the loudest type on the site. */
.stat-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr));
    gap: 2px;
    background: var(--ink);
    border: var(--rule);
}

.stat {
    background: var(--paper);
    padding: clamp(1.1rem, 0.9rem + 1vw, 1.75rem);
}

.stat__num {
    display: block;
    font-family: var(--font-display);
    font-weight: 800;
    font-size: clamp(2.1rem, 1.2rem + 3.4vw, 3.4rem);
    line-height: 0.95;
    letter-spacing: -0.05em;
}

.stat__label {
    display: block;
    overflow-wrap: break-word;
    margin-top: 0.55rem;
    font-family: var(--font-mono);
    font-size: var(--t-xs);
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink-quiet);
}

.stat--sea .stat__num      { color: var(--sea); }
.stat--yaz .stat__num      { color: var(--yaz); }
.stat--mountain .stat__num { color: var(--mountain); }

/* Doors — the big tappable entries. Deliberately unequal. */
.doors {
    display: grid;
    gap: 2px;
    background: var(--ink);
    border: var(--rule);
}

@media (min-width: 768px) {
    .doors { grid-template-columns: 1.4fr minmax(0, 1fr) minmax(0, 1fr); }
}

.door {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 2.5rem;
    min-height: 260px;
    padding: clamp(1.35rem, 1rem + 1.6vw, 2.25rem);
    text-decoration: none;
    transition: transform 0.15s ease;
}

.door:hover { transform: scale(0.985); }

.door--sea      { background: var(--sea); color: var(--on-colour); }
.door--sand     { background: var(--sand); color: var(--ink); }
.door--mountain { background: var(--mountain); color: var(--on-colour); }

.door__title {
    display: block;
    font-family: var(--font-display);
    font-weight: 800;
    font-size: clamp(1.7rem, 1.2rem + 2.2vw, 2.6rem);
    line-height: 0.98;
    letter-spacing: -0.04em;
    margin: 0.4rem 0 0.6rem;
}

.door__text {
    display: block;
    font-size: var(--t-sm);
    line-height: 1.5;
    margin: 0;
    max-width: 32ch;
}

.door__go {
    font-family: var(--font-mono);
    font-size: var(--t-xs);
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

/* --------------------------------------------------------------------------
   9. Hero
   -------------------------------------------------------------------------- */

.hero {
    background: var(--paper);
    padding-block: clamp(2.5rem, 1.5rem + 5vw, 5.5rem);
}

.hero__grid {
    display: grid;
    gap: var(--gap);
    align-items: end;
}

@media (min-width: 1024px) {
    .hero__grid { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
}

.hero__title {
    font-size: var(--t-h1);
    margin: 0 0 1rem;
}

.hero__title em {
    font-style: normal;
    color: var(--yaz);
}

.hero__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1.75rem;
}

/* --------------------------------------------------------------------------
   10. Figures — authored SVG only, never a photograph
   -------------------------------------------------------------------------- */

.figure {
    margin: 0 0 var(--gap);
}

.figure__frame {
    border: var(--rule);
    background: var(--paper);
    padding: clamp(0.9rem, 0.7rem + 1vw, 1.5rem);
    overflow-x: auto;
}

.figure svg {
    display: block;
    width: 100%;
    min-width: 540px;
    height: auto;
}

.figure__caption {
    margin-top: 0.85rem;
    font-size: var(--t-sm);
    line-height: 1.5;
    color: var(--ink-quiet);
    max-width: 62ch;
}

.figure__caption b { color: var(--ink); }

/* Diagram legend — colour is never the only cue, so every swatch is labelled. */
.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 1.25rem;
    margin: 0 0 1rem;
    padding: 0;
    list-style: none;
    font-family: var(--font-mono);
    font-size: var(--t-xs);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.legend li {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.legend__dot {
    width: 12px;
    height: 12px;
    border-radius: var(--radius-dot);
    flex: none;
}

/* --------------------------------------------------------------------------
   11. Notes, sourcing, page furniture
   -------------------------------------------------------------------------- */

.note {
    border-left: 8px solid var(--sand);
    background: var(--paper-sunk);
    padding: clamp(1.1rem, 0.9rem + 1vw, 1.6rem);
}

.note h2,
.note h3 { margin-top: 0; }

.note > :last-child { margin-bottom: 0; }

.sourcing-note {
    font-size: var(--t-sm);
    color: var(--ink-quiet);
    border-top: var(--rule);
    padding-top: 1rem;
}

.page-title { margin-bottom: 0.75rem; }

.page-updated {
    font-family: var(--font-mono);
    font-size: var(--t-xs);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-quiet);
}

/* Section nav on content pages — static, no injected TOC. */
.section-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    margin: 0 0 var(--gap);
    padding: 0;
    list-style: none;
}

.section-nav a {
    display: flex;
    align-items: center;
    min-height: 48px;
    padding: 0.6rem 1rem;
    background: var(--paper-sunk);
    color: var(--ink);
    text-decoration: none;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: var(--t-sm);
}

.section-nav a:hover {
    background: var(--ink);
    color: var(--paper);
}

.section-marker {
    font-family: var(--font-tifinagh);
    color: var(--yaz);
    font-size: 1.5rem;
    line-height: 1;
    display: block;
    margin-bottom: 0.6rem;
}

/* Two-column split used by the lineage page. */
.split {
    display: grid;
    gap: 2px;
    background: var(--ink);
    border: var(--rule);
}

@media (min-width: 768px) {
    .split { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.split > * { margin: 0; }

/* Scenario comparison table. */
.scenarios {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--t-sm);
}

.scenarios th,
.scenarios td {
    text-align: left;
    padding: 0.8rem 0.9rem;
    border-bottom: 1px solid rgba(22, 19, 15, 0.15);
    vertical-align: top;
}

.scenarios th {
    font-family: var(--font-display);
    font-weight: 800;
    letter-spacing: -0.01em;
}

.scenarios thead th {
    background: var(--ink);
    color: var(--on-colour);
    font-size: var(--t-xs);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-family: var(--font-mono);
    font-weight: 600;
}

.verdict {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    font-family: var(--font-mono);
    font-size: var(--t-xs);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    white-space: nowrap;
}

.verdict--yes { background: var(--mountain); color: var(--on-colour); }
.verdict--no  { background: var(--paper-sunk); color: var(--ink); }

.table-scroll { overflow-x: auto; }

/* --------------------------------------------------------------------------
   12. Utilities
   -------------------------------------------------------------------------- */

.stack > * + * { margin-top: var(--gap); }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }

/* --------------------------------------------------------------------------
   13. Accessibility
   -------------------------------------------------------------------------- */

/* Visually hidden until keyboard focus. No offset to be out-run — see the
   regression this replaced (#75). */
.skip-to-main,
.skip-link {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.skip-to-main:focus,
.skip-link:focus {
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    clip-path: none;
    padding: 1rem;
    background: var(--ink);
    color: var(--paper);
    text-decoration: none;
    z-index: 1000;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 3px solid var(--sea);
    outline-offset: 2px;
}

/* On colour grounds the ring switches to paper so it stays visible. */
.band--sea a:focus-visible,
.band--mountain a:focus-visible,
.band--yaz a:focus-visible,
.band--ink a:focus-visible,
.nav a:focus-visible,
.site-footer a:focus-visible,
.door:focus-visible {
    outline-color: var(--paper);
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* --------------------------------------------------------------------------
   14. Diagram type — inline SVG inherits these, which is why diagrams are
   never <img src="*.svg">
   -------------------------------------------------------------------------- */

.dg-title {
    font-family: var(--font-display);
    font-weight: 800;
    letter-spacing: -0.02em;
}

.dg-label {
    font-family: var(--font-display);
    font-weight: 700;
    letter-spacing: -0.01em;
}

.dg-meta {
    font-family: var(--font-mono);
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.dg-body { font-family: var(--font-body); }

/* --------------------------------------------------------------------------
   15. Column grids
   -------------------------------------------------------------------------- */

.cols {
    display: grid;
    gap: 2px;
    background: var(--ink);
    border: var(--rule);
}

@media (min-width: 700px) {
    .cols--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 900px) {
    .cols--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (min-width: 700px) and (max-width: 899px) {
    .cols--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* --------------------------------------------------------------------------
   16. Glossary
   -------------------------------------------------------------------------- */

.gloss {
    display: grid;
    gap: 2px;
    margin: 0;
    background: var(--ink);
    border: var(--rule);
}

@media (min-width: 700px) {
    .gloss { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.gloss > div {
    background: var(--paper);
    padding: clamp(1.1rem, 0.9rem + 1vw, 1.6rem);
}

.gloss dt {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 1.15rem;
    letter-spacing: -0.02em;
    margin-bottom: 0.4rem;
}

.gloss dd {
    margin: 0;
    font-size: var(--t-sm);
    line-height: 1.55;
}

.gloss .hg,
.gloss .gloss__also {
    display: block;
    margin-top: 0.5rem;
    font-family: var(--font-mono);
    font-size: var(--t-xs);
    letter-spacing: 0.04em;
    color: var(--ink-quiet);
    white-space: normal;
}

/* --------------------------------------------------------------------------
   17. Era list — the Souss timeline
   -------------------------------------------------------------------------- */

.eras {
    margin: 0;
    padding: 0;
    list-style: none;
    border-top: var(--rule);
}

.era {
    display: grid;
    gap: 0.25rem 1.5rem;
    padding: 1.1rem 0;
    border-bottom: 1px solid rgba(22, 19, 15, 0.18);
}

@media (min-width: 700px) {
    .era { grid-template-columns: 8.5rem minmax(0, 1fr); }
}

.era__when {
    font-family: var(--font-mono);
    font-size: var(--t-sm);
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--sea);
}

.era__what {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 1.1rem;
    letter-spacing: -0.02em;
    margin: 0 0 0.2rem;
}

.era__note {
    margin: 0;
    font-size: var(--t-sm);
    line-height: 1.55;
    color: var(--ink-quiet);
}

/* --------------------------------------------------------------------------
   18. Phrases — Tifinagh script with transliteration and gloss
   -------------------------------------------------------------------------- */

.phrase__script {
    display: block;
    font-family: var(--font-tifinagh);
    font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.2rem);
    line-height: 1.3;
    margin-bottom: 0.35rem;
}

.phrase__latin {
    display: block;
    font-family: var(--font-mono);
    font-size: var(--t-sm);
    font-weight: 600;
    margin-bottom: 0.15rem;
}

.phrase__gloss {
    display: block;
    font-size: var(--t-sm);
    color: var(--ink-quiet);
}

/* Full --on-colour, not a dimmed white: 85% white composites to 4.38:1 over
   --mountain and fails AA. Opacity is not free on a coloured ground. */
.block--sea .phrase__gloss,
.block--mountain .phrase__gloss,
.block--yaz .phrase__gloss,
.block--ink .phrase__gloss { color: var(--on-colour); }

/* --------------------------------------------------------------------------
   19. Forms
   -------------------------------------------------------------------------- */

.form {
    display: grid;
    gap: var(--gap);
    max-width: 46rem;
}

.field { display: grid; gap: 0.4rem; }

.field label {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: var(--t-sm);
    letter-spacing: -0.01em;
}

.field input,
.field select,
.field textarea {
    min-height: 48px;
    padding: 0.7rem 0.85rem;
    font-family: var(--font-body);
    font-size: 1rem;
    color: var(--ink);
    background: var(--paper);
    border: var(--rule);
    border-radius: 0;
    width: 100%;
}

.field textarea {
    min-height: 9rem;
    resize: vertical;
    line-height: 1.55;
}

.field__help {
    font-size: var(--t-xs);
    color: var(--ink-quiet);
}

.field--check {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
    gap: 0.65rem;
}

.field--check input {
    min-height: 0;
    width: 22px;
    height: 22px;
    margin-top: 0.15rem;
}

.form__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.form__note {
    font-size: var(--t-sm);
    color: var(--ink-quiet);
    max-width: 62ch;
}

.required { color: var(--yaz); }

/* --------------------------------------------------------------------------
   20. Paper entries — the research index
   -------------------------------------------------------------------------- */

.papers {
    margin: 0;
    padding: 0;
    list-style: none;
    border-top: var(--rule);
}

.paper {
    display: grid;
    gap: 0.3rem 1.5rem;
    padding: 1.25rem 0;
    border-bottom: 1px solid rgba(22, 19, 15, 0.18);
}

@media (min-width: 800px) {
    .paper { grid-template-columns: 7rem minmax(0, 1fr); }
}

.paper__year {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 1.35rem;
    letter-spacing: -0.03em;
    color: var(--sea);
}

/* Year and exact date share one grid cell: side by side on phones, stacked
   in the 7rem column from 800px. The date is first online publication. */
.paper__when {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0 0.75rem;
}

@media (min-width: 800px) {
    .paper__when { flex-direction: column; gap: 0.1rem; }
}

.paper__date {
    font-family: var(--font-mono);
    font-size: var(--t-xs);
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--ink);
    white-space: nowrap;
}

.paper__title {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 1.15rem;
    line-height: 1.15;
    letter-spacing: -0.02em;
    margin: 0 0 0.35rem;
}

.paper__title a { color: var(--ink); }

.paper__finding {
    margin: 0 0 0.5rem;
    font-size: var(--t-sm);
    line-height: 1.55;
}

.paper__meta {
    font-family: var(--font-mono);
    font-size: var(--t-xs);
    letter-spacing: 0.04em;
    color: var(--ink-quiet);
}

/* The journal was here all along in quiet grey and read as noise; in ink it
   is the second thing the eye finds after the title. */
.paper__journal {
    font-style: normal;
    font-weight: 600;
    color: var(--ink);
}

/* A figure inside a colour band: the caption cannot keep its ink-on-paper
   colours. Full --on-colour is the only value that clears AA on all four
   grounds (a dimmed white fails 4.5:1 against --yaz). */
.band--sea .figure__caption,
.band--mountain .figure__caption,
.band--yaz .figure__caption,
.band--ink .figure__caption,
.band--sea .figure__caption b,
.band--mountain .figure__caption b,
.band--yaz .figure__caption b,
.band--ink .figure__caption b {
    color: var(--on-colour);
}

/* --------------------------------------------------------------------------
   21. Language switcher
   -------------------------------------------------------------------------- */

.langs {
    display: flex;
    align-items: center;
    gap: 2px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.langs a {
    display: flex;
    align-items: center;
    min-height: 48px;
    padding: 0.35rem 0.7rem;
    font-family: var(--font-mono);
    font-size: var(--t-xs);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    text-decoration: none;
    color: var(--ink);
    background: var(--paper-sunk);
}

.langs a:hover { background: var(--ink); color: var(--paper); }

.langs a[aria-current="true"] {
    background: var(--ink);
    color: var(--paper);
}

/* --------------------------------------------------------------------------
   22. Right-to-left
   Arabic is not a translation problem, it is a direction problem: this system
   encodes meaning in left/right (the stripe, the two-lineage diagram, the
   timeline's label sides), so those have to be mirrored, not just reversed.
   -------------------------------------------------------------------------- */

[dir="rtl"] .stripe { transform: scaleX(-1); }

[dir="rtl"] .note {
    border-left: 0;
    border-right: 8px solid var(--sand);
}

[dir="rtl"] .era__when,
[dir="rtl"] .paper__year { text-align: right; }

/* Diagrams are NOT CSS-mirrored — an RTL diagram is authored with mirrored
   geometry in its own source. But `direction: rtl` inherits into the SVG and
   INVERTS text-anchor: `start` then anchors to the right and `end` to the left,
   so every label runs off-canvas and is silently clipped. Pin the SVG to ltr so
   the authored coordinates mean what they say, and let each label pick its own
   text direction from its content. */
[dir="rtl"] .figure__frame svg { direction: ltr; }
[dir="rtl"] .figure__frame svg text { unicode-bidi: plaintext; }

/* Latin identifiers inside RTL text: haplogroups, DOIs and dates must not be
   re-ordered by the bidi algorithm. */
[dir="rtl"] .hg,
[dir="rtl"] .paper__meta,
[dir="rtl"] .page-updated {
    direction: ltr;
    unicode-bidi: isolate;
    display: inline-block;
}

[dir="rtl"] .page-updated { display: block; text-align: right; }

/* The Latin display faces have no Arabic coverage, so an RTL page swaps them.
   Noto Kufi Arabic keeps the geometric poster weight; Noto Sans Arabic reads.
   Plex Mono stays for haplogroups, which are Latin in every language. */
[dir="rtl"] {
    --font-display: "Noto Kufi Arabic", "Bricolage Grotesque", system-ui, sans-serif;
    --font-body: "Noto Sans Arabic", system-ui, sans-serif;
}

/* Arabic needs a little more leading and no negative tracking — the letterforms
   connect, so tightening them damages legibility rather than tidying it. */
[dir="rtl"] body { line-height: 1.85; }

[dir="rtl"] h1,
[dir="rtl"] h2,
[dir="rtl"] h3,
[dir="rtl"] h4 {
    letter-spacing: 0;
    line-height: 1.25;
}

[dir="rtl"] .stat__num { letter-spacing: 0; }

[dir="rtl"] .kicker,
[dir="rtl"] .stat__label,
[dir="rtl"] .door__go {
    letter-spacing: 0;
    text-transform: none;
}

/* Long unbreakable tokens — DOIs, URLs, haplogroup strings — are wider than a
   280px container. They only surfaced on the Arabic pages, where the Arabic body
   face renders the Latin run wider, but the hazard is language-independent. */
p, li, dd, figcaption, .prose, .figure__caption {
    overflow-wrap: break-word;
}
