:root {
  color-scheme: dark;
  --bg: #05070f;
  --surface: #0c1228;
  --surface-2: #121a38;
  --text: #e9efff;
  --muted: #a3aed0;
  --border: #222c55;
  --accent: #63ddff;
  --accent-text: #04202a;
  --accent-soft: #10264a;
  --gold: #4d8cff;
  --gold-text: #031433;
  --gold-ink: #8fb4ff;
  --link: #8ac8ff;
  --focus: #63ddff;
  --warn: #f0a050;
  --warn-soft: #2d2113;
  --warn-ink: #f6c48a;
  --hero-from: #0a1030;
  --hero-to: #1a2a66;
  --hero-text: #e9efff;
  --hero-border: #63ddff;
  --radius: 14px;
  --radius-sm: 8px;
  --maxw: 1120px;
  --prose: 46rem;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f7fc;
  --surface: #ffffff;
  --surface-2: #e8eef9;
  --text: #0c1228;
  --muted: #4a5679;
  --border: #cfd8ee;
  --accent: #0b6fa8;
  --accent-text: #ffffff;
  --accent-soft: #dcecf8;
  --gold: #2f62cc;
  --gold-text: #ffffff;
  --gold-ink: #1f4aa8;
  --link: #0b5a8a;
  --focus: #1f6fd0;
  --warn: #a35200;
  --warn-soft: #fbefdc;
  --warn-ink: #7a3d00;
  --hero-from: #0a1030;
  --hero-to: #1a2a66;
  --hero-text: #e9efff;
  --hero-border: #63ddff;
}

:root[data-theme="dark"] { color-scheme: dark; }

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-block-start: 5.5rem; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans Arabic", system-ui, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.95;
  overflow-wrap: anywhere;
}

[hidden] { display: none !important; }

a { color: var(--link); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

.skip { position: absolute; inset-inline-start: 8px; inset-block-start: -60px; background: var(--accent); color: var(--accent-text); padding: 8px 14px; border-radius: 8px; z-index: 100; }
.skip:focus { inset-block-start: 8px; }

.progress { position: fixed; inset-block-start: 0; inset-inline: 0; height: 4px; z-index: 60; background: transparent; }
.progress span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), var(--accent)); transition: width 0.1s linear; }

/* الشريط العلوي */
.topbar { position: sticky; inset-block-start: 0; z-index: 50; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: 10px 20px; background:var(--bg); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-block-end: 1px solid var(--border); }
@supports (color: color-mix(in srgb, red 50%, blue)) { .topbar { background: color-mix(in srgb, var(--bg) 88%, transparent) } }
.brand { font-weight: 800; font-size: 1.25rem; color: var(--text); text-decoration: none; letter-spacing: 0.01em; }
.brand::before { content: ""; display: inline-block; width: 0.7em; height: 0.7em; margin-inline-end: 0.5em; background: linear-gradient(135deg, var(--gold), var(--accent)); border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%; }
.topbar-actions { display: flex; gap: 8px; }
.site-nav { flex-basis: 100%; }
.site-nav ul { display: flex; flex-wrap: wrap; gap: 4px 6px; list-style: none; margin: 0; padding: 0; }
.site-nav a { display: block; padding: 4px 12px; border-radius: 999px; color: var(--muted); text-decoration: none; font-size: 0.95rem; line-height: 1.7; }
.site-nav a:hover { background: var(--accent-soft); color: var(--text); }
.site-nav a[aria-current="page"] { background: var(--accent); color: var(--accent-text); }
#nav-toggle { display: none; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 18px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1.4; }
.btn:hover { border-color: var(--accent); }
.btn-small { min-height: 36px; padding: 4px 14px; font-size: 0.9rem; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-gold { background: var(--gold); border-color: var(--gold); color: var(--gold-text); }
.btn-ghost { background: transparent; border-color: var(--hero-border); color: var(--hero-text); }

/* البطل */
.hero { position: relative; overflow: hidden; background: linear-gradient(135deg, var(--hero-from), var(--hero-to)); color: var(--hero-text); }
.hero-art { position: absolute; inset: 0; opacity: 0.3; pointer-events: none; }
.hero-art svg { width: 100%; height: 100%; }
.hero-inner { position: relative; max-width: var(--maxw); margin: 0 auto; padding: clamp(56px, 11vw, 132px) 24px clamp(48px, 9vw, 108px); }
.eyebrow { margin: 0 0 12px; color: var(--hero-text); font-weight: 700; letter-spacing: 0.04em; font-size: 0.95rem; }
.hero h1 { margin: 0 0 18px; font-size: clamp(2.4rem, 7vw, 4.6rem); line-height: 1.2; font-weight: 800; }
.hero .lead { max-width: 38rem; font-size: clamp(1.1rem, 2.4vw, 1.4rem); line-height: 1.9; margin: 0 0 28px; color: var(--hero-text); opacity: 0.92; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; }

.page-head { max-width: var(--maxw); margin: 0 auto; padding: clamp(24px, 4.5vw, 52px) 24px 8px; }
.page-head::after { content: ""; display: block; width: 84px; height: 5px; margin-top: 22px; border-radius: 4px; background: linear-gradient(90deg, var(--gold), var(--accent)); }
.page-head h1 { margin: 0 0 14px; font-size: clamp(1.9rem, 5vw, 3.1rem); line-height: 1.3; }
.page-head .eyebrow { color: var(--accent); }
.lead { font-size: 1.2rem; color: var(--muted); max-width: 44rem; margin: 0; line-height: 1.9; }

/* التخطيط */
.layout { max-width: var(--maxw); margin: 0 auto; padding: 24px; display: grid; grid-template-columns: minmax(0, var(--prose)) 15rem; gap: 56px; align-items: start; }
.layout-home { display: block; }
.layout-home .prose { max-width: none; }
.prose { min-width: 0; }
.prose > * { max-width: var(--prose); }
.layout-home .prose > * { max-width: none; }
.layout-home .prose > p, .layout-home .prose > .callout, .layout-home .prose > ul, .layout-home .prose > ol { max-width: var(--prose); }
.prose h2 { margin: 2.6em 0 0.6em; font-size: clamp(1.5rem, 3.4vw, 2rem); line-height: 1.4; position: relative; padding-inline-start: 18px; }
.prose h2::before { content: ""; position: absolute; inset-inline-start: 0; inset-block: 0.25em; width: 5px; border-radius: 4px; background: linear-gradient(180deg, var(--gold), var(--accent)); }
.prose h3 { margin: 1.8em 0 0.4em; font-size: 1.25rem; color: var(--accent); }
.prose p { margin: 0 0 1.1em; }
.cite { font-size: 0.88em; color: var(--muted); white-space: nowrap; }
.cite a { color: var(--muted); }
.list { margin: 0 0 1.2em; padding-inline-start: 1.4em; }
.list li { margin-bottom: 0.5em; }
strong { font-weight: 700; }

.toc { position: sticky; inset-block-start: 7rem; padding: 18px 20px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); font-size: 0.95rem; line-height: 1.7; }
.toc-title { margin: 0 0 8px; font-weight: 800; color: var(--accent); }
.toc ol { margin: 0; padding-inline-start: 1.1em; }
.toc li { margin-bottom: 6px; }
.toc a { color: var(--muted); text-decoration: none; }
.toc a:hover { color: var(--text); text-decoration: underline; }

/* صناديق */
.callout { margin: 1.6em 0; padding: 18px 22px; border-radius: var(--radius); border: 1px solid var(--border); border-inline-start: 6px solid var(--accent); background: var(--surface); }
.callout p { margin: 0 0 0.5em; }
.callout p:last-child, .callout .list:last-child { margin-bottom: 0; }
.callout-title { font-weight: 800; color: var(--accent); }
.callout-key { background: var(--accent-soft); }
.callout-use { border-inline-start-color: var(--gold); }
.callout-use .callout-title { color: var(--gold-ink); }
.callout-warn { border-inline-start-color: var(--warn); background: var(--warn-soft); }
.callout-warn .callout-title { color: var(--warn-ink); }

.table-wrap { overflow-x: auto; margin: 1.6em 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); max-width: 100%; }
table { width: 100%; border-collapse: collapse; font-size: 0.97rem; line-height: 1.7; }
caption { padding: 14px 16px; text-align: start; font-weight: 800; color: var(--accent); }
th, td { padding: 10px 16px; text-align: start; border-block-start: 1px solid var(--border); vertical-align: top; }
thead th { background: var(--surface-2); font-weight: 800; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 15.5rem), 1fr)); gap: 16px; margin: 1.4em 0; }
.card { display: flex; flex-direction: column; gap: 6px; padding: 22px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none; line-height: 1.7; transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease; }
.card:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow:0 10px 28px rgba(0,0,0,.2); }
@supports (color: color-mix(in srgb, red 50%, blue)) { .card:hover { box-shadow: 0 10px 28px color-mix(in srgb, var(--accent) 18%, transparent) } }
.card strong { font-size: 1.15rem; }
.card span:last-child { color: var(--muted); font-size: 0.95rem; }
.card-no { width: 2.2rem; height: 2.2rem; display: grid; place-items: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 800; }

.steps { list-style: none; margin: 1.4em 0; padding: 0; counter-reset: s; display: grid; gap: 14px; }
.steps li { counter-increment: s; position: relative; padding: 16px 20px; padding-inline-start: 68px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); display: flex; flex-direction: column; gap: 4px; }
.steps li::before { content: counter(s); position: absolute; inset-inline-start: 18px; inset-block-start: 14px; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; background: var(--accent); color: var(--accent-text); font-weight: 800; }

.quiz { margin: 2em 0; padding: 22px; border-radius: var(--radius); background: var(--surface-2); border: 1px dashed var(--accent); }
.quiz h3 { margin-top: 0; }
.qa { margin-bottom: 10px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); }
.qa summary { cursor: pointer; padding: 12px 16px; font-weight: 700; min-height: 44px; }
.qa p { margin: 0; padding: 0 16px 14px; }
.hint { color: var(--muted); font-size: 0.93rem; line-height: 1.8; }

/* الأدوات */
.widget { margin: 2em 0; padding: 24px; border-radius: var(--radius); border: 1px solid var(--accent); background: var(--surface); }
.widget h3 { margin-top: 0; }
.widget .row { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 14px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 9rem; flex: 1 1 9rem; }
.field label { font-weight: 700; font-size: 0.95rem; }
.field input, .field textarea, .field select { min-height: 44px; padding: 8px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit; }
.field textarea { min-height: 96px; resize: vertical; }
.out { margin-top: 14px; padding: 16px; border-radius: var(--radius-sm); background: var(--accent-soft); min-height: 3rem; }
.out ol, .out ul { margin: 0; padding-inline-start: 1.3em; }
.meter { display: flex; height: 22px; border-radius: 999px; overflow: hidden; border: 1px solid var(--border); margin: 10px 0; background: var(--surface-2); }
.meter span { display: block; height: 100%; min-width: 2px; }
.meter .m-a { background: var(--accent); }
.meter .m-b { background: var(--gold); }
.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: 0.9rem; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-inline-end: 6px; vertical-align: -1px; }
.legend .l-a { background: var(--accent); }
.legend .l-b { background: var(--gold); }
.checks { list-style: none; margin: 0 0 1em; padding: 0; display: grid; gap: 8px; }
.checks label { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); cursor: pointer; line-height: 1.7; }
.checks input { width: 22px; height: 22px; margin-top: 3px; accent-color: var(--accent); flex: none; }

/* المراجع */
.page-refs { margin-top: 3em; padding-top: 1.4em; border-top: 1px solid var(--border); }
.page-refs h2 { font-size: 1.3rem; }
.refs { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.refs li { padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: space-between; font-size: 0.95rem; line-height: 1.7; }
.refs li:target { border-color: var(--gold); box-shadow:0 0 0 3px var(--gold); }
@supports (color: color-mix(in srgb, red 50%, blue)) { .refs li:target { box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 35%, transparent) } }
.ref-text { flex: 1 1 20rem; text-align: left; }
.refs-full { max-width: var(--prose); }
.doi { word-break: break-all; }

.pn-wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 24px 56px; display: flex; flex-wrap: wrap; gap: 16px; justify-content: space-between; }
.pn { flex: 1 1 14rem; display: flex; flex-direction: column; gap: 2px; padding: 16px 20px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); text-decoration: none; line-height: 1.6; }
.pn:hover { border-color: var(--accent); }
.pn span { color: var(--muted); font-size: 0.88rem; }
.pn-next { text-align: end; }

.footer { border-top: 1px solid var(--border); padding: 28px 24px 44px; text-align: center; color: var(--muted); background: var(--surface); }
.footer p { margin: 0 auto 6px; max-width: 46rem; }

.toast { position: fixed; inset-inline: 0; inset-block-end: 20px; margin: 0 auto; width: fit-content; max-width: 90vw; padding: 10px 20px; border-radius: 999px; background: var(--text); color: var(--bg); opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 90; }
.toast.show { opacity: 1; }

@media (max-width: 899px) {
  .layout { display: block; padding: 16px; }
  .toc { position: static; margin: 0 0 20px; order: -1; }
  .layout .toc { display: block; }
  #nav-toggle { display: inline-flex; }
  .site-nav { display: none; }
  .site-nav.open { display: block; }
  .site-nav ul { flex-direction: column; }
  .topbar { padding: 8px 14px; }
  .hero-inner, .page-head, .pn-wrap { padding-inline: 16px; }
  body { font-size: 1.03rem; line-height: 1.9; }
}

@media (min-width: 900px) {
  .layout .toc { order: 2; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media print {
  .topbar, .progress, .toc, .pn-wrap, .toast, .hero-art, .copy-ref, .no-print { display: none !important; }
  body { background: Canvas; color: CanvasText; font-size: 12pt; }
  .hero { background: none; color: CanvasText; }
  .hero h1, .hero .lead, .eyebrow { color: CanvasText; }
  .layout { display: block; padding: 0; }
  .callout, .widget, .table-wrap, .refs li { break-inside: avoid; }
  a { color: CanvasText; }
}

.page-head .eyebrow { color: var(--accent); }
.hero .eyebrow { color: var(--hero-text); opacity: 0.9; }

.card > span:not(.card-no):not(.card-meta) { color: var(--muted); font-size: 0.95rem; }
.card .card-meta { margin-top: auto; padding-top: 6px; font-size: 0.82rem; color: var(--muted); }
.card.is-read, .site-nav a.is-read { position: relative; }
.card.is-read::after { content: "✓ قرأتها"; position: absolute; inset-block-start: 14px; inset-inline-end: 16px; font-size: 0.78rem; color: var(--accent); font-weight: 700; }
.site-nav a.is-read::after { content: " ✓"; color: var(--gold); }
.site-nav a[aria-current="page"].is-read::after { color: var(--accent-text); }
.meta { display: flex; gap: 14px; flex-wrap: wrap; margin: 14px 0 0; font-size: 0.9rem; color: var(--muted); }
.meta-read { color: var(--accent); font-weight: 700; }
.read-progress { margin: 0 0 18px; padding: 10px 16px; border-radius: var(--radius-sm); background: var(--accent-soft); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.trust { list-style: none; margin: 0; padding: 14px 24px; display: flex; flex-wrap: wrap; gap: 10px 28px; justify-content: center; background: var(--surface-2); border-block-end: 1px solid var(--border); font-weight: 600; font-size: 0.95rem; }
.trust li::before { content: "✓"; color: var(--accent); margin-inline-end: 8px; font-weight: 800; }
.tldr { margin: 1.4em 0 2em; padding: 20px 24px; border-radius: var(--radius); background: var(--accent-soft); border: 1px solid var(--accent); }
.tldr-title { margin: 0 0 8px; font-weight: 800; color: var(--accent); }
.tldr-title::before { content: "⚡ "; }
.tldr ul { margin: 0; padding-inline-start: 1.3em; }
.tldr li { margin-bottom: 6px; }
.callout-title::before { margin-inline-end: 6px; }
.callout-key .callout-title::before { content: "💡"; }
.callout-warn .callout-title::before { content: "⚠️"; }
.callout-use .callout-title::before { content: "🧭"; }
.toc summary { cursor: pointer; list-style: none; }
.toc summary::-webkit-details-marker { display: none; }
.toc summary::after { content: " ▾"; color: var(--muted); }
.toc a[aria-current="true"] { color: var(--accent); font-weight: 800; }
.search { position: relative; flex: 1 1 14rem; max-width: 22rem; margin-inline-start: auto; }
.search input { width: 100%; min-height: 40px; padding: 4px 16px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: 0.95rem; }
.q-res { position: absolute; inset-inline: 0; inset-block-start: calc(100% + 6px); z-index: 70; list-style: none; margin: 0; padding: 6px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); box-shadow:0 12px 30px rgba(0,0,0,.2); max-height: 60vh; overflow-y: auto; }
@supports (color: color-mix(in srgb, red 50%, blue)) { .q-res { box-shadow: 0 12px 30px color-mix(in srgb, var(--text) 18%, transparent) } }
.q-res a { display: block; padding: 8px 12px; border-radius: 6px; color: var(--text); text-decoration: none; line-height: 1.6; font-size: 0.93rem; }
.q-res a:hover, .q-res a:focus-visible { background: var(--accent-soft); }
.q-none { padding: 8px 12px; color: var(--muted); }
.to-top { position: fixed; inset-block-end: 20px; inset-inline-start: 20px; width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--border); background: var(--accent); color: var(--accent-text); font-size: 1.3rem; cursor: pointer; z-index: 55; box-shadow:0 6px 18px rgba(0,0,0,.2); }
@supports (color: color-mix(in srgb, red 50%, blue)) { .to-top { box-shadow: 0 6px 18px color-mix(in srgb, var(--text) 25%, transparent) } }
.page-head .lead { font-size: 1.25rem; }
.prose > p:first-of-type { font-size: 1.08rem; }
@media (max-width: 899px) { .search { order: 3; flex-basis: 100%; max-width: none; } .trust { justify-content: flex-start; } }
@media print { .search, .to-top, .tldr-title::before { display: none !important; } }

.sr-only, .offscreen { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.art .s-a { fill: var(--gold); }
.art .s-b { fill: var(--hero-text); }
.art .s-c { fill: none; stroke: var(--hero-text); stroke-width: 2; }
.art .s-d { fill: none; stroke: var(--gold); stroke-width: 3; }
.art .s-e { fill: var(--accent); }
.big-num { font-size: 2.2rem; font-weight: 800; color: var(--accent); line-height: 1.2; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); gap: 14px; margin: 1.4em 0; }
.stat { padding: 18px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
.stat p { margin: 0; }
.plan-list { margin: 0; padding-inline-start: 1.2em; }
.plan-list li { margin-bottom: 4px; }

/* الجداول: لا تُكسر الكلمات حرفًا حرفًا، والأعمدة بحد أدنى مقروء، ويمرَّر الجدول أفقيًا عند الضيق */
.table-wrap table { overflow-wrap: normal; word-break: normal; }
.table-wrap th, .table-wrap td { overflow-wrap: normal; word-break: normal; hyphens: none; min-width: 7.5rem; padding: 10px 12px; }
.table-wrap td .doi, .table-wrap td a.doi { word-break: break-all; }
@media (max-width: 600px) {
  .table-wrap th:first-child, .table-wrap td:first-child { min-width: 6.5rem; font-weight: 700; }
  .table-wrap table { font-size: 0.94rem; }
}
