/* ==========================================================================
   base.css — reset, design tokens, typography scale
   --------------------------------------------------------------------------
   Everything here is direction-agnostic. Spacing uses logical properties
   (margin-inline / padding-block ...) so the Arabic (dir="rtl") build mirrors
   without a separate stylesheet. See the note at the bottom of components.css
   for the few genuinely directional exceptions.
   ========================================================================== */

/* --- 1. Reset ------------------------------------------------------------ */

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

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

body,
h1, h2, h3, h4, p,
figure, blockquote,
dl, dd,
ul, ol {
  margin: 0;
  padding: 0;
}

ul[class],
ol[class] {
  list-style: none;
}

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

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

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

a {
  color: inherit;
}

:target {
  scroll-margin-block-start: 6rem;
}

/* --- 2. Design tokens ---------------------------------------------------- *
 * The palette is a cool paper neutral with a single deep-green accent.
 * Deliberately not the cream/terracotta or dark/neon defaults.              */

:root {
  /* Surfaces */
  --paper:         #fcfcfc;
  --paper-raised:  #ffffff;
  --paper-sunken:  #f1f2f1;
  --paper-invert:  #15181a;

  /* Ink */
  --ink:           #15181a;   /* headings, primary text */
  --ink-2:         #4b535b;   /* body prose */
  --ink-3:         #7e868e;   /* metadata, captions */
  --ink-invert:    #f4f5f4;

  /* Lines */
  --rule:          #e2e4e2;
  --rule-strong:   #c9ccc9;

  /* Accent — used sparingly: links, active states, the one hero rule. */
  --accent:        #14584a;
  --accent-hover:  #0e3f35;
  --accent-soft:   #e7efeb;
  --accent-ink:    #0b3129;

  /* Type */
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI",
               Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, "JetBrains Mono", "SFMono-Regular", "SF Mono",
               Menlo, Consolas, "Liberation Mono", monospace;

  /* Fluid type scale (1.25 minor third at the small end, wider at the top).
     clamp() keeps the hero from overwhelming a 360px phone.               */
  --step--1: clamp(0.8rem,  0.77rem + 0.15vw, 0.875rem);
  --step-0:  clamp(1rem,    0.96rem + 0.2vw,  1.0625rem);
  --step-1:  clamp(1.2rem,  1.13rem + 0.35vw, 1.4rem);
  --step-2:  clamp(1.45rem, 1.31rem + 0.7vw,  1.85rem);
  --step-3:  clamp(1.75rem, 1.5rem  + 1.25vw, 2.5rem);
  --step-4:  clamp(2.1rem,  1.6rem  + 2.5vw,  3.5rem);
  --step-5:  clamp(2.5rem,  1.55rem + 4.75vw, 5.25rem);

  /* Rhythm */
  --space-3xs: 0.25rem;
  --space-2xs: 0.5rem;
  --space-xs:  0.75rem;
  --space-s:   1rem;
  --space-m:   1.5rem;
  --space-l:   2.25rem;
  --space-xl:  3.5rem;
  --space-2xl: 5.5rem;
  --space-3xl: 8rem;

  /* Layout */
  --measure: 62ch;          /* max comfortable prose width */
  --shell:   72rem;         /* page gutter-to-gutter max width */
  --gutter:  clamp(1.25rem, 5vw, 3.5rem);
  --radius:  4px;

  /* Motion — one shared easing so everything feels like one system. */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --dur-fast: 180ms;
  --dur-mid:  420ms;
  --dur-slow: 900ms;

  /* Direction multiplier. Any transform that moves along the inline axis
     multiplies by this so it mirrors correctly under dir="rtl".           */
  --dir: 1;
}

[dir="rtl"] {
  --dir: -1;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:        #101214;
    --paper-raised: #171a1d;
    --paper-sunken: #0b0d0e;
    --paper-invert: #f4f5f4;

    --ink:          #eef0ee;
    --ink-2:        #b3bab8;
    --ink-3:        #838b8a;
    --ink-invert:   #15181a;

    --rule:         #262a2c;
    --rule-strong:  #3a4044;

    --accent:       #5fbfa6;
    --accent-hover: #86d4bf;
    --accent-soft:  #14251f;
    --accent-ink:   #d6efe6;
  }
}

/* --- 3. Base typography -------------------------------------------------- */

body {
  background-color: var(--paper);
  color: var(--ink-2);
  font-family: var(--font-sans);
  font-size: var(--step-0);
  line-height: 1.6;
  font-synthesis-weight: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

/* Arabic gets a slightly larger line-height: the script has taller ascenders
   and diacritics that collide at 1.6. */
[lang="ar"] body {
  font-family: "Noto Naskh Arabic", "Segoe UI", Tahoma, var(--font-sans);
  line-height: 1.85;
}

h1, h2, h3, h4 {
  color: var(--ink);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

h1 { font-size: var(--step-5); letter-spacing: -0.035em; }
h2 { font-size: var(--step-4); letter-spacing: -0.03em; }
h3 { font-size: var(--step-2); }
h4 { font-size: var(--step-1); }

p {
  text-wrap: pretty;
}

strong {
  color: var(--ink);
  font-weight: 600;
}

/* --- 4. Shared utilities -------------------------------------------------- */

.prose {
  max-inline-size: var(--measure);
}

/* Small uppercase mono label used above every section title and on metadata. */
.eyebrow {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--step--1);
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

[lang="ar"] .eyebrow {
  letter-spacing: normal;
  text-transform: none;
}

.mono {
  font-family: var(--font-mono);
  font-size: 0.9em;
  font-variant-numeric: tabular-nums;
}

/* Visually hidden but readable by screen readers and still focusable. */
.visually-hidden:not(:focus):not(:active) {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  inset-block-start: var(--space-2xs);
  inset-inline-start: var(--space-2xs);
  z-index: 100;
  padding: var(--space-2xs) var(--space-s);
  background: var(--paper-raised);
  color: var(--ink);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
}

/* One consistent focus ring everywhere — never removed, only restyled. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}
