/*
 * Flawta design tokens — charcoal-first editorial identity.
 * Integrate through the existing Zola stylesheet entry point.
 * Validate actual color pairs with a contrast checker before release.
 */

:root {
  color-scheme: light;

  /* Clean neutral light theme */
  --color-bg: #fafafa;
  --color-surface: #ffffff;
  --color-surface-raised: #ffffff;
  --color-surface-muted: #f0f0f0;
  --color-text: #1f2326;
  --color-text-muted: #4a5055;
  --color-text-subtle: #5c6267;
  --color-border: #e5e5e5;
  --color-border-strong: #d0d0d0;
  --color-accent: #76552b;
  --color-accent-hover: #604321;
  --color-accent-soft: #f0f0f0;
  --color-link: #315b50;
  --color-link-hover: #23483f;
  --color-success: #286345;
  --color-warning: #76521c;
  --color-danger: #a13d35;
  --color-focus: #1b6eaa;
  --color-selection: #e0e0e0;
  --shadow-soft: 0 1px 2px rgb(22 25 27 / 7%);
  --shadow-raised: 0 8px 24px rgb(22 25 27 / 9%);

  /* Control backgrounds — neutral, works in both themes */
  --color-control-bg: #f5f5f5;
  --color-control-bg-active: #ffffff;

  /* ==========================================================================
     TYPOGRAPHY TOKENS — centralized editorial type system
     Latin (en, fr) and Arabic (ar) are configured independently.
     ========================================================================== */

  /* Latin script fonts (en, fr) */
  --font-heading-latin: "Newsreader", "Newsreader Fallback", Georgia, "Times New Roman", serif;
  --font-body-latin: "Source Serif 4", "Noto Naskh Arabic", "Source Serif 4 Fallback", Georgia, "Times New Roman", serif;
  --font-ui-latin: "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;

  /* Arabic script fonts (ar) */
  --font-ui-arabic: "Noto Sans Arabic", Arial, Tahoma, sans-serif;
  --font-body-arabic: "Noto Naskh Arabic", "Noto Sans Arabic", Tahoma, serif;
  --font-heading-arabic: var(--font-ui-arabic);
  --font-ui: var(--font-ui-latin);
  --font-body: var(--font-body-latin);
  --font-heading: var(--font-heading-latin);

  /* Latin editorial body text */
  --text-body-size: 1.125rem;              /* 18px mobile */
  --text-body-size-desktop: 1.1875rem;    /* 19px desktop */
  --text-body-line-height: 1.65;

  /* Latin editorial headings */
  --heading-h1-size: clamp(2rem, 1.65rem + 1.5vw, 2.75rem);
  --heading-h2-size: clamp(1.6875rem, 1.5rem + 0.8vw, 2rem);
  --heading-h3-size: clamp(1.4375rem, 1.35rem + 0.4vw, 1.5625rem);
  --heading-h4-size: clamp(1.25rem, 1.2rem + 0.2vw, 1.3125rem);
  --heading-h5-size: 1.125rem;
  --heading-h6-size: 1rem;
  --heading-line-height: 1.25;
  --heading-letter-spacing: -0.02em;

  /* Arabic editorial body text */
  --text-ar-body-size: 1.1875rem;
  --text-ar-body-size-desktop: 1.25rem;
  --text-ar-body-line-height: 1.85;

  /* Arabic editorial headings */
  --heading-ar-h1-size: clamp(2rem, 1.65rem + 1.5vw, 2.75rem);
  --heading-ar-h2-size: clamp(1.625rem, 1.4rem + 0.8vw, 1.9375rem);
  --heading-ar-h3-size: clamp(1.375rem, 1.3rem + 0.4vw, 1.5rem);
  --heading-ar-h4-size: 1.25rem;
  --heading-ar-h5-size: 1.125rem;
  --heading-ar-h6-size: 1rem;
  --heading-ar-line-height: 1.5;

  /* Paragraph spacing */
  --paragraph-spacing: 1.2em;

  /* Reading width */
  --reading-width: 47.5rem;
  --text-meta: 0.9375rem;
  --text-caption: 0.9375rem;
  --text-card-title: clamp(1.3125rem, 1.2rem + 0.5vw, 1.4375rem);

  /* Text scale tokens (kept for component compatibility) */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1.125rem;
  --text-lg: 1.1875rem;
  --text-xl: 1.375rem;
  --text-2xl: clamp(1.65rem, 3vw, 2.15rem);
  --text-3xl: clamp(2rem, 4vw, 3.1rem);
  --text-display: clamp(2.6rem, 6vw, 5rem);

  --leading-tight: 1.2;
  --leading-heading: 1.2;
  --leading-body: 1.70;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;

  --content-width: 75rem;
  --page-gutter: clamp(1.125rem, 4vw, 3.5rem);

  --radius-sm: 0.2rem;
  --radius-md: 0.4rem;
  --radius-lg: 0.65rem;
  --radius-pill: 999px;

  --control-height: 2.5rem;
  --border-width: 1px;
  --transition-fast: 140ms ease;
  --transition-normal: 220ms ease;
}

/* ==========================================================================
   FONT FACE — Newsreader (Latin editorial headings)
   Variable font: wght 200–800, opsz 6–72. Self-hosted WOFF2.
   License: SIL Open Font License 1.1
   ========================================================================== */
@font-face {
  font-family: "Newsreader";
  src: url("../fonts/Newsreader-Variable.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Newsreader Fallback";
  src: local("Georgia"), local("Times New Roman");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
  size-adjust: 98.5%;
}

/* ==========================================================================
   FONT FACE — Source Serif 4 (Latin editorial body)
   Variable font: wght 200–900, opsz 8–60. Self-hosted WOFF2.
   License: SIL Open Font License 1.1
   ========================================================================== */
@font-face {
  font-family: "Source Serif 4";
  src: url("../fonts/SourceSerif4-Variable.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Source Serif 4 Fallback";
  src: local("Georgia"), local("Times New Roman");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
  size-adjust: 100%;
}

@font-face {
  font-family: "Source Sans 3";
  src: url("../fonts/SourceSans3-Latin-Variable.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Source Sans 3";
  src: url("../fonts/SourceSans3-LatinExt-Variable.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ==========================================================================
   FONT FACE — Noto Sans Arabic (Arabic UI and navigation)
   Variable font: wght 100–900, wdth 62.5–100. Self-hosted WOFF2.
   License: SIL Open Font License 2.1
   ========================================================================== */
@font-face {
  font-family: "Noto Sans Arabic";
  src: url("../fonts/NotoSansArabic-Variable.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

/* ==========================================================================
   FONT FACE — Noto Naskh Arabic (Arabic editorial text)
   Variable font: wght 400–700. Self-hosted WOFF2.
   License: SIL Open Font License 2.1
   ========================================================================== */
@font-face {
  font-family: "Noto Naskh Arabic";
  src: url("../fonts/NotoNaskhArabic-Variable.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

/* Explicit dark theme: deep charcoal, never pure black. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --color-bg: #0f1113;
  --color-surface: #15181b;
  --color-surface-raised: #1c2024;
  --color-surface-muted: #121518;
  --color-text: #eae7e2;
  --color-text-muted: #b0b4b7;
  --color-text-subtle: #969b9e;
  --color-border: #2a2e32;
  --color-border-strong: #42484e;
  --color-accent: #c4a16a;
  --color-accent-hover: #d5b982;
  --color-accent-soft: #332a20;
  --color-link: #b9d2c8;
  --color-link-hover: #d1e3dc;
  --color-success: #91c6a5;
  --color-warning: #e0bd7d;
  --color-danger: #ef9b91;
  --color-focus: #83bdf0;
  --color-selection: #52442c;
  --shadow-soft: 0 1px 2px rgb(0 0 0 / 22%);
  --shadow-raised: 0 10px 28px rgb(0 0 0 / 28%);

  /* Control backgrounds — neutral, works in both themes */
  --color-control-bg: #1a1d21;
  --color-control-bg-active: #262a2e;
}

/* Auto mode follows the OS only when no explicit theme is selected. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    color-scheme: dark;
    --color-bg: #0f1113;
    --color-surface: #15181b;
    --color-surface-raised: #1c2024;
    --color-surface-muted: #121518;
    --color-text: #eae7e2;
    --color-text-muted: #b0b4b7;
    --color-text-subtle: #969b9e;
    --color-border: #2a2e32;
    --color-border-strong: #42484e;
    --color-accent: #c4a16a;
    --color-accent-hover: #d5b982;
    --color-accent-soft: #332a20;
    --color-link: #b9d2c8;
    --color-link-hover: #d1e3dc;
    --color-success: #91c6a5;
    --color-warning: #e0bd7d;
    --color-danger: #ef9b91;
    --color-focus: #83bdf0;
    --color-selection: #52442c;
    --shadow-soft: 0 1px 2px rgb(0 0 0 / 22%);
    --shadow-raised: 0 10px 28px rgb(0 0 0 / 28%);

    /* Control backgrounds — neutral, works in both themes */
    --color-control-bg: #1a1d21;
    --color-control-bg-active: #262a2e;
  }
}

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

html {
  background: var(--color-bg);
  color: var(--color-text);
  scroll-behavior: smooth;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-ui);
  font-size: var(--text-body-size);
  line-height: var(--text-body-line-height);
}

h1, h2, h3, h4, h5, h6 {
  color: var(--color-text);
  font-family: var(--font-heading);
  font-weight: 500;
  line-height: var(--heading-line-height);
  text-wrap: balance;
}

h1 { font-size: var(--heading-h1-size); line-height: 1.15; letter-spacing: var(--heading-letter-spacing); }
h2 { font-size: var(--heading-h2-size); letter-spacing: var(--heading-letter-spacing); }
h3 { font-size: var(--heading-h3-size); line-height: 1.3; letter-spacing: -0.015em; }
h4 { font-size: var(--heading-h4-size); line-height: 1.35; letter-spacing: normal; }
h5 { font-size: var(--heading-h5-size); letter-spacing: normal; }
h6 { font-size: var(--heading-h6-size); letter-spacing: normal; }

/* Arabic typography */
html:lang(ar) {
  --font-ui: var(--font-ui-arabic);
  --font-body: var(--font-body-arabic);
  --font-heading: var(--font-heading-arabic);
}

html:lang(ar) :is(h1, h2, h3, h4, h5, h6) {
  font-weight: 600;
  line-height: var(--heading-ar-line-height);
  letter-spacing: normal;
}

:lang(ar) h1 { font-size: var(--heading-ar-h1-size); }
:lang(ar) h2 { font-size: var(--heading-ar-h2-size); }
:lang(ar) h3 { font-size: var(--heading-ar-h3-size); }
:lang(ar) h4 { font-size: var(--heading-ar-h4-size); }
:lang(ar) h5 { font-size: var(--heading-ar-h5-size); }
:lang(ar) h6 { font-size: var(--heading-ar-h6-size); }

html:lang(ar) {
  font-synthesis: none;
}

p { text-wrap: pretty; }

a {
  color: var(--color-link);
  text-decoration-thickness: 0.07em;
  text-underline-offset: 0.18em;
}

a:hover { color: var(--color-link-hover); }

:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 3px;
}

::selection {
  background: var(--color-selection);
  color: var(--color-text);
}

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

img,
video { height: auto; }

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

button { color: inherit; }

hr {
  border: 0;
  border-block-start: var(--border-width) solid var(--color-border);
}

.surface {
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
}

.surface-raised {
  background: var(--color-surface-raised);
  border: var(--border-width) solid var(--color-border);
  box-shadow: var(--shadow-soft);
}

.muted { color: var(--color-text-muted); }

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

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

.skip-link {
  position: absolute;
  z-index: 1000;
  inset-block-start: var(--space-2);
  inset-inline-start: var(--space-2);
  transform: translateY(-160%);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-raised);
  color: var(--color-text);
  border: 2px solid var(--color-focus);
}

.skip-link:focus { transform: translateY(0); }

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (forced-colors: active) {
  :focus-visible {
    outline: 2px solid Highlight;
  }
}
