/* ============================================================================
   Cad-Ya · עולם התורה — Design System
   "מעגלי זמן" (Circles of Time): a visual language for cyclical Jewish time —
   the lunar month, the annual Torah cycle, the generations of a family tree.

   One source of truth for tokens (color · type · space · shadow · radius ·
   motion) + a small set of RTL-native, WCAG-AA component primitives, shared by
   all modules. Load this FIRST, before any page-specific <style>.

   Theming: dark is the default (a night sky over parchment). A light
   ("day / parchment") theme is available via <html data-theme="light">.
   ============================================================================ */

:root {
  /* ---- Brand palette (raw) -------------------------------------------------
     gold  = candlelight & the moon (primary accent)
     tekhelet = the biblical blue of sky & holiness (secondary accent)
     olive = the land, growth, the family tree (tertiary / positive) */
  --c-gold-100: #f7ecc9;
  --c-gold-200: #eed79a;
  --c-gold-300: #e2c273;
  --c-gold-400: #d4a94f;   /* base gold */
  --c-gold-500: #b98a34;
  --c-gold-600: #8f6825;
  --c-gold-glow: rgba(212, 169, 79, .34);

  --c-tekhelet-100: #cfe1f4;
  --c-tekhelet-200: #9fc3e8;
  --c-tekhelet-300: #6ba0d6;
  --c-tekhelet-400: #4b83c4;
  --c-tekhelet-500: #35659e;
  --c-tekhelet-600: #244a76;

  --c-olive-200: #cfe0b0;
  --c-olive-400: #8fb063;
  --c-olive-500: #6f8c4a;

  --c-rose-400: #e08585;
  --c-amber-400: #e0a34a;

  /* ---- Dark theme (default): night over deep indigo-ink ------------------- */
  --bg-void:    #0b0912;   /* deepest — the night behind everything */
  --bg-base:    #131120;   /* page background */
  --bg-surface: #1c1a2b;   /* cards, panels */
  --bg-raised:  #262336;   /* raised / hover / popovers */
  --bg-inset:   #100e1b;   /* wells: inputs, code, scroll tracks */

  --line:        rgba(238, 224, 178, .12);
  --line-strong: rgba(238, 224, 178, .24);
  --line-accent: rgba(212, 169, 79, .45);

  --ink:       #f3ecdd;    /* primary text (parchment) — AAA on bg-base */
  --ink-soft:  #cdc6b4;    /* secondary text — AA on bg-base */
  --ink-dim:   #968f7d;    /* tertiary / captions — AA(large) */
  --ink-faint: #6a6456;    /* disabled / hairline labels */

  --accent:        var(--c-gold-400);
  --accent-text:   var(--c-gold-200);  /* gold used AS text on dark: passes AA */
  --accent-2:      var(--c-tekhelet-400);
  --accent-2-text: var(--c-tekhelet-200);
  --on-accent:     #17130a;  /* text on a gold fill — AA */
  --on-accent-2:   #0a1420;  /* text on a tekhelet fill */

  --ok:    var(--c-olive-400);
  --ok-text: var(--c-olive-200);
  --warn:  var(--c-amber-400);
  --alert: var(--c-rose-400);

  --selection: rgba(212, 169, 79, .32);
  --focus-ring: 0 0 0 2px var(--bg-base), 0 0 0 4px var(--c-gold-300);

  /* ---- Typography ---------------------------------------------------------- */
  --font-display: 'Frank Ruhl Libre', 'Noto Serif Hebrew', 'David Libre', serif;
  --font-body:    'Assistant', 'Rubik', system-ui, 'Segoe UI', sans-serif;
  --font-torah:   'Noto Serif Hebrew', 'Frank Ruhl Libre', serif; /* pointed text */
  --font-num:     'Assistant', ui-monospace, system-ui, sans-serif; /* tabular times */

  /* fluid scale — Hebrew is set with generous line-height for legibility */
  --fs-display: clamp(2.4rem, 1.6rem + 3.2vw, 3.6rem);
  --lh-display: 1.08;
  --fs-h1: clamp(1.85rem, 1.4rem + 1.9vw, 2.6rem);
  --lh-h1: 1.18;
  --fs-h2: clamp(1.35rem, 1.15rem + .9vw, 1.75rem);
  --lh-h2: 1.3;
  --fs-h3: 1.18rem;  --lh-h3: 1.4;
  --fs-lead: 1.14rem; --lh-lead: 1.75;
  --fs-body: 1rem;    --lh-body: 1.75;
  --fs-sm: .875rem;   --lh-sm: 1.65;
  --fs-caption: .78rem; --lh-caption: 1.5;

  --fw-light: 300; --fw-reg: 400; --fw-med: 500; --fw-semi: 600; --fw-bold: 700; --fw-black: 900;
  --tracking-label: .06em;
  --tracking-tight: -.01em;

  /* ---- Space scale (4pt base) --------------------------------------------- */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px; --sp-5: 24px;
  --sp-6: 32px; --sp-7: 48px; --sp-8: 64px; --sp-9: 96px;

  /* ---- Radii --------------------------------------------------------------- */
  --r-xs: 6px; --r-sm: 10px; --r-md: 14px; --r-lg: 20px; --r-xl: 28px; --r-pill: 999px;

  /* ---- Elevation — soft, downward, RTL-neutral (no L/R light-source bias) -- */
  --shadow-sm: 0 1px 2px rgba(0,0,0,.35);
  --shadow-md: 0 8px 24px -10px rgba(0,0,0,.55);
  --shadow-lg: 0 22px 50px -22px rgba(0,0,0,.72);
  --shadow-ring-gold: 0 0 0 1px var(--line-accent), 0 10px 34px -14px var(--c-gold-glow);
  --glow-moon: 0 0 40px -6px var(--c-gold-glow);

  /* ---- Motion — gentle, moonrise-like; never bouncy ----------------------- */
  --ease-moon:  cubic-bezier(.22, 1, .36, 1);   /* decisive ease-out */
  --ease-inout: cubic-bezier(.65, 0, .35, 1);
  --dur-1: 120ms; --dur-2: 200ms; --dur-3: 320ms; --dur-4: 520ms;

  /* ---- Layout knobs -------------------------------------------------------- */
  --container: 1120px;
  --topbar-h: 60px;
  color-scheme: dark;
  accent-color: var(--accent);
}

/* ---- Light theme: "day / parchment" ------------------------------------- */
:root[data-theme="light"] {
  --bg-void:    #ece3cf;
  --bg-base:    #f5eede;
  --bg-surface: #fffaf0;
  --bg-raised:  #fff;
  --bg-inset:   #efe6d2;

  --line:        rgba(70, 52, 20, .16);
  --line-strong: rgba(70, 52, 20, .28);
  --line-accent: rgba(150, 110, 40, .5);

  --ink:       #2b2416;
  --ink-soft:  #5b5241;
  --ink-dim:   #7c715a;
  --ink-faint: #a99c82;

  --accent:        var(--c-gold-500);
  --accent-text:   var(--c-gold-600);
  --accent-2:      var(--c-tekhelet-500);
  --accent-2-text: var(--c-tekhelet-600);
  --on-accent:     #fff8e8;
  --on-accent-2:   #eef5fc;

  --ok-text: var(--c-olive-500);
  --selection: rgba(185, 138, 52, .28);
  --focus-ring: 0 0 0 2px var(--bg-base), 0 0 0 4px var(--c-gold-500);

  --shadow-sm: 0 1px 2px rgba(70,52,20,.14);
  --shadow-md: 0 8px 22px -10px rgba(70,52,20,.24);
  --shadow-lg: 0 22px 48px -22px rgba(70,52,20,.32);
  color-scheme: light;
}

/* ============================================================================
   Base
   ============================================================================ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
::selection { background: var(--selection); }

.ds, body.ds {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-body);
  font-weight: var(--fw-reg);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  background:
    radial-gradient(1200px 620px at 82% -8%, rgba(75, 131, 196, .10), transparent 60%),
    radial-gradient(1000px 560px at 12% 108%, var(--c-gold-glow), transparent 55%),
    var(--bg-base);
  background-attachment: fixed;
}

/* ---- Typography utilities ------------------------------------------------ */
.t-display { font-family: var(--font-display); font-size: var(--fs-display); line-height: var(--lh-display); font-weight: var(--fw-black); letter-spacing: var(--tracking-tight); }
.t-h1 { font-family: var(--font-display); font-size: var(--fs-h1); line-height: var(--lh-h1); font-weight: var(--fw-bold); }
.t-h2 { font-family: var(--font-display); font-size: var(--fs-h2); line-height: var(--lh-h2); font-weight: var(--fw-bold); }
.t-h3 { font-family: var(--font-display); font-size: var(--fs-h3); line-height: var(--lh-h3); font-weight: var(--fw-semi); }
.t-lead { font-size: var(--fs-lead); line-height: var(--lh-lead); color: var(--ink-soft); }
.t-body { font-size: var(--fs-body); line-height: var(--lh-body); }
.t-sm { font-size: var(--fs-sm); line-height: var(--lh-sm); }
.t-caption { font-size: var(--fs-caption); line-height: var(--lh-caption); color: var(--ink-dim); }
.t-label { font-size: var(--fs-caption); font-weight: var(--fw-bold); letter-spacing: var(--tracking-label); color: var(--accent-text); text-transform: none; }
.t-num { font-family: var(--font-num); font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

/* gilded display text — used sparingly for hero titles */
.t-gild {
  background: linear-gradient(158deg, var(--c-gold-100) 8%, var(--c-gold-300) 48%, var(--c-gold-500) 92%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

a { color: var(--accent-text); text-underline-offset: .18em; text-decoration-color: var(--line-accent); transition: color var(--dur-1) var(--ease-inout); }
a:hover { color: var(--c-gold-100); }

/* ============================================================================
   Components (RTL-native — logical properties throughout)
   ============================================================================ */

/* ---- Buttons ------------------------------------------------------------- */
.btn {
  --btn-bg: rgba(255,255,255,.04);
  --btn-fg: var(--ink);
  --btn-bd: var(--line-strong);
  display: inline-flex; align-items: center; gap: var(--sp-2);
  font-family: var(--font-body); font-size: var(--fs-sm); font-weight: var(--fw-semi);
  line-height: 1; white-space: nowrap; cursor: pointer; user-select: none;
  padding-block: 10px; padding-inline: 18px;
  min-height: 40px; /* touch target */
  color: var(--btn-fg); background: var(--btn-bg);
  border: 1px solid var(--btn-bd); border-radius: var(--r-pill);
  transition: transform var(--dur-2) var(--ease-moon),
              border-color var(--dur-2) var(--ease-inout),
              background var(--dur-2) var(--ease-inout),
              box-shadow var(--dur-2) var(--ease-inout);
}
.btn:hover { border-color: var(--line-accent); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.985); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn .i { font-size: 1.1em; line-height: 1; }

.btn--primary {
  --btn-fg: var(--on-accent); --btn-bd: transparent;
  background: linear-gradient(135deg, var(--c-gold-300), var(--c-gold-500));
  box-shadow: var(--shadow-ring-gold);
}
.btn--primary:hover { border-color: transparent; box-shadow: var(--shadow-ring-gold), var(--glow-moon); }

.btn--tekhelet {
  --btn-fg: var(--on-accent-2); --btn-bd: transparent;
  background: linear-gradient(135deg, var(--c-tekhelet-300), var(--c-tekhelet-500));
}
.btn--ghost { --btn-bg: transparent; }
.btn--sm { min-height: 32px; padding-block: 6px; padding-inline: 12px; font-size: var(--fs-caption); }
.btn[disabled] { opacity: .45; pointer-events: none; }

/* ---- Card ---------------------------------------------------------------- */
.card {
  background: linear-gradient(180deg, var(--bg-raised), var(--bg-surface));
  border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--sp-5); box-shadow: var(--shadow-md);
}
.card--interactive {
  cursor: pointer; position: relative; overflow: hidden;
  transition: transform var(--dur-3) var(--ease-moon),
              border-color var(--dur-2) var(--ease-inout),
              box-shadow var(--dur-3) var(--ease-inout);
}
.card--interactive::after {  /* a soft moonlight wash on hover */
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(460px 150px at 50% 0%, var(--c-gold-glow), transparent 70%);
  transition: opacity var(--dur-3) var(--ease-inout);
}
.card--interactive:hover { transform: translateY(-4px); border-color: var(--line-accent); box-shadow: var(--shadow-lg); }
.card--interactive:hover::after { opacity: 1; }
.card--interactive:focus-visible { outline: none; box-shadow: var(--focus-ring), var(--shadow-lg); }

/* ---- Chip / Tag / Badge -------------------------------------------------- */
.chip {
  display: inline-flex; align-items: center; gap: var(--sp-1);
  font-size: var(--fs-caption); font-weight: var(--fw-med); color: var(--ink-soft);
  background: rgba(255,255,255,.04); border: 1px solid var(--line);
  border-radius: var(--r-pill); padding-block: 5px; padding-inline: 11px;
  transition: border-color var(--dur-2) var(--ease-inout), color var(--dur-2) var(--ease-inout);
}
a.chip:hover, button.chip:hover { border-color: var(--line-accent); color: var(--ink); }
.chip--gold { color: var(--accent-text); border-color: var(--line-accent); background: rgba(212,169,79,.08); }
.badge {
  display: inline-flex; align-items: center; font-size: var(--fs-caption); font-weight: var(--fw-semi);
  border-radius: var(--r-pill); padding-block: 3px; padding-inline: 9px; border: 1px solid;
}
.badge--ok { color: var(--ok-text); border-color: rgba(143,176,99,.4); background: rgba(143,176,99,.12); }
.badge--warn { color: var(--warn); border-color: rgba(224,163,74,.45); background: rgba(224,163,74,.12); }
.badge--alert { color: var(--alert); border-color: rgba(224,133,133,.42); background: rgba(224,133,133,.12); }
.badge--muted { color: var(--ink-dim); border-color: var(--line); background: rgba(255,255,255,.03); }

/* ---- Form fields --------------------------------------------------------- */
.field {
  width: 100%; color: var(--ink); font-family: inherit; font-size: var(--fs-sm);
  background: var(--bg-inset); border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  padding-block: 10px; padding-inline: 14px; min-height: 42px;
  transition: border-color var(--dur-2) var(--ease-inout), box-shadow var(--dur-2) var(--ease-inout);
}
.field::placeholder { color: var(--ink-dim); }
.field:hover { border-color: var(--line-accent); }
.field:focus, .field:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--c-gold-glow); }
.field--pill { border-radius: var(--r-pill); }

/* ---- Segmented control (chips as radio-ish) ------------------------------ */
.seg { display: inline-flex; gap: var(--sp-1); flex-wrap: wrap; }
.seg > button {
  font-family: inherit; font-size: var(--fs-caption); font-weight: var(--fw-med);
  color: var(--ink-soft); background: rgba(255,255,255,.04);
  border: 1px solid var(--line); border-radius: var(--r-pill);
  padding-block: 7px; padding-inline: 13px; min-height: 34px; cursor: pointer;
  transition: all var(--dur-2) var(--ease-inout);
}
.seg > button:hover { border-color: var(--line-accent); color: var(--ink); }
.seg > button:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.seg > button[aria-pressed="true"], .seg > button.is-on {
  color: var(--on-accent); font-weight: var(--fw-bold); border-color: transparent;
  background: linear-gradient(135deg, var(--c-gold-300), var(--c-gold-500));
}

/* ---- Top bar ------------------------------------------------------------- */
.ds-topbar {
  display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap;
  min-height: var(--topbar-h); padding-block: 10px; padding-inline: var(--sp-4);
  background: color-mix(in srgb, var(--bg-surface) 82%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 50;
}

/* ============================================================================
   Motifs — the cyclical-time visual language (pure CSS, decorative)
   ============================================================================ */

/* a small waxing moon — candlelight crescent */
.moon {
  --moon-size: 44px;
  width: var(--moon-size); height: var(--moon-size); border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, var(--c-gold-100), var(--c-gold-400) 62%, var(--c-gold-600));
  box-shadow: inset -6px -4px 12px rgba(0,0,0,.35), var(--glow-moon);
  position: relative; flex: none;
}
.moon::after { /* the shadow that carves the crescent — mirrored for RTL by inset-inline */
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: var(--bg-base);
  transform: translateX(28%) scale(.92);
}

/* concentric rings — the annual cycle / generations */
.rings {
  --ring: var(--line-accent);
  width: 120px; height: 120px; border-radius: 50%; position: relative; flex: none;
  border: 1px solid var(--ring);
}
.rings::before, .rings::after {
  content: ""; position: absolute; border-radius: 50%; border: 1px solid var(--ring);
}
.rings::before { inset: 16px; opacity: .7; }
.rings::after { inset: 34px; opacity: .45; }

/* a thin gilded divider with a centered star node */
.rule-star { display: flex; align-items: center; gap: var(--sp-3); color: var(--line-strong); }
.rule-star::before, .rule-star::after {
  content: ""; height: 1px; flex: 1;
  background: linear-gradient(var(--_d, 90deg), transparent, var(--line-accent), transparent);
}
.rule-star .node { color: var(--accent); font-size: 1.1em; }

/* ---- Motion & a11y guards ------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
:where(a, button, input, select, textarea, [tabindex]):focus-visible { outline: none; box-shadow: var(--focus-ring); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
