/* ============================================================
   أوراق تحرّرية — design tokens & base
   Reading-optimized palette (research + WCAG-verified).
   Identity kept: warm paper, blue ink, one hot spark —
   but the paper is lifted out of "muddy" into the comfort band,
   and dark mode is retuned to a single warm temperature.
   Body text clears AAA (>=7:1) in BOTH modes.
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }   /* the hidden attribute must win over display:grid/flex */

:root {
  /* palette — light (warm paper) */
  --bg: #f7f2e8;          /* clean warm off-white — lifted from the old muddy beige */
  --surface: #fcfaf4;     /* card / content surface */
  --surface-2: #efe7d8;   /* secondary surface / hover */
  --text: #16324f;        /* blue ink — 11.7:1 on paper (AAA) */
  --muted: #52616c;       /* secondary text — 5.7:1 */
  --faint: #5c6a74;       /* meta / labels — 5.0:1 (AA) */
  --border: #d8cebb;      /* decorative hairline */
  --field-border: #8c7f66;/* functional edges (inputs) — 3.5:1 per SC 1.4.11 */
  --accent: #bc3d18;      /* primary action (the spark, tuned to carry a label) */
  --accent-600: #9e3212;  /* accent hover */
  --on-accent: #ffffff;
  --spark: #d1471e;       /* reserved hot mark: rules, focus rings, small accents */
  --link: #0f4c81;        /* in-body links — blue, 7.9:1 (always underline in prose) */
  --link-hover: #0d3f6e;
  --motto: #171310;       /* the masthead line — press-black on paper, 16.9:1 */
  --danger: #b23417;
  --danger-bg: #f3ddd2;
  --danger-border: #e0b6a4;
  --ok: #2f6f4f;
  --ok-bg: #dfeadf;
  --ok-border: #b3cdb9;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(22, 50, 79, .06);
  --shadow: 0 2px 6px rgba(22, 50, 79, .06), 0 20px 44px rgba(22, 50, 79, .10);

  --display: 'Lalezar', 'Reem Kufi', cursive;
  --sans: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
  /* Owner-chosen faces. font_style_tag() in app/settings.php overrides these
     per page; the values here are the fallback when nothing is set, so the
     site looks exactly as it does today if storage/settings.json is absent. */
  --font-title: var(--sans);
  --font-body: var(--sans);
  --title-weight: 700;

  --grain-blend: multiply;
  --grain-opacity: .04;
  color-scheme: light;
}

:root[data-theme="dark"] {
  /* palette — dark (single warm temperature; not pure black, text not pure white) */
  --bg: #1c1815;          /* warm near-black */
  --surface: #262019;
  --surface-2: #2e2820;
  --text: #ddd4c4;        /* dimmed warm cream — 12:1 (AAA), no halation */
  --muted: #a89f8b;       /* 6.7:1 */
  --faint: #938a76;       /* 5.2:1 (AA) */
  --border: #38332c;      /* decorative hairline */
  --field-border: #867c69;/* functional edges — 3.5:1 */
  --accent: #f0774e;      /* desaturated/lifted spark for the button */
  --accent-600: #e3663b;
  --on-accent: #1c1815;   /* dark-on-orange reads more native on dark UI */
  --spark: #ff7a4d;
  --link: #7cc0e8;        /* light blue link — 8.9:1 */
  --link-hover: #a6d4f0;
  --motto: #efe7d8;       /* black would vanish here — the same weight, inverted (14.3:1) */
  --danger: #ff7d63;
  --danger-bg: #2a1512;
  --danger-border: #5a2a20;
  --ok: #64c38a;
  --ok-bg: #12231a;
  --ok-border: #274f38;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 2px 6px rgba(0, 0, 0, .4), 0 22px 46px rgba(0, 0, 0, .5);
  --grain-blend: soft-light;
  --grain-opacity: .08;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #1c1815; --surface: #262019; --surface-2: #2e2820;
    --text: #ddd4c4; --muted: #a89f8b; --faint: #938a76;
    --border: #38332c; --field-border: #867c69;
    --accent: #f0774e; --accent-600: #e3663b; --on-accent: #1c1815; --spark: #ff7a4d;
    --link: #7cc0e8; --link-hover: #a6d4f0; --motto: #efe7d8;
    --danger: #ff7d63; --danger-bg: #2a1512; --danger-border: #5a2a20;
    --ok: #64c38a; --ok-bg: #12231a; --ok-border: #274f38;
    --grain-blend: soft-light; --grain-opacity: .08; color-scheme: dark;
  }
}

body {
  margin: 0;
  font-family: var(--font-body, var(--sans));
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background .3s ease, color .3s ease;
}

/* printed paper grain — the pamphlet tactility (kept subtle) */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  opacity: var(--grain-opacity);
  mix-blend-mode: var(--grain-blend);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.82' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; font-weight: 600; }

/* links — blue in both modes (only colorblind-safe choice on warm paper + ink) */
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; }
img { max-width: 100%; display: block; }

/* ---- forms ---- */
.field { margin-bottom: 1.05rem; display: flex; flex-direction: column; gap: .4rem; }
label { font-size: .82rem; font-weight: 500; color: var(--muted); }
input, select, textarea {
  width: 100%; padding: .72rem .9rem; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--field-border); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--spark);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--spark) 26%, transparent);
}
::placeholder { color: var(--faint); opacity: .85; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .72rem 1.2rem; font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  transition: background .15s, transform .05s, box-shadow .15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-600); color: var(--on-accent); text-decoration: none; }
.btn-ghost { background: transparent; border-color: var(--field-border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.btn-block { width: 100%; }

/* keyboard focus — visible, in the spark colour */
a:focus-visible, .btn:focus-visible, .theme-toggle:focus-visible {
  outline: 2px solid var(--spark); outline-offset: 3px; border-radius: 4px;
}

/* ---- alerts ---- */
.alert { padding: .7rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-size: .9rem; border: 1px solid transparent; }
.alert-danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-border); }
.alert-ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-border); }

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