/* ============================================================
   البنية المعمارية لصيغ الصور — "مختبر الطيف" (Spectral Signal Lab)
   ثيم مشتقّ من الموضوع: ضوء يتفكّك إلى بيانات.
   قاعدة داكنة باردة (غرفة مظلمة) + إشارة سماوية مهيمنة +
   موتيف طيفي (قوس ألوان) يجسّد تفكيك الضوء، ونسيج شبكة بكسلات.
   ============================================================ */

:root {
  /* surfaces — غرفة مظلمة باردة، أزرق-بنفسجي عميق */
  --bg-void: #06070d;
  --bg-deep: #0a0c16;
  --bg-panel: #0e1120;
  --bg-elevated: #151a2c;
  --bg-code: #07080f;

  /* borders / lines */
  --line: #1c2236;
  --line-strong: #2c3552;
  --line-faint: #121624;

  /* text */
  --fg: #dde3f0;
  --fg-muted: #95a0ba;
  --fg-dim: #5d667e;
  --fg-faint: #3b4258;

  /* accents — طيف: أزرق إشارة مهيمن، تركواز ثانوي، بنفسجي كروما، كهرماني/أحمر دلالي */
  --acid: #49c5ff;        /* dominant — أزرق الإشارة (luma/scope) */
  --acid-dim: #226d92;
  --cyan: #37e0c2;        /* secondary — تركواز (عناوين فرعية، تأكيد) */
  --cyan-dim: #1d7a68;
  --amber: #ffb454;       /* warn */
  --amber-dim: #8a5f1f;
  --red: #ff5470;         /* danger */
  --red-dim: #8a2235;
  --magenta: #c07cff;     /* chroma/violet — كلمات مفتاحية، لمسة كروما */
  --magenta-dim: #5e3a8a;

  /* الطيف الكامل — الموتيف الجوهري (تفكيك الضوء/القنوات) */
  --spectrum: linear-gradient(90deg, #ff5470, #ffb454, #37e0c2, #49c5ff, #c07cff);

  /* type */
  --mono: "JetBrains Mono", "IBM Plex Mono", ui-monospace, monospace;
  --ar: "IBM Plex Sans Arabic", "Tajawal", "Noto Sans Arabic", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg-void);
  color: var(--fg);
  font-family: var(--ar);
  font-size: 16px;
  line-height: 1.78;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* النسيج: شبكة بكسلات دقيقة (lattice أخذ العيّنات) + توهّج طيفي خافت */
body {
  background-image:
    radial-gradient(ellipse at 15% 0%, rgba(73,197,255,0.05) 0%, transparent 45%),
    radial-gradient(ellipse at 85% 75%, rgba(192,124,255,0.045) 0%, transparent 45%),
    linear-gradient(rgba(120,150,200,0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120,150,200,0.022) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 22px 22px, 22px 22px;
  background-attachment: fixed;
  min-height: 100vh;
}

::selection { background: var(--acid); color: var(--bg-void); }

a { color: var(--acid); text-decoration: none; border-bottom: 1px dashed var(--acid-dim); }
a:hover { color: var(--cyan); border-color: var(--cyan); }

/* شريط طيفي — الموتيف الموحّد */
.spectral-bar {
  height: 3px; width: 100%;
  background: var(--spectrum);
  border: none; margin: 0; padding: 0;
  opacity: 0.85;
}

/* ============================================================ LAYOUT */
.shell { display: grid; grid-template-columns: 320px 1fr; min-height: 100vh; }

.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 24px;
  padding: 10px 28px;
  background: var(--bg-void);
  border-bottom: 1px solid var(--line);
  font-family: var(--mono); font-size: 11px;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--fg-dim);
}
.topbar .brand { color: var(--acid); font-weight: 700; display: flex; align-items: center; gap: 8px; }
.topbar .brand::before {
  content: ""; width: 9px; height: 9px;
  background: var(--spectrum); display: inline-block;
  border-radius: 1px;
}
.topbar .meta { display: flex; gap: 18px; flex-wrap: wrap; }
.topbar .meta b { color: var(--cyan); font-weight: 500; }
.topbar .spacer { flex: 1; }
.topbar .status { color: var(--acid); display: flex; align-items: center; gap: 6px; }
.topbar .status::before {
  content: ""; width: 8px; height: 8px;
  background: var(--acid); border-radius: 50%;
  box-shadow: 0 0 8px var(--acid);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.35; transform: scale(0.65); } }

/* sidebar */
.sidebar {
  position: sticky; top: 40px; height: calc(100vh - 40px);
  overflow-y: auto; background: var(--bg-deep);
  border-left: 1px solid var(--line);
  padding: 26px 22px 60px;
  font-family: var(--mono); font-size: 13px;
}
.sidebar .sb-title {
  font-size: 10px; letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--fg-dim); margin: 22px 0 8px;
  display: flex; align-items: center; gap: 8px;
}
.sidebar .sb-title::before {
  content: ""; display: inline-block; width: 6px; height: 6px;
  background: var(--acid); transform: rotate(45deg);
}
.sidebar .sb-title:first-child { margin-top: 0; }
.sidebar a {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 7px 10px; border: none; color: var(--fg-muted);
  border-right: 2px solid transparent;
  font-size: 13px; line-height: 1.5; margin-bottom: 1px; transition: all 0.12s;
}
.sidebar a:hover { background: var(--bg-elevated); color: var(--fg); border-right-color: var(--acid-dim); }
.sidebar a.active { background: var(--bg-elevated); color: var(--acid); border-right-color: var(--acid); }
.sidebar a .num { color: var(--fg-dim); font-size: 11px; flex-shrink: 0; min-width: 22px; }
.sidebar a.active .num { color: var(--acid); }
.sidebar a.locked { color: var(--fg-faint); cursor: default; }
.sidebar a.locked:hover { background: transparent; color: var(--fg-faint); border-right-color: transparent; }
.sidebar a.locked .num::before { content: "▣ "; color: var(--fg-faint); }

.cheat {
  font-family: var(--mono); font-size: 11px; color: var(--fg-dim);
  padding: 12px 12px; line-height: 1.9;
  background: var(--bg-panel); border: 1px solid var(--line); margin-top: 6px;
}
.cheat b { color: var(--acid); font-weight: 500; }
.cheat .v2 { color: var(--cyan); }
.cheat .v3 { color: var(--amber); }

.main { padding: 56px 64px 120px; max-width: 1120px; width: 100%; }

/* ============================================================ TYPE */
h1, h2, h3, h4 { font-family: var(--ar); font-weight: 700; color: var(--fg); line-height: 1.3; text-wrap: balance; }
h1 { font-size: clamp(34px, 4vw, 52px); margin: 0 0 12px; letter-spacing: -0.01em; }
h1 .accent { color: var(--acid); }

h2 {
  font-size: 30px; margin: 66px 0 18px; padding-bottom: 14px;
  border-bottom: 1px solid var(--line); position: relative;
}
h2::before {
  content: attr(data-num); display: inline-block;
  font-family: var(--mono); font-size: 13px; color: var(--acid);
  margin-left: 14px; padding: 2px 8px;
  background: rgba(73,197,255,0.07); border: 1px solid var(--acid-dim);
  letter-spacing: 0.05em; vertical-align: middle;
}
h3 { font-size: 22px; margin: 42px 0 12px; color: var(--cyan); }
h3::before { content: "// "; font-family: var(--mono); color: var(--fg-dim); font-weight: 400; }
h4 { font-size: 17px; margin: 28px 0 10px; color: var(--amber); font-family: var(--mono); font-weight: 500; letter-spacing: 0.02em; }

p { margin: 0 0 16px; text-wrap: pretty; }
strong, b { color: var(--fg); font-weight: 700; }
em { color: var(--cyan); font-style: normal; font-weight: 500; }
ul, ol { padding-right: 22px; margin: 0 0 18px; }
li { margin-bottom: 8px; }
li::marker { color: var(--acid); }

code, .en { font-family: var(--mono); direction: ltr; unicode-bidi: isolate; }
code {
  background: var(--bg-elevated); color: var(--cyan);
  padding: 1px 6px; font-size: 0.88em;
  border: 1px solid var(--line); border-radius: 2px;
}

/* ============================================================ HERO */
.hero { padding: 76px 64px 56px; border-bottom: 1px solid var(--line); position: relative; overflow: hidden; }
.hero::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(circle at 18% 28%, rgba(73,197,255,0.10) 0%, transparent 42%),
    radial-gradient(circle at 82% 72%, rgba(192,124,255,0.09) 0%, transparent 42%);
}
/* شبكة بكسلات أبرز في الـ hero */
.hero::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0.5;
  background:
    linear-gradient(rgba(120,150,200,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120,150,200,0.04) 1px, transparent 1px);
  background-size: 30px 30px, 30px 30px;
  mask-image: linear-gradient(120deg, black, transparent 70%);
}
.hero > * { position: relative; z-index: 1; }

.hero-meta { display: flex; gap: 14px; margin-bottom: 24px; font-family: var(--mono); font-size: 12px; color: var(--fg-dim); letter-spacing: 0.06em; text-transform: uppercase; flex-wrap: wrap; }
.hero-meta .tag { padding: 4px 10px; border: 1px solid var(--line); background: var(--bg-panel); color: var(--fg-muted); }
.hero-meta .tag.live { color: var(--acid); border-color: var(--acid-dim); }
.hero-meta .tag.spec { color: var(--magenta); border-color: var(--magenta-dim); }

.hero h1 { font-size: clamp(40px, 5.5vw, 74px); font-weight: 800; line-height: 1.06; margin: 0 0 18px; }
.hero h1 .accent { color: var(--acid); }

/* موتيف: انفصال قنوات RGB (الكروما مرئية) بدل الـ glitch */
.split { position: relative; display: inline-block; }
.split::before, .split::after {
  content: attr(data-text); position: absolute; top: 0; left: 0;
  width: 100%; height: 100%; pointer-events: none; opacity: 0.55;
  mix-blend-mode: screen;
}
.split::before { color: #ff5470; transform: translate(-3px, 0); animation: chroma-r 6s ease-in-out infinite; }
.split::after  { color: #49c5ff; transform: translate(3px, 0);  animation: chroma-b 6s ease-in-out infinite; }
@keyframes chroma-r { 0%,92%,100% { transform: translate(-3px,0);} 95% { transform: translate(-6px,1px);} }
@keyframes chroma-b { 0%,92%,100% { transform: translate(3px,0);}  95% { transform: translate(6px,-1px);} }

.hero .lede { font-size: 20px; color: var(--fg-muted); max-width: 820px; line-height: 1.72; }
.hero .spectral-bar { margin-top: 30px; max-width: 480px; }

/* ============================================================ PANELS / CALLOUTS */
.panel { background: var(--bg-panel); border: 1px solid var(--line); padding: 22px 26px; margin: 22px 0; position: relative; }
.panel.bracket::before, .panel.bracket::after { content: ""; position: absolute; width: 14px; height: 14px; border: 1px solid var(--acid); }
.panel.bracket::before { top: -1px; right: -1px; border-bottom: none; border-left: none; }
.panel.bracket::after  { bottom: -1px; left: -1px; border-top: none; border-right: none; }

.callout {
  margin: 24px 0; padding: 16px 22px; background: var(--bg-panel);
  border-right: 3px solid var(--acid);
  border-left: 1px solid var(--line); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.callout.warn { border-right-color: var(--amber); }
.callout.danger { border-right-color: var(--red); }
.callout.info { border-right-color: var(--cyan); }
.callout .label {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--acid); margin-bottom: 6px; display: flex; align-items: center; gap: 8px;
}
.callout.warn .label { color: var(--amber); }
.callout.danger .label { color: var(--red); }
.callout.info .label { color: var(--cyan); }
.callout .label::before { content: "▸"; }
.callout p:last-child { margin-bottom: 0; }

/* ============================================================ TABLES */
table { width: 100%; border-collapse: collapse; margin: 22px 0; font-size: 14px; background: var(--bg-panel); border: 1px solid var(--line); }
th {
  background: var(--bg-elevated); color: var(--acid); font-family: var(--mono);
  font-size: 12px; font-weight: 500; letter-spacing: 0.05em; text-transform: uppercase;
  text-align: right; padding: 12px 16px; border-bottom: 1px solid var(--line-strong);
}
td { padding: 12px 16px; border-bottom: 1px solid var(--line-faint); vertical-align: top; color: var(--fg-muted); }
td:first-child { color: var(--fg); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(73,197,255,0.025); }

/* ============================================================ CODE / TERMINAL */
pre {
  background: var(--bg-code); border: 1px solid var(--line); padding: 0; margin: 22px 0;
  overflow: hidden; font-family: var(--mono); font-size: 13.5px; line-height: 1.65; position: relative;
}
pre .term-head {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  background: var(--bg-elevated); border-bottom: 1px solid var(--line);
  font-size: 11px; color: var(--fg-dim); letter-spacing: 0.08em; text-transform: uppercase;
}
pre .term-head::before { content: "● ● ●"; color: var(--fg-dim); letter-spacing: 2px; font-size: 8px; }
pre .term-head .tt { color: var(--acid); margin-right: auto; }
pre code { display: block; padding: 18px 20px; background: transparent; border: none; color: var(--fg); white-space: pre; overflow-x: auto; direction: ltr; text-align: left; }
pre code .pmt { color: var(--acid); }
pre code .cmt { color: var(--fg-dim); font-style: italic; }
pre code .kw  { color: var(--magenta); }
pre code .str { color: var(--amber); }
pre code .num { color: var(--cyan); }

/* ============================================================ ASCII / FIGURE */
.ascii {
  font-family: var(--mono); font-size: 12px; line-height: 1.5; white-space: pre;
  background: var(--bg-code); border: 1px solid var(--line); padding: 18px 22px; margin: 22px 0;
  color: var(--fg-muted); overflow-x: auto; direction: ltr; text-align: left;
}
.ascii .hl { color: var(--acid); }
.ascii .hl2 { color: var(--cyan); }
.ascii .hl3 { color: var(--amber); }
.ascii .hl4 { color: var(--magenta); }
.ascii .dim { color: var(--fg-faint); }

figure { margin: 28px 0; background: var(--bg-panel); border: 1px solid var(--line); padding: 0; overflow: hidden; }
figure .fig-head {
  padding: 10px 18px; background: var(--bg-elevated); border-bottom: 1px solid var(--line);
  font-family: var(--mono); font-size: 11px; color: var(--fg-dim);
  letter-spacing: 0.08em; text-transform: uppercase; display: flex; align-items: center; gap: 10px;
}
figure .fig-head .id { color: var(--acid); }
figure .fig-head::after { content: ""; flex: 1; height: 1px; background: var(--spectrum); opacity: 0.4; }
figure .fig-body { padding: 28px 24px; display: flex; justify-content: center; }
figure .fig-body svg { max-width: 100%; height: auto; }
figure figcaption { padding: 10px 18px; border-top: 1px solid var(--line); background: var(--bg-deep); font-size: 13px; color: var(--fg-muted); text-align: center; }

/* عناصر SVG مساعدة (نصوص داخل المخططات) */
.svg-mono { font-family: "JetBrains Mono", monospace; }

/* ============================================================ STATS */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin: 24px 0; }
.stat { border: 1px solid var(--line); background: var(--bg-panel); padding: 18px; position: relative; overflow: hidden; }
.stat::after { content: ""; position: absolute; bottom: 0; left: 0; right: 0; height: 2px; background: var(--spectrum); opacity: 0.5; }
.stat .v { font-family: var(--mono); font-size: 30px; color: var(--acid); font-weight: 700; line-height: 1; }
.stat .k { font-family: var(--mono); font-size: 11px; color: var(--fg-dim); text-transform: uppercase; letter-spacing: 0.1em; margin-top: 8px; }

/* ============================================================ MODULE GRID */
.modgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 16px; margin: 28px 0; }
.modcard {
  display: block; background: var(--bg-panel); border: 1px solid var(--line);
  padding: 24px; color: var(--fg); position: relative; transition: all 0.15s ease; overflow: hidden;
}
.modcard:hover { border-color: var(--acid-dim); background: var(--bg-elevated); transform: translateY(-2px); }
.modcard::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 2px; background: var(--spectrum); opacity: 0; transition: opacity 0.15s; }
.modcard:hover::before { opacity: 0.7; }
.modcard .mc-num { font-family: var(--mono); font-size: 11px; color: var(--acid); letter-spacing: 0.15em; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.modcard .mc-num::after { content: ""; flex: 1; border-top: 1px dashed var(--line-strong); }
.modcard .mc-title { font-size: 21px; font-weight: 700; margin: 0 0 8px; color: var(--fg); line-height: 1.3; }
.modcard .mc-desc { font-size: 14px; color: var(--fg-muted); line-height: 1.65; margin-bottom: 16px; }
.modcard .mc-foot { display: flex; justify-content: space-between; align-items: center; font-family: var(--mono); font-size: 11px; color: var(--fg-dim); text-transform: uppercase; letter-spacing: 0.08em; padding-top: 14px; border-top: 1px solid var(--line); }
.modcard .mc-foot .open { color: var(--acid); }
.modcard:hover .mc-foot .open::after { content: " ←"; }

.modcard.locked { opacity: 0.55; pointer-events: none; }
.modcard.locked .mc-num { color: var(--fg-dim); }
.modcard.locked .mc-foot .open { color: var(--fg-dim); }
.modcard.locked .mc-foot .open::before { content: "▣ "; }

/* ============================================================ PAGER */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 64px 0 0; border-top: 1px solid var(--line); padding-top: 28px; }
.pager a { display: block; padding: 18px 22px; background: var(--bg-panel); border: 1px solid var(--line); color: var(--fg); transition: all 0.15s; }
.pager a:hover { border-color: var(--acid-dim); background: var(--bg-elevated); }
.pager .label { font-family: var(--mono); font-size: 11px; color: var(--fg-dim); letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 6px; }
.pager .title { font-size: 15px; color: var(--acid); }
.pager .seed { font-size: 12px; color: var(--magenta); margin-top: 6px; font-style: italic; }
.pager .next { text-align: left; }
.pager .next .label::before { content: "→ "; }
.pager .prev .label::after  { content: " ←"; }

/* ============================================================ BOX (puzzles) */
.box { margin: 28px 0; border: 1px solid var(--line); background: var(--bg-panel); padding: 26px 28px 22px; position: relative; }
.box::before {
  content: attr(data-label); position: absolute; top: -10px; right: 20px;
  background: var(--bg-void); padding: 0 10px; font-family: var(--mono); font-size: 11px;
  color: var(--acid); letter-spacing: 0.15em; text-transform: uppercase;
}
.box.amber { border-color: var(--amber-dim); }
.box.amber::before { color: var(--amber); }
.box.amber::after { content: ""; position: absolute; top: 0; right: 0; bottom: 0; width: 3px; background: var(--amber); opacity: 0.6; }
.box.puzzle { border-color: var(--magenta-dim); }
.box.puzzle::before { color: var(--magenta); }
.box.puzzle::after { content: ""; position: absolute; top: 0; right: 0; bottom: 0; width: 3px; background: var(--magenta); opacity: 0.6; }
.box ol:last-child, .box ul:last-child, .box p:last-child { margin-bottom: 0; }

/* ============================================================ BADGES */
.badge { display: inline-block; padding: 2px 8px; font-family: var(--mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; border: 1px solid var(--line-strong); color: var(--fg-muted); background: var(--bg-elevated); vertical-align: middle; direction: ltr; }
.badge.ok { color: var(--acid); border-color: var(--acid-dim); }
.badge.bad { color: var(--red); border-color: var(--red-dim); }
.badge.warn { color: var(--amber); border-color: var(--amber-dim); }
.badge.info { color: var(--cyan); border-color: var(--cyan-dim); }
.badge.spec { color: var(--magenta); border-color: var(--magenta-dim); }

/* ============================================================ TOC */
.toc { background: var(--bg-panel); border: 1px solid var(--line); padding: 18px 26px; margin: 24px 0 32px; font-size: 14px; position: relative; }
.toc::before { content: ""; position: absolute; top: 0; right: 0; bottom: 0; width: 2px; background: var(--spectrum); opacity: 0.4; }
.toc .toc-h { font-family: var(--mono); font-size: 11px; color: var(--fg-dim); letter-spacing: 0.15em; text-transform: uppercase; margin-bottom: 10px; }
.toc ol { padding-right: 18px; margin: 0; }
.toc a { color: var(--fg-muted); border: none; }
.toc a:hover { color: var(--acid); }

/* ============================================================ FOOTER */
.foot { border-top: 1px solid var(--line); margin-top: 60px; padding: 28px 64px; font-family: var(--mono); font-size: 11px; color: var(--fg-dim); letter-spacing: 0.08em; text-transform: uppercase; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 16px; background: var(--bg-void); }
.foot .sig { color: var(--acid); }

/* ============================================================ RESPONSIVE */
@media (max-width: 1000px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; top: 0; }
  .main { padding: 40px 22px 80px; }
  .hero { padding: 56px 22px 40px; }
  .foot { padding: 28px 22px; }
  .pager { grid-template-columns: 1fr; }
}

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