/*
 * آيات — design tokens, three layers: primitive → semantic → component.
 * Direction: smoked glass over a drawn night scene (dark) and warm daylight glass (light).
 * One primary (emerald) and one accent (gold, for ayah marks and ornament only).
 * Components read semantic or component tokens only, never a raw value.
 */

/* === PRIMITIVES ============================================================ */
:root {
  --ivory-50: #fdf9ee;
  --ivory-100: #f6efdc;
  --ivory-200: #e9dfc6;
  --ivory-300: #d6c9a6;
  --ivory-400: #8a7f63;

  --ink-900: #17211c;
  --ink-700: #33403a;
  --ink-600: #4d5a53;

  --night-950: #050d0a;
  --night-900: #08140f;
  --night-800: #0d1d17;
  --night-700: #15291f;

  --emerald-900: #083526;
  --emerald-800: #0a4633;
  --emerald-700: #0e5a43;
  --emerald-400: #4fb893;
  --emerald-300: #86d3b4;
  --emerald-200: #b4e4cf;
  --emerald-100: #dcefe5;

  --gold-700: #84560f;
  --gold-300: #e3c27a;

  --red-700: #9a2b2b;
  --red-300: #f3a59d;

  --white-rgb: 255 255 255;

  /* Space, 4px base */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4rem;

  /* Radius by role (kit ladder) */
  --radius-sm: 0.75rem;   /* dense controls */
  --radius-md: 1.125rem;  /* inputs, rows */
  --radius-lg: 1.625rem;  /* cards, dialogs */
  --radius-xl: 2.25rem;   /* slabs */
  --radius-pill: 999px;

  /* Type families */
  --font-quran: "Amiri Quran", "Amiri", "Scheherazade New", "Traditional Arabic", serif;
  --font-display: "Amiri", "Amiri Quran", "Traditional Arabic", serif;
  --font-ui: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif;

  /* Type scale (UI) */
  --text-xs: 0.8125rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-md: 1.125rem;
  --text-lg: 1.375rem;
  --text-xl: 1.75rem;
  --text-2xl: 2.25rem;
  --text-3xl: 3rem;

  /* Quran text steps, in rem so browser zoom and text scaling still apply */
  --quran-step-0: 1.375rem;
  --quran-step-1: 1.625rem;
  --quran-step-2: 1.875rem;
  --quran-step-3: 2.125rem;
  --quran-step-4: 2.5rem;
  --quran-step-5: 3rem;

  /* Motion (kit constants) */
  --duration-fast: 160ms;
  --duration-base: 240ms;
  --duration-move: 420ms;
  --duration-enter: 320ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-nav: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --stagger: 25ms;

  /* Layout */
  --measure-reading: 46rem;
  --measure-page: 72rem;
  --tap: 2.75rem; /* 44px touch target */

  /* Glass blur by role */
  --blur-chrome: blur(30px) saturate(1.55);
  --blur-panel: blur(40px) saturate(1.5);
  --blur-card: blur(24px) saturate(1.45);
  --blur-bead: blur(4px) saturate(1.9) brightness(1.08);
}

/* === SEMANTIC: light (daylight glass) ====================================== */
:root,
html[data-theme="light"] {
  color-scheme: light;
  --color-bg: #e7dcc3;
  --color-text: var(--ink-900);
  --color-text-muted: var(--ink-600);
  --color-accent: var(--emerald-700);
  --color-accent-hover: var(--emerald-800);
  --color-accent-active: var(--emerald-900);
  --color-on-accent: #fffdf6;
  --color-accent-soft: rgb(14 90 67 / 0.13);
  --color-on-accent-soft: var(--emerald-900);
  --color-gold: var(--gold-700);
  --color-danger: var(--red-700);
  --color-ring: var(--emerald-700);
  --color-selection: rgb(14 90 67 / 0.22);
  --color-backdrop: rgb(40 32 18 / 0.38);
  --tour-dim: rgb(40 32 18 / 0.62);
  --tour-halo: rgb(132 86 15 / 0.22);

  /* Surfaces. `surface` is the hover / inset fill, `border` the hairline. */
  --color-surface: rgb(23 33 28 / 0.055);
  --color-surface-2: rgb(23 33 28 / 0.1);
  --color-surface-raised: #fffaf0;
  --color-border: rgb(23 33 28 / 0.12);
  --color-border-strong: rgb(23 33 28 / 0.42);

  /* Glass */
  --glass: rgb(255 251 240 / 0.64);
  --glass-strong: rgb(255 251 241 / 0.88);
  --glass-sheet: rgb(255 250 239 / 0.9);
  --glass-edge: rgb(var(--white-rgb) / 0.75);
  --glass-lip: rgb(var(--white-rgb) / 0.85);
  --glass-sheen: rgb(var(--white-rgb) / 0.5);
  --glass-shadow: 0 30px 70px -34px rgb(70 50 20 / 0.55), 0 2px 8px -4px rgb(70 50 20 / 0.2);
  --bead: linear-gradient(180deg, rgb(var(--white-rgb) / 0.95), rgb(var(--white-rgb) / 0.7));
  --bead-shadow: inset 0 1px 0 rgb(var(--white-rgb) / 1), 0 8px 18px -10px rgb(70 50 20 / 0.6);

  /* Backdrop scene */
  --scene-base: linear-gradient(165deg, #f1e8d2 0%, #e4d6b6 55%, #d9c9a4 100%);
  --scene-orb-1: rgb(255 244 214 / 0.95);
  --scene-orb-2: rgb(96 170 140 / 0.42);
  --scene-orb-3: rgb(214 160 84 / 0.4);
  --scene-lattice: rgb(14 90 67 / 0.08);
  --scene-veil: linear-gradient(180deg, rgb(255 250 235 / 0.1), rgb(120 96 50 / 0.12));
}

/* === SEMANTIC: dark (smoked glass, emerald night) ========================== */
html[data-theme="dark"] {
  color-scheme: dark;
  --color-bg: var(--night-950);
  --color-text: #f3ecd9;
  --color-text-muted: rgb(243 236 217 / 0.7);
  --color-accent: var(--emerald-300);
  --color-accent-hover: var(--emerald-200);
  --color-accent-active: #cdeede;
  --color-on-accent: #06211a;
  --color-accent-soft: rgb(134 211 180 / 0.16);
  --color-on-accent-soft: #e6f6ee;
  --color-gold: var(--gold-300);
  --color-danger: var(--red-300);
  --color-ring: var(--emerald-300);
  --color-selection: rgb(134 211 180 / 0.3);
  --color-backdrop: rgb(2 6 5 / 0.6);
  --tour-dim: rgb(2 6 5 / 0.74);
  --tour-halo: rgb(227 194 122 / 0.22);

  --color-surface: rgb(var(--white-rgb) / 0.06);
  --color-surface-2: rgb(var(--white-rgb) / 0.11);
  --color-surface-raised: #0f2019;
  --color-border: rgb(var(--white-rgb) / 0.11);
  --color-border-strong: rgb(var(--white-rgb) / 0.4);

  --glass: rgb(10 23 18 / 0.64);
  --glass-strong: rgb(7 18 14 / 0.8);
  --glass-sheet: rgb(10 23 18 / 0.86);
  --glass-edge: rgb(var(--white-rgb) / 0.14);
  --glass-lip: rgb(var(--white-rgb) / 0.26);
  --glass-sheen: rgb(var(--white-rgb) / 0.1);
  --glass-shadow: 0 34px 80px -36px rgb(0 0 0 / 0.9), 0 2px 10px -4px rgb(0 0 0 / 0.5);
  --bead: linear-gradient(180deg, rgb(var(--white-rgb) / 0.22), rgb(var(--white-rgb) / 0.07) 55%, rgb(var(--white-rgb) / 0.12));
  --bead-shadow: inset 0 1px 1px rgb(var(--white-rgb) / 0.6), inset 0 -1px 1px rgb(var(--white-rgb) / 0.2), 0 10px 24px -10px rgb(0 0 0 / 0.6);

  --scene-base: linear-gradient(165deg, #06150f 0%, #04100c 50%, #020806 100%);
  --scene-orb-1: rgb(34 150 112 / 0.6);
  --scene-orb-2: rgb(226 168 84 / 0.4);
  --scene-orb-3: rgb(20 96 110 / 0.5);
  --scene-lattice: rgb(227 194 122 / 0.13);
  --scene-veil: linear-gradient(180deg, rgb(0 0 0 / 0.05), rgb(0 0 0 / 0.35));
}

/* === COMPONENT ============================================================= */
:root {
  --page-gutter: var(--space-4);

  --button-height: var(--tap);
  --button-radius: var(--radius-pill);
  --button-bg: var(--color-accent);
  --button-bg-hover: var(--color-accent-hover);
  --button-bg-active: var(--color-accent-active);
  --button-fg: var(--color-on-accent);

  --input-height: 3rem;
  --input-bg: var(--color-surface);
  --input-border: var(--color-border-strong);
  --input-radius: var(--radius-md);

  --dialog-radius: var(--radius-lg);
  --dialog-width: 26rem;

  --topbar-height: 3.5rem;
  --topbar-gap: var(--space-3);
  --header-height: calc(var(--topbar-height) + 2 * var(--topbar-gap));
  --reader-bar-height: var(--header-height);
  --dock-height: 4rem;

  --quran-size: var(--quran-step-2);
  --quran-leading: 2.3;

  --ayah-mark-fg: var(--color-gold);
  --ayah-active-bg: var(--color-accent-soft);
}

html[data-size="0"] { --quran-size: var(--quran-step-0); }
html[data-size="1"] { --quran-size: var(--quran-step-1); }
html[data-size="2"] { --quran-size: var(--quran-step-2); }
html[data-size="3"] { --quran-size: var(--quran-step-3); }
html[data-size="4"] { --quran-size: var(--quran-step-4); }
html[data-size="5"] { --quran-size: var(--quran-step-5); }

@media (min-width: 48rem) {
  :root {
    --page-gutter: var(--space-6);
    --topbar-gap: var(--space-4);
  }
}

/* Phones and touch screens: smaller blurs cost far less to scroll, and the look holds. */
@media (max-width: 47.99rem), (pointer: coarse) {
  :root {
    --blur-chrome: blur(14px) saturate(1.4);
    --blur-panel: blur(0);
    --blur-card: blur(10px) saturate(1.3);
  }
}
