/* ═══════════════════════════════════════════════════════════════════════
   INELT · Design System v2 — "Quiet Academic"
   Shared design tokens + base + primitives for every page.
   Loaded BEFORE each page's own <style> block, so pages can refine
   anything here without fighting specificity.

   VISUAL LAYER ONLY. No JavaScript, data flow, or markup contract
   depends on this file — it restyles class names that already exist.
   ═══════════════════════════════════════════════════════════════════════ */

/* ───────────────────────────────────────────────────────────────────────
   1. TOKENS — LIGHT (default)
   ─────────────────────────────────────────────────────────────────────── */
:root {
  /* ── Primary · sampled from the mockup ──
     500 #488A70 is the mockup's brand green; 600 #377863 is its CTA fill
     (white on #488A70 alone is 4.1:1, so buttons use 600). ── */
  --green-50:  #EFF5EE;
  --green-100: #E2EEE8;
  --green-200: #C3DFD1;
  --green-300: #80BC9A;
  --green-400: #5FA285;
  --green-500: #488A70;
  --green-600: #377863;
  --green-700: #2C6350;
  --green-800: #234E40;
  --green-900: #17362C;

  /* ── Neutrals · warm cream, matching the mockup's #FDF9F2 canvas ── */
  --n-0:   #FFFFFF;
  --n-25:  #FEFCF7;
  --n-50:  #FDF9F2;
  --n-100: #F5F0E5;
  --n-200: #E6E0D2;
  --n-300: #C3BCAC;
  --n-400: #9A9488;
  --n-500: #6E6A60;
  --n-600: #52504A;
  --n-700: #3C3B36;
  --n-800: #262A26;
  --n-900: #1E2A24;
  --n-950: #121A16;

  /* ── Pastel category tints, sampled from the mockup's cards ── */
  --tint-green:  #EFF5EE;
  --tint-purple: #F2EEF7;
  --tint-blue:   #ECF4FB;
  --tint-amber:  #FEF5E3;
  --tint-cool:   #F1F5F9;

  /* ── Roles ── */
  --primary:         var(--green-500);
  --primary-strong:  var(--green-600);
  --primary-deep:    var(--green-700);
  --primary-soft:    var(--green-50);
  --primary-dim:     rgba(72,138,112,.10);
  --primary-border:  rgba(72,138,112,.26);
  --primary-glow:    rgba(72,138,112,.22);
  --on-primary:      #FFFFFF;

  --secondary:       #1B5E9E;
  --secondary-dim:   rgba(27,94,158,.08);
  --secondary-border:rgba(27,94,158,.20);

  --accent:          #8F5F11;   /* gold — premium only, kept scarce (AA as text) */
  --accent-bright:   #C9922E;   /* decorative fills/icons only, never small text */
  --accent-dim:      rgba(180,121,28,.10);
  --accent-border:   rgba(180,121,28,.26);

  /* ── Semantic ── */
  --success:         #136A49;
  --success-dim:     rgba(19,106,73,.09);
  --success-border:  rgba(19,106,73,.24);
  --danger:          #B02F46;
  --danger-dim:      rgba(176,47,70,.08);
  --danger-border:   rgba(176,47,70,.22);
  --warn:            #8F5F11;
  --warn-bright:     #C9922E;
  --warn-dim:        rgba(180,121,28,.10);
  --warn-border:     rgba(180,121,28,.26);
  --info:            #2B6CB0;
  --info-dim:        rgba(43,108,176,.08);
  --info-border:     rgba(43,108,176,.22);

  /* ── Surfaces ── */
  --surface-base:    var(--n-50);
  --surface-raised:  var(--n-0);
  --surface-overlay: var(--n-25);
  --surface-high:    var(--n-100);
  --surface-sunken:  var(--n-100);
  --surface-glass:   rgba(253,249,242,.86);

  /* ── Text ── */
  --text-primary:   var(--n-900);
  --text-secondary: var(--n-600);  /* 7.4:1 on paper */
  --text-muted:     #6B6459;       /* AA at 12px on the cream canvas */
  --text-inverse:   #FFFFFF;
  --text-link:      var(--green-600);

  /* ── Lines ── */
  --border:        rgba(60,52,38,.10);
  --border-strong: rgba(60,52,38,.17);
  --focus-ring:    var(--green-500);

  /* ── Section hues (mirrors the 4 exam sections) ── */
  --sec-reading:      #5134B0;   /* mockup "Reading"   — purple */
  --sec-grammar:      #1B5E9E;   /* mockup "Grammar"   — blue   */
  --sec-functions:    #8F5F11;   /* mockup "Writing"   — amber  */
  --sec-conversation: #276F52;   /* mockup "Listening" — green  */

  /* ── Spacing scale (4px base) ── */
  --sp-1: 2px;   --sp-2: 4px;   --sp-3: 8px;   --sp-4: 12px;
  --sp-5: 16px;  --sp-6: 20px;  --sp-7: 24px;  --sp-8: 32px;
  --sp-9: 40px;  --sp-10: 48px; --sp-11: 64px; --sp-12: 80px;

  /* ── Radius ── */
  --r-xs: 8px;  --r-sm: 12px; --r-md: 16px;
  --r-lg: 22px; --r-xl: 26px; --r-2xl: 34px; --r-pill: 999px;

  /* ── Elevation ── */
  --shadow-xs: 0 1px 2px rgba(60,52,38,.04);
  --shadow-sm: 0 2px 6px rgba(60,52,38,.05), 0 1px 2px rgba(60,52,38,.03);
  --shadow-md: 0 8px 20px rgba(60,52,38,.06), 0 2px 6px rgba(60,52,38,.03);
  --shadow-lg: 0 18px 40px rgba(60,52,38,.08), 0 5px 14px rgba(60,52,38,.04);
  --shadow-xl: 0 30px 70px rgba(60,52,38,.10), 0 10px 24px rgba(60,52,38,.05);

  /* ── Motion ── */
  --ease:          cubic-bezier(.2,.8,.2,1);
  --ease-entrance: cubic-bezier(0,.55,.45,1);
  --ease-spring:   cubic-bezier(.34,1.3,.64,1);
  --dur-1: 120ms;  --dur-2: 180ms;  --dur-3: 260ms;  --dur-4: 380ms;

  /* ── Type ── */
  --font-ar: 'IBM Plex Sans Arabic', system-ui, -apple-system, sans-serif;
  --font-en: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
  /* Question/option text is English on an Arabic page, but may contain
     Arabic. Latin glyphs take Inter, Arabic glyphs fall back to Plex. */
  --font-mixed: 'Inter', 'IBM Plex Sans Arabic', system-ui, sans-serif;

  --fs-2xs: .75rem;   /* 12 */
  --fs-xs:  .8125rem; /* 13 */
  --fs-sm:  .875rem;  /* 14 */
  --fs-md:  1rem;     /* 16 */
  --fs-lg:  1.125rem; /* 18 */
  --fs-xl:  1.25rem;  /* 20 */
  --fs-2xl: 1.5rem;   /* 24 */
  --fs-3xl: 1.875rem; /* 30 */
  --fs-4xl: 2.25rem;  /* 36 */
  --fs-5xl: 3rem;     /* 48 */
}

/* ───────────────────────────────────────────────────────────────────────
   2. TOKENS — DARK
   Surfaces get their own ramp rather than an inversion; elevation comes
   from hairlines + a faint accent glow, never black-on-black shadow.
   ─────────────────────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --primary:        #4DBE95;
  --primary-strong: #3EA57F;
  --primary-deep:   #2E8B69;
  --primary-soft:   rgba(77,190,149,.10);
  --primary-dim:    rgba(77,190,149,.13);
  --primary-border: rgba(77,190,149,.30);
  --primary-glow:   rgba(77,190,149,.22);
  --on-primary:     #06211A;

  --secondary:       #7FB3DE;
  --secondary-dim:   rgba(127,179,222,.12);
  --secondary-border:rgba(127,179,222,.28);

  --accent:         #E0AC5A;
  --accent-bright:  #E8BC74;
  --accent-dim:     rgba(224,172,90,.12);
  --accent-border:  rgba(224,172,90,.28);

  --success:        #45C48F;
  --success-dim:    rgba(69,196,143,.12);
  --success-border: rgba(69,196,143,.28);
  --danger:         #E88296;
  --danger-dim:     rgba(232,130,150,.12);
  --danger-border:  rgba(232,130,150,.26);
  --warn:           #E0AC5A;
  --warn-bright:    #E8BC74;
  --warn-dim:       rgba(224,172,90,.12);
  --warn-border:    rgba(224,172,90,.28);
  --info:           #7FB3DE;
  --info-dim:       rgba(127,179,222,.12);
  --info-border:    rgba(127,179,222,.28);

  --surface-base:    #0D1310;
  --surface-raised:  #141C18;
  --surface-overlay: #1A2420;
  --surface-high:    #222E28;
  --surface-sunken:  #0A100D;
  --surface-glass:   rgba(20,28,24,.82);

  --text-primary:   #E8EFEA;
  --text-secondary: #9AAAA0;
  --text-muted:     #8A9A90;   /* 6.4:1 on --surface-base, 4.8:1 on --surface-high */
  --text-inverse:   #0D1310;
  --text-link:      #6FD1AB;

  --border:        rgba(255,255,255,.09);
  --border-strong: rgba(255,255,255,.16);
  --focus-ring:    #4DBE95;

  --sec-reading:      #B9A6F0;   /* purple */
  --sec-grammar:      #8FC0E8;   /* blue   */
  --sec-functions:    #E5B76A;   /* amber  */
  --sec-conversation: #6FCBA3;   /* green  */

  /* Dark counterparts of the pastel category tints. */
  --tint-green:  #1A2B22;
  --tint-purple: #241F33;
  --tint-blue:   #172533;
  --tint-amber:  #2E2517;
  --tint-cool:   #1E262B;

  --shadow-xs: 0 1px 2px rgba(0,0,0,.34);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.40), 0 1px 2px rgba(0,0,0,.26);
  --shadow-md: 0 6px 18px rgba(0,0,0,.44), 0 2px 6px rgba(0,0,0,.28);
  --shadow-lg: 0 16px 40px rgba(0,0,0,.50), 0 4px 12px rgba(0,0,0,.32);
  --shadow-xl: 0 28px 70px rgba(0,0,0,.56), 0 8px 22px rgba(0,0,0,.36);
}

/* ───────────────────────────────────────────────────────────────────────
   3. RESET & BASE
   ─────────────────────────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

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

body {
  font-family: var(--font-ar);
  font-size: var(--fs-md);
  line-height: 1.75;            /* Arabic needs the extra leading */
  color: var(--text-primary);
  background: var(--surface-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Arabic is never letter-spaced. */
:root, body, h1, h2, h3, h4, h5, h6, p, li, button, input, textarea, select {
  letter-spacing: 0;
}

h1, h2, h3, h4, h5, h6 {
  line-height: 1.25;
  font-weight: 700;
  color: var(--text-primary);
}

a { color: var(--text-link); text-decoration: none; }
a:hover { text-decoration: underline; }

img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }

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

/* Keyboard-first focus ring on every interactive element. */
:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}
:focus:not(:focus-visible) { outline: none; }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--r-pill);
  border: 2px solid var(--surface-base);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ───────────────────────────────────────────────────────────────────────
   4. TYPE + LAYOUT UTILITIES
   .en / .mono / .hidden are referenced by existing JS-generated markup —
   their names and behaviour are unchanged.
   ─────────────────────────────────────────────────────────────────────── */
.en {
  font-family: var(--font-en);
  direction: ltr;
  unicode-bidi: isolate;
}
.mono {
  font-family: var(--font-mono);
  direction: ltr;
  unicode-bidi: isolate;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ───────────────────────────────────────────────────────────────────────
   5. PRIMITIVES
   ─────────────────────────────────────────────────────────────────────── */

/* ── Card ── */
.card {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-sm);
}

/* ── Button ──
   .btn must keep position:relative + overflow:hidden: the existing
   global click handler appends a .ripple span inside it. */
.btn {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: 13px 24px;
  border-radius: var(--r-pill);
  border: 1px solid transparent;
  font-family: var(--font-ar);
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition:
    background-color var(--dur-2) var(--ease),
    border-color var(--dur-2) var(--ease),
    color var(--dur-2) var(--ease),
    box-shadow var(--dur-2) var(--ease),
    transform var(--dur-1) var(--ease);
}
.btn svg { flex-shrink: 0; }
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0) scale(.985); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn-lg { padding: 16px 30px; font-size: var(--fs-md); border-radius: var(--r-pill); }
.btn-sm { padding: 9px 16px; font-size: var(--fs-xs); border-radius: var(--r-pill); }
.btn-block { width: 100%; }

.btn-primary {
  background: var(--primary-strong);
  color: var(--on-primary);
  box-shadow: var(--shadow-xs);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-deep);
  box-shadow: 0 6px 18px var(--primary-glow);
}

.btn-ghost {
  background: var(--surface-raised);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-high);
  border-color: var(--primary-border);
  color: var(--primary-strong);
}

.btn-success {
  background: var(--success);
  color: var(--on-primary);
}
.btn-success:hover:not(:disabled) { filter: brightness(.93); box-shadow: 0 6px 18px var(--success-dim); }

.btn-danger {
  background: var(--surface-raised);
  color: var(--danger);
  border-color: var(--danger-border);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger);
  color: #fff;
  border-color: transparent;
}

/* Ripple injected by the existing click handler. */
.ripple {
  position: absolute;
  border-radius: 50%;
  background: currentColor;
  opacity: .18;
  transform: scale(0);
  animation: ripple-out 560ms var(--ease);
  pointer-events: none;
}
@keyframes ripple-out { to { transform: scale(2.2); opacity: 0; } }

/* ── Icon button ── */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text-secondary);
  transition: background-color var(--dur-2) var(--ease),
              color var(--dur-2) var(--ease),
              border-color var(--dur-2) var(--ease),
              transform var(--dur-1) var(--ease);
}
.icon-btn:hover {
  background: var(--surface-high);
  color: var(--primary-strong);
  border-color: var(--primary-border);
  transform: translateY(-1px);
}
.icon-btn:active { transform: scale(.94); }

/* ── Badge / chip ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: var(--r-pill);
  font-size: var(--fs-2xs);
  font-weight: 600;
  line-height: 1.4;
  border: 1px solid transparent;
}
.badge-accent  { background: var(--primary-dim);  color: var(--primary-deep); border-color: var(--primary-border); }
.badge-success { background: var(--success-dim);  color: var(--success);        border-color: var(--success-border); }
.badge-danger  { background: var(--danger-dim);   color: var(--danger);         border-color: var(--danger-border); }
.badge-warn    { background: var(--warn-dim);     color: var(--warn);           border-color: var(--warn-border); }
.badge-muted   { background: var(--surface-high); color: var(--text-secondary); border-color: var(--border); }
.badge-gold    { background: var(--accent-dim);   color: var(--accent);         border-color: var(--accent-border); }

/* ── Form controls ── */
.text-input {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--r-md);
  border: 1px solid var(--border-strong);
  background: var(--surface-raised);
  color: var(--text-primary);
  font-size: var(--fs-sm);
  transition: border-color var(--dur-2) var(--ease),
              box-shadow var(--dur-2) var(--ease),
              background-color var(--dur-2) var(--ease);
}
.text-input::placeholder { color: var(--text-muted); }
.text-input:hover { border-color: var(--n-300); }
.text-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-dim);
}

/* ── Section label ── */
.section-label {
  font-size: var(--fs-2xs);
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: .04em;
  text-transform: uppercase;
  margin-bottom: var(--sp-4);
}

/* ── Skeleton loaders (replace blank loading states) ── */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--surface-high);
  border-radius: var(--r-sm);
  color: transparent !important;
  user-select: none;
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255,255,255,.45) 50%,
    transparent 100%
  );
  animation: skeleton-sweep 1.3s infinite;
}
[data-theme="dark"] .skeleton::after {
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,.07) 50%, transparent 100%);
}
@keyframes skeleton-sweep { to { transform: translateX(100%); } }

.skeleton-line { height: 12px; margin-bottom: 8px; border-radius: var(--r-pill); }
.skeleton-line:last-child { width: 62%; margin-bottom: 0; }

/* ── Spinner ── */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────────────────────────────────────────────────────────────────────
   6. ENTRANCE ANIMATIONS
   Subtle, fast (150–400ms), and never re-triggered mid-exam.
   ─────────────────────────────────────────────────────────────────────── */
@keyframes fade-in      { from { opacity: 0 } to { opacity: 1 } }
@keyframes rise-in      { from { opacity: 0; transform: translateY(12px) } to { opacity: 1; transform: none } }
@keyframes rise-in-lg   { from { opacity: 0; transform: translateY(22px) } to { opacity: 1; transform: none } }
@keyframes scale-in     { from { opacity: 0; transform: scale(.96) } to { opacity: 1; transform: none } }
@keyframes slide-in-rtl { from { opacity: 0; transform: translateX(-16px) } to { opacity: 1; transform: none } }
@keyframes slide-in-ltr { from { opacity: 0; transform: translateX(16px) } to { opacity: 1; transform: none } }

.anim-fade  { animation: fade-in    var(--dur-3) var(--ease-entrance) both; }
.anim-rise  { animation: rise-in    var(--dur-4) var(--ease-entrance) both; }
.anim-scale { animation: scale-in   var(--dur-3) var(--ease-entrance) both; }

/* Staggered children — capped at 8 so long lists stay snappy. */
.stagger > *          { animation: rise-in var(--dur-3) var(--ease-entrance) both; }
.stagger > *:nth-child(1) { animation-delay: 30ms }
.stagger > *:nth-child(2) { animation-delay: 60ms }
.stagger > *:nth-child(3) { animation-delay: 90ms }
.stagger > *:nth-child(4) { animation-delay: 120ms }
.stagger > *:nth-child(5) { animation-delay: 150ms }
.stagger > *:nth-child(6) { animation-delay: 180ms }
.stagger > *:nth-child(7) { animation-delay: 210ms }
.stagger > *:nth-child(n+8) { animation-delay: 240ms }

/* ───────────────────────────────────────────────────────────────────────
   7. REDUCED MOTION — global kill-switch
   ─────────────────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
  .btn:hover:not(:disabled),
  .icon-btn:hover { transform: none; }
}

/* ───────────────────────────────────────────────────────────────────────
   8. PRINT
   ─────────────────────────────────────────────────────────────────────── */
@media print {
  body { background: #fff; color: #000; }
  .btn, .icon-btn, .floating-controls { display: none !important; }
}
