/* ==========================================================================
   مختبر الاحتمال — الأنماط
   ========================================================================== */

:root {
  color-scheme: dark;
  --f-d: "Alexandria", "Readex Pro", system-ui, sans-serif;
  --f-b: "Readex Pro", "Segoe UI", system-ui, sans-serif;
  --f-m: "IBM Plex Mono", ui-monospace, "Courier New", monospace;

  --bg:      oklch(15% 0.022 260);
  --bg-2:    oklch(18.5% 0.028 262);
  --surface: oklch(21% 0.03 262 / .72);
  --solid:   oklch(20% 0.028 262);
  --line:    oklch(62% 0.03 262 / .22);
  --line-2:  oklch(72% 0.04 262 / .34);
  --ink:     oklch(96% 0.008 262);
  --muted:   oklch(76% 0.02 262);
  --faint:   oklch(62% 0.022 262);
  --accent:  oklch(78% 0.14 235);
  --amber:   oklch(84% 0.14 72);
  --ok:      oklch(80% 0.15 152);
  --bad:     oklch(72% 0.17 22);
  --grid:    oklch(70% 0.02 262 / .16);
  --btn-ink: oklch(16% 0.03 262);
  --shadow:  0 1px 2px oklch(0% 0 0 / .35), 0 16px 40px -18px oklch(0% 0 0 / .6);
  --r: 18px;
  --ease: cubic-bezier(.22,1,.36,1);
}
:root[data-theme="light"] { color-scheme: light; }
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) { color-scheme: light; } }

:root[data-theme="light"] {
  --bg: oklch(97.6% 0.005 260); --bg-2: oklch(99.6% 0.002 260);
  --surface: oklch(100% 0 0 / .8); --solid: oklch(100% 0 0);
  --line: oklch(50% 0.02 260 / .18); --line-2: oklch(40% 0.03 260 / .3);
  --ink: oklch(22% 0.02 262); --muted: oklch(44% 0.02 262); --faint: oklch(56% 0.02 262);
  --accent: oklch(52% 0.14 250); --amber: oklch(58% 0.13 62);
  --ok: oklch(50% 0.14 152); --bad: oklch(52% 0.18 25);
  --grid: oklch(30% 0.02 262 / .14);
  --btn-ink: oklch(99% 0 0);
  --shadow: 0 1px 2px oklch(60% 0.02 260 / .16), 0 16px 40px -20px oklch(50% 0.03 260 / .32);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: oklch(97.6% 0.005 260); --bg-2: oklch(99.6% 0.002 260);
    --surface: oklch(100% 0 0 / .8); --solid: oklch(100% 0 0);
    --line: oklch(50% 0.02 260 / .18); --line-2: oklch(40% 0.03 260 / .3);
    --ink: oklch(22% 0.02 262); --muted: oklch(44% 0.02 262); --faint: oklch(56% 0.02 262);
    --accent: oklch(52% 0.14 250); --amber: oklch(58% 0.13 62);
    --ok: oklch(50% 0.14 152); --bad: oklch(52% 0.18 25);
    --grid: oklch(30% 0.02 262 / .14);
    --btn-ink: oklch(99% 0 0);
    --shadow: 0 1px 2px oklch(60% 0.02 260 / .16), 0 16px 40px -20px oklch(50% 0.03 260 / .32);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--f-b); font-weight: 300; line-height: 1.95; font-size: 1.02rem;
  overflow-x: hidden; -webkit-font-smoothing: antialiased;
}
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(60rem 40rem at 85% -10%, oklch(from var(--accent) l c h / .16), transparent 60%),
    radial-gradient(50rem 34rem at 0% 100%, oklch(from var(--amber) l c h / .10), transparent 62%),
    linear-gradient(180deg, var(--bg-2), var(--bg) 40%);
}

h1, h2, h3 { font-family: var(--f-d); font-weight: 600; line-height: 1.4; margin: 0; }
p { margin: 0 0 1.05rem; text-wrap: pretty; }
b, strong { font-weight: 600; }
em { font-style: normal; color: var(--accent); }
a { color: var(--accent); }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 8px; }

.wrap { width: min(100% - 2rem, 64rem); margin-inline: auto; }
.wrap.narrow { width: min(100% - 2rem, 44rem); }

/* شريط تقدّم القراءة */
.progress { position: fixed; inset-block-start: 0; inset-inline: 0; height: 3px; z-index: 60; background: transparent; }
.progress i { display: block; height: 100%; transform-origin: right center; transform: scaleX(0);
  background: linear-gradient(90deg, var(--amber), var(--accent)); }
@supports (animation-timeline: scroll()) {
  .progress i { animation: growx linear both; animation-timeline: scroll(root block); }
}
@keyframes growx { from { transform: scaleX(0) } to { transform: scaleX(1) } }

/* الشريط العلوي */
.topbar { position: sticky; inset-block-start: 0; z-index: 50;
  background: color-mix(in oklab, var(--bg) 80%, transparent); backdrop-filter: blur(14px) saturate(150%);
  border-block-end: 1px solid var(--line); }
.bar { display: flex; align-items: center; gap: .8rem; padding: .6rem 0; padding-top: max(.6rem, env(safe-area-inset-top)); }
.brand { display: flex; align-items: center; gap: .5rem; font-family: var(--f-d); font-weight: 600; text-decoration: none; color: var(--ink); font-size: 1rem; white-space: nowrap; }
.brand .mark { inline-size: 26px; block-size: 26px; border-radius: 8px; flex: none;
  background: conic-gradient(from 210deg, var(--accent), var(--amber), var(--accent));
  box-shadow: 0 4px 14px -6px oklch(from var(--accent) l c h / .9); }
.chips { display: flex; gap: .3rem; overflow-x: auto; flex: 1; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips a { flex: none; font-size: .78rem; text-decoration: none; color: var(--faint);
  border: 1px solid transparent; padding: .2rem .6rem; border-radius: 99px; transition: .2s var(--ease); }
.chips a:hover { color: var(--ink); border-color: var(--line); }
.chips a.on { color: var(--accent); border-color: color-mix(in oklab, var(--accent) 45%, transparent);
  background: color-mix(in oklab, var(--accent) 12%, transparent); }
@media (max-width: 46rem) { .chips { display: none; } }
.iconbtn { inline-size: 36px; block-size: 36px; display: grid; place-items: center; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; flex: none; }
.iconbtn:active { transform: scale(.94); }

/* الافتتاحية */
.hero { padding: clamp(2.5rem, 9vw, 5.5rem) 0 3rem; }
.eyebrow { display: inline-block; font-size: .76rem; letter-spacing: .04em; color: var(--accent);
  border: 1px solid color-mix(in oklab, var(--accent) 40%, transparent); border-radius: 99px;
  padding: .22rem .7rem; margin-bottom: 1.1rem; }
.hero h1 { font-size: clamp(2.1rem, 7.5vw, 3.6rem); font-weight: 700; text-wrap: balance; letter-spacing: -.01em; }
.hero .lead { font-size: clamp(1rem, 2.6vw, 1.16rem); color: var(--muted); margin-top: 1rem; font-weight: 300; }
.fine { font-size: .84rem; color: var(--faint); border-inline-start: 2px solid var(--line-2); padding-inline-start: .8rem; }

/* الفصول */
.chapter { padding: clamp(2.4rem, 7vw, 4.5rem) 0; border-block-start: 1px solid var(--line); }
.num { font-family: var(--f-m); font-size: .74rem; letter-spacing: .08em; color: var(--amber); display: block; margin-bottom: .5rem; }
.chapter h2 { font-size: clamp(1.5rem, 5vw, 2.1rem); margin-bottom: .9rem; }

/* صندوق السؤال */
.ask { border: 1px solid var(--line-2); border-radius: var(--r); background: var(--surface);
  padding: 1.1rem; margin: 1.6rem 0; backdrop-filter: blur(8px); }
.ask .q { font-weight: 500; color: var(--ink); margin-bottom: .9rem; }
.opts { display: grid; gap: .5rem; }
.opts button { text-align: start; cursor: pointer; border: 1px solid var(--line); background: var(--solid);
  border-radius: 12px; padding: .68rem .9rem; font-size: .95rem; font-weight: 300; transition: .18s var(--ease); }
.opts button:hover:not(:disabled) { border-color: var(--accent); transform: translateX(-3px); }
.opts button:disabled { cursor: default; opacity: .55; }
.opts button.right { border-color: var(--ok); background: color-mix(in oklab, var(--ok) 14%, transparent); color: var(--ok); opacity: 1; font-weight: 500; }
.opts button.wrong { border-color: var(--bad); background: color-mix(in oklab, var(--bad) 12%, transparent); color: var(--bad); opacity: 1; }
.verdict { margin: .9rem 0 0; font-size: .9rem; color: var(--muted); border-inline-start: 3px solid var(--accent);
  padding-inline-start: .8rem; }

/* المختبر */
.lab { margin-top: 1.6rem; }
.lab[hidden] { display: none; }
.controls { display: flex; flex-wrap: wrap; gap: .9rem 1.4rem; align-items: end;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); padding: 1rem 1.1rem; margin-bottom: 1.2rem; }
.controls label { display: grid; gap: .35rem; font-size: .84rem; color: var(--muted); flex: 1 1 15rem; }
.controls output { font-family: var(--f-m); font-size: .95rem; color: var(--accent); float: inline-end; }
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 5px; border-radius: 99px; background: color-mix(in oklab, var(--ink) 16%, transparent); }
input[type="range"]::-moz-range-track { height: 5px; border-radius: 99px; background: color-mix(in oklab, var(--ink) 16%, transparent); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; margin-top: -7.5px;
  border-radius: 50%; background: var(--accent); border: 3px solid var(--bg); box-shadow: 0 2px 8px -2px oklch(0% 0 0 / .5); }
input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--accent); border: 3px solid var(--bg); }

.btn { cursor: pointer; border: 1px solid var(--line-2); background: var(--solid); border-radius: 12px;
  padding: .6rem 1.1rem; font-size: .9rem; font-weight: 400; transition: .18s var(--ease); flex: none; }
.btn:hover { transform: translateY(-2px); border-color: var(--accent); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: progress; transform: none; }
.btn.primary { border: 0; color: var(--btn-ink); font-weight: 500;
  background: linear-gradient(120deg, var(--accent), color-mix(in oklab, var(--accent) 60%, var(--amber))); }
.hero .btn.primary { display: inline-block; text-decoration: none; margin-top: 1.4rem; padding: .8rem 1.6rem; }

figure { margin: 0; }
figcaption { font-size: .82rem; color: var(--faint); margin-bottom: .4rem; text-align: center; }
canvas { width: 100%; display: block; border: 1px solid var(--line); border-radius: 14px; background: color-mix(in oklab, var(--solid) 55%, transparent); }
.grid2 { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 44rem) { .grid2 { grid-template-columns: 1fr 1fr; } }

.readout { text-align: center; font-size: .86rem; color: var(--muted); margin: .5rem 0 0; }
.readout b, .stats3 b, .big-readout b { font-family: var(--f-m); color: var(--accent); font-size: 1.05rem;
  direction: ltr; unicode-bidi: isolate; display: inline-block; }
.stats3 { display: grid; gap: .7rem; grid-template-columns: 1fr; margin: 1rem 0 0; }
@media (min-width: 40rem) { .stats3 { grid-template-columns: repeat(3, 1fr); } }
.stats3 div { border: 1px solid var(--line); border-radius: 14px; padding: .7rem .8rem; background: var(--surface); text-align: center; }
.stats3 b { display: block; font-size: 1.5rem; line-height: 1.5; }
.mono { font-family: var(--f-m); direction: ltr; unicode-bidi: isolate; color: var(--muted); }
.stats3 span { font-size: .76rem; color: var(--faint); line-height: 1.6; display: block; }

.legend { display: flex; flex-wrap: wrap; gap: .5rem 1rem; justify-content: center; margin-top: .7rem; font-size: .8rem; color: var(--muted); }
.legend i { display: inline-block; inline-size: 11px; block-size: 11px; border-radius: 3px; margin-inline-end: .35rem; vertical-align: -1px; }

.big-readout { text-align: center; font-size: clamp(.95rem, 2.4vw, 1.1rem); margin-top: 1rem; color: var(--muted); }
.big-readout b { font-family: var(--f-m); color: var(--ink); }
.big-readout b.hl { color: var(--amber); font-size: 1.35em; }

.take { border: 1px dashed var(--line-2); border-radius: var(--r); padding: .95rem 1.1rem; font-size: .92rem;
  color: var(--muted); margin-top: 1.3rem; background: color-mix(in oklab, var(--accent) 6%, transparent); }
.take b { color: var(--ink); }

.foot { padding: 3rem 0 4rem; color: var(--faint); font-size: .86rem; border-block-start: 1px solid var(--line); margin-top: 2rem; }

/* ظهور تدريجي */
@media (prefers-reduced-motion: no-preference) {
  .chapter > * { animation: rise .6s var(--ease) both; }
  @supports (animation-timeline: view()) {
    .chapter > * { animation: rise linear both; animation-timeline: view(); animation-range: entry 0% cover 18%; }
  }
}
@keyframes rise { from { opacity: 0; transform: translateY(16px) } to { opacity: 1; transform: none } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
