/* =========================================================================
   Jamaity — base
   Reset, document defaults, typography, bi-directional rules, motion layer.

   RULE: no physical direction properties anywhere in this project.
   Use margin-inline-*, padding-inline-*, inset-inline-*, border-inline-*,
   text-align: start/end. RTL then costs nothing.
   ========================================================================= */

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

* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-block-start: var(--sp-24);
}

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

body {
  font-family: var(--font);
  font-size: var(--fs-md);
  font-weight: var(--fw-regular);
  line-height: var(--lh-normal);
  color: var(--text);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern" 1, "liga" 1;
  min-block-size: 100vh;
}

img, svg, video, canvas, picture {
  display: block;
  max-inline-size: 100%;
  block-size: auto;
}

input, button, textarea, select {
  font: inherit;
  color: inherit;
}

button { background: none; border: none; padding: 0; cursor: pointer; }

p, h1, h2, h3, h4, h5, h6 { overflow-wrap: break-word; }

ul, ol { padding: 0; list-style: none; }

/* -------------------------------------------------------------------------
   Headings — tight leading, slight negative tracking, weight carries the
   emphasis rather than size alone.
   ------------------------------------------------------------------------- */

h1, h2, h3, h4, h5, h6 {
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
  letter-spacing: var(--tracking-tight);
  color: var(--text);
  text-wrap: balance;
}

h1 { font-size: var(--fs-3xl); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); }
h4 { font-size: var(--fs-lg); line-height: var(--lh-snug); }
h5 { font-size: var(--fs-md); line-height: var(--lh-snug); }
h6 {
  font-size: var(--fs-xs);
  line-height: var(--lh-snug);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  font-weight: var(--fw-semibold);
}

p { text-wrap: pretty; }

a {
  color: var(--text-link);
  text-decoration-thickness: var(--stroke);
  text-underline-offset: 0.22em;
  transition: color var(--dur-fast) var(--ease-out);
}

a:hover { color: var(--blue-500); }

/* -------------------------------------------------------------------------
   Focus — visible, round, offset. Echoes the logo's open gap: the ring
   never touches the element.
   ------------------------------------------------------------------------- */

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

::selection {
  background: var(--mint-200);
  color: var(--blue-800);
}

/* -------------------------------------------------------------------------
   Bi-directional typography

   Arabic and Latin share Cairo, but Arabic needs slightly more size and
   noticeably more leading to read evenly beside Latin at the same nominal
   size. Applied by language, not by changing the scale.
   ------------------------------------------------------------------------- */

/* The Arabic boost goes on the SCALE TOKENS, never as an em multiplier on the
   container.

   An em multiplier scales every descendant — icons, metadata, the line box of
   a card footer — so an Arabic card ends up 5px taller than its French
   neighbours in the same grid, its hairlines land on different fractional
   pixels, and they render visibly softer. Redefining the tokens changes only
   what actually uses the type scale, and it cannot compound, because each
   level recomputes from --fs-*-raw rather than from the inherited value. */
:is([lang="ar"], [dir="rtl"]) {
  --fs-2xs: calc(var(--fs-2xs-raw) * var(--ar-size-boost));
  --fs-xs:  calc(var(--fs-xs-raw)  * var(--ar-size-boost));
  --fs-sm:  calc(var(--fs-sm-raw)  * var(--ar-size-boost));
  --fs-md:  calc(var(--fs-md-raw)  * var(--ar-size-boost));
  --fs-lg:  calc(var(--fs-lg-raw)  * var(--ar-size-boost));
  --fs-xl:  calc(var(--fs-xl-raw)  * var(--ar-size-boost));
  --fs-2xl: calc(var(--fs-2xl-raw) * var(--ar-size-boost));
  --fs-3xl: calc(var(--fs-3xl-raw) * var(--ar-size-boost));
  --fs-4xl: calc(var(--fs-4xl-raw) * var(--ar-size-boost));

  letter-spacing: 0;              /* Arabic must never be tracked */
}

/* Leading goes on the text itself, not the container, for the same reason. */
:is([lang="ar"], [dir="rtl"]) :is(p, li, dd, dt, blockquote) {
  line-height: calc(var(--lh-normal) * var(--ar-lh-boost));
}

:is([lang="ar"], [dir="rtl"]) :is(h1, h2, h3, h4, h5, h6) {
  letter-spacing: 0;
  line-height: calc(var(--lh-tight) * var(--ar-lh-boost));
  font-weight: var(--fw-bold);
}

/* Arabic has no uppercase. Small-caps eyebrows must not transform. */
[lang="ar"] h6, [dir="rtl"] h6 {
  text-transform: none;
  letter-spacing: 0;
}

/* Numerals stay Latin in both directions — deadlines, counts and dates are
   read by a mixed audience and Jamaity's own Arabic pages use Latin digits. */
[lang="ar"] .u-num, [dir="rtl"] .u-num {
  font-variant-numeric: lining-nums tabular-nums;
  direction: ltr;
  unicode-bidi: isolate;
}

/* Mixed-script records: isolate so a Latin org name inside an Arabic line
   does not reorder the punctuation around it. */
.bidi-isolate { unicode-bidi: isolate; }

/* -------------------------------------------------------------------------
   Icons — round caps everywhere, no exceptions. This is the single most
   recognisable trait of the mark, so it is enforced globally rather than
   left to each icon file.
   ------------------------------------------------------------------------- */

svg:not([data-raw]) {
  fill: none;
  stroke: currentColor;
  stroke-width: var(--stroke-bold);
  stroke-linecap: round;
  stroke-linejoin: round;
}

svg[data-raw] { fill: currentColor; stroke: none; }

svg.icon {
  inline-size: 1.25em;
  block-size: 1.25em;
  flex: none;
  vertical-align: -0.22em;
}

svg.icon--sm { inline-size: 1em;    block-size: 1em; }
svg.icon--lg { inline-size: 1.75em; block-size: 1.75em; }

/* Phosphor webfont icons. Sized by font-size rather than box, so the same
   .icon / .icon--sm / .icon--lg classes keep meaning what they meant when
   these were inline SVGs: 1.25em / 1em / 1.75em of the parent's type size.
   flex:none because an icon in a flex row must never be the thing that
   shrinks, and the explicit block-size stops a glyph whose ink box is taller
   than 1em from growing the line box of a card footer. */
i.ph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  font-size: 1.25em;
  block-size: 1em;
  inline-size: 1em;
  vertical-align: -0.16em;
}

i.ph.icon--sm { font-size: 1em; }
i.ph.icon--lg { font-size: 1.75em; }

/* The mark's icons are round-capped and open; Phosphor's "regular" weight is
   the closest match in the family, so no weight class is used anywhere. */

/* -------------------------------------------------------------------------
   Layout primitives
   ------------------------------------------------------------------------- */

.container {
  inline-size: min(100% - (var(--gutter) * 2), var(--container));
  margin-inline: auto;
}

.container--narrow { inline-size: min(100% - (var(--gutter) * 2), var(--container-narrow)); }
.container--wide   { inline-size: min(100% - (var(--gutter) * 2), var(--container-wide)); }

.section { padding-block: var(--section-y); }

/* The first section after the hero. A full --section-y above it is the right
   rhythm BETWEEN sections, but under the hero it reads as dead space and
   pushes the section below the fold — the hero's own bottom padding and the
   wedge already provide the separation. */
.section--lead { padding-block-start: clamp(1.75rem, 0.75rem + 2vw, 2.75rem); }
.section--sunken { background: var(--surface-sunken); }

.stack > * + * { margin-block-start: var(--flow, var(--sp-4)); }

.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--gap, var(--sp-3));
}

.grid-auto {
  display: grid;
  gap: var(--gap, var(--sp-6));
  /* min() guard: without it a track wider than the container (--min 330px in
     a 328px column) forces the grid to overflow by the difference. */
  /* auto-FIT, not auto-fill: auto-fill keeps the empty tracks it created, so a
     row of four cards in a six-track grid left two card-widths of dead space
     on the end. auto-fit collapses the empty tracks and the real cards stretch
     to fill the row. With a full grid the two behave identically. */
  grid-template-columns: repeat(auto-fit, minmax(min(var(--min, 260px), 100%), 1fr));
}

/* -------------------------------------------------------------------------
   Utilities
   ------------------------------------------------------------------------- */

.u-measure { max-inline-size: var(--measure); }
.u-muted   { color: var(--text-muted); }
.u-subtle  { color: var(--text-subtle); }
.u-center  { text-align: center; }

/* Quiet editorial label. Deliberately not brand-coloured and deliberately
   undecorated — a coloured dot on every section heading is the fastest way to
   make a site look generated. */
.u-eyebrow {
  display: inline-flex;
  align-items: center;
  /* An inline-flex row does not wrap by default, so a long eyebrow
     ("23 588 opportunités · 2 299 organisations") becomes an unbreakable
     324px min-content block that pushes its whole grid column wider than the
     viewport. Chrome text is never load-bearing enough to justify that. */
  flex-wrap: wrap;
  gap: var(--sp-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-muted);
}

/* The dot motif — the logo's diacritics, tittles and chimney — is opt-in and
   reserved for places where it carries meaning: active state, status,
   list bullets. Not decoration. */
.u-dot::before {
  content: "";
  inline-size: 0.5em;
  block-size: 0.5em;
  border-radius: var(--radius-pill);
  background: currentColor;
  flex: none;
}

.u-clamp-1, .u-clamp-2, .u-clamp-3 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.u-clamp-1 { -webkit-line-clamp: 1; line-clamp: 1; }
.u-clamp-2 { -webkit-line-clamp: 2; line-clamp: 2; }
.u-clamp-3 { -webkit-line-clamp: 3; line-clamp: 3; }

.visually-hidden {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* -------------------------------------------------------------------------
   Motion layer

   Elements opt in with data-anim. A single IntersectionObserver in
   motion.js adds .is-in. Everything degrades to visible-by-default if JS
   never runs — critical, because a directory must render without it.
   ------------------------------------------------------------------------- */

[data-anim] {
  --anim-delay: 0ms;
  transition:
    opacity var(--dur-slow) var(--ease-entrance) var(--anim-delay),
    transform var(--dur-slow) var(--ease-entrance) var(--anim-delay);
}

/* Only hide when JS is present to reveal it again. */
.js [data-anim]:not(.is-in) { opacity: 0; }

.js [data-anim="rise"]:not(.is-in)  { transform: translateY(20px); }
.js [data-anim="fall"]:not(.is-in)  { transform: translateY(-16px); }
.js [data-anim="enter"]:not(.is-in) { transform: translateX(-20px); }
.js [data-anim="scale"]:not(.is-in) { transform: scale(0.96); }

[data-anim].is-in { opacity: 1; transform: none; }

/* Stroke-draw: the logo is drawn, so key graphics draw themselves in.
   [data-raw] shapes are filled, not stroked, so they sit this out. */
.js [data-anim="draw"] :is(path, circle, line, polyline, rect):not([data-raw]) {
  stroke-dasharray: var(--len, 1200);
  stroke-dashoffset: var(--len, 1200);
  transition: stroke-dashoffset var(--dur-slower) var(--ease-out) var(--anim-delay);
}

.js [data-anim="draw"].is-in :is(path, circle, line, polyline, rect):not([data-raw]) {
  stroke-dashoffset: 0;
}

/* Theme switching.

   Cards, buttons and fields all transition their background and border, so
   flipping the theme cross-fades the entire page one component at a time and
   looks broken. The switch is suppressed for a frame instead: the new theme
   appears at once, the way a theme change should. */
:root[data-theme-switching] *,
:root[data-theme-switching] *::before,
:root[data-theme-switching] *::after {
  transition: none !important;
}

/* The brand mark.

   The logo is vectorised in the source file — filled outlines, not strokes —
   so it cannot be drawn with stroke-dashoffset without being redrawn, and
   redrawing the mark is not an option. Instead its three real elements are
   revealed in sequence: the dot, the house, the arc.

   The svg itself is exempted from the blanket opacity hide below, otherwise
   the whole thing would fade in as one and the sequence would be invisible. */
/* Exempt from the blanket opacity hide: the mark reveals through its masks,
   not by fading in as one block. */
.js [data-anim="mark"]:not(.is-in) { opacity: 1; }

/* The trim. [data-trim] paths live inside <mask> elements and are never
   painted — they only decide how much of the real artwork is visible.
   Each carries its own --trim-delay / --trim-dur so the sequence is
   declared in the markup next to the shape it drives. */
.js [data-anim="mark"] [data-trim] {
  stroke-dasharray: var(--len, 900);
  stroke-dashoffset: var(--len, 900);
  /* Linear, deliberately. Each segment's duration is set from its own length
     so the pen moves at one constant speed across both; any easing would make
     the speed jump at the join and betray it as two animations. */
  transition: stroke-dashoffset
              var(--trim-dur, 800ms)
              linear
              var(--trim-delay, 0ms);
}

.js [data-anim="mark"].is-in [data-trim] { stroke-dashoffset: 0; }

/* The dot is a circle, not a stroke, so it cannot trim. It lands after the
   arc finishes — the last beat of the sequence. */
.js [data-anim="mark"] [data-mark="dot"] {
  opacity: 0;
  transform: scale(0.4);
  transform-box: fill-box;
  transform-origin: center;
  transition:
    opacity   var(--dur-base) var(--ease-out)      var(--dot-delay, 1180ms),
    transform var(--dur-slow) var(--ease-entrance) var(--dot-delay, 1180ms);
}

.js [data-anim="mark"].is-in [data-mark="dot"] { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  .js [data-anim="mark"] [data-trim]        { stroke-dashoffset: 0; }
  .js [data-anim="mark"] [data-mark="dot"]  { opacity: 1; transform: none; }
}

/* Filled accents fade in on the same beat instead. */
.js [data-anim="draw"] [data-raw] {
  opacity: 0;
  transition: opacity var(--dur-slow) var(--ease-out) var(--dur-base);
}
.js [data-anim="draw"].is-in [data-raw] { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .js [data-anim]:not(.is-in) { opacity: 1; transform: none; }
  .js [data-anim="draw"] :is(path, circle, line, polyline, rect):not([data-raw]) {
    stroke-dashoffset: 0;
  }
  .js [data-anim="draw"] [data-raw] { opacity: 1; }
}
