/* ============================================================
   الستاك الكامل — Data-Path / Trace Board design system
   الثيم: لوحة تتبّع البيانات. حبر أزرق عميق + شبكة مخطّطات +
   سماوي مائي مهيمن (إشارة) + أزرق فولتي ثانوي. داكن دائماً.
   ============================================================ */

:root {
  /* surfaces — حبر أزرق عميق بارد (لوحة هندسية) */
  --bg-void: #04080d;
  --bg-deep: #06101a;
  --bg-panel: #0a1622;
  --bg-elevated: #0f2030;
  --bg-code: #061018;

  /* borders / lines */
  --line: #15293a;
  --line-strong: #244055;
  --line-faint: #0e1d2a;

  /* text */
  --fg: #d6e4f0;
  --fg-muted: #8aa2b6;
  --fg-dim: #587184;
  --fg-faint: #3a4f5f;

  /* accents — السماوي المائي مهيمن (تدفّق البيانات) */
  --acid: #2ee6dc;        /* dominant: flow/signal */
  --acid-dim: #137d78;
  --cyan: #5a9bff;        /* secondary: volt blue */
  --cyan-dim: #2f5699;
  --amber: #ffb454;       /* warn */
  --amber-dim: #8a5e1a;
  --red: #ff4d6a;         /* danger */
  --red-dim: #8a2238;
  --ok: #3ddc84;          /* success / pass */
  --ok-dim: #1c7a48;
  --magenta: #b98cff;     /* code keyword */

  /* 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;
}

/* schematic grid + signal glows */
body {
  background-image:
    linear-gradient(rgba(46, 230, 220, 0.020) 1px, transparent 1px),
    linear-gradient(90deg, rgba(46, 230, 220, 0.020) 1px, transparent 1px),
    radial-gradient(ellipse at 15% 0%, rgba(90, 155, 255, 0.06) 0%, transparent 55%),
    radial-gradient(ellipse at 85% 90%, rgba(46, 230, 220, 0.05) 0%, transparent 55%);
  background-size: 34px 34px, 34px 34px, 100% 100%, 100% 100%;
  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); }

/* ============================================================ 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: "›_"; color: var(--acid);
  animation: blink 1.4s steps(2, end) infinite;
}
.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 1.8s ease-in-out infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.4; transform: scale(0.7); } }

/* sidebar */
.sidebar {
  position: sticky; top: 39px; height: calc(100vh - 39px); overflow-y: auto;
  background: var(--bg-deep); border-left: 1px solid var(--line);
  padding: 28px 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; border-radius: 0; 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 .cheat {
  font-family: var(--mono); font-size: 11px; color: var(--fg-dim);
  padding: 4px 10px; line-height: 1.95;
}
.sidebar .cheat b { color: var(--acid); font-weight: 500; }
.sidebar .cheat i { color: var(--amber); font-style: normal; }

/* main */
.main { padding: 52px 64px 120px; max-width: 1080px; 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(32px, 4vw, 48px); margin: 0 0 12px; letter-spacing: -0.01em; }
h1 .accent { color: var(--acid); }

h2 {
  font-size: 28px; margin: 60px 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(46, 230, 220, 0.06); border: 1px solid var(--acid-dim);
  letter-spacing: 0.05em; vertical-align: middle;
}
h3 { font-size: 21px; margin: 38px 0 12px; color: var(--cyan); }
h3::before { content: "// "; font-family: var(--mono); color: var(--fg-dim); font-weight: 400; }
h4 { font-size: 16px; margin: 26px 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: 24px; margin: 0 0 18px; }
li { margin-bottom: 9px; }
li::marker { color: var(--acid); }

hr { border: none; border-top: 1px solid var(--line); margin: 34px 0; }

.partbreak { display: flex; align-items: center; gap: 16px; margin: 56px 0 8px; font-family: var(--mono); }
.partbreak::before, .partbreak::after { content: ""; flex: 1; border-top: 1px solid var(--line-strong); }
.partbreak span { color: var(--cyan); font-size: 15px; letter-spacing: 0.04em; font-weight: 500; padding: 4px 14px; border: 1px solid var(--cyan-dim); background: var(--bg-panel); white-space: nowrap; }

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

/* ============================================================ HERO (index) */
.hero { padding: 80px 64px 56px; border-bottom: 1px solid var(--line); position: relative; overflow: hidden; }
.hero::before {
  content: ""; position: absolute; inset: 0;
  background:
    radial-gradient(circle at 18% 28%, rgba(46, 230, 220, 0.10) 0%, transparent 42%),
    radial-gradient(circle at 82% 72%, rgba(90, 155, 255, 0.08) 0%, transparent 42%);
  pointer-events: none;
}
.hero > * { position: relative; }
.hero-meta { display: flex; gap: 14px; margin-bottom: 22px; 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.cls { color: var(--cyan); border-color: var(--cyan-dim); }
.hero h1 { font-size: clamp(38px, 5.2vw, 68px); font-weight: 800; line-height: 1.06; margin: 0 0 16px; }
.hero h1 .accent { color: var(--acid); }
.hero .lede { font-size: 19px; color: var(--fg-muted); max-width: 800px; line-height: 1.7; }

/* animated flow divider under hero */
.flowline { height: 2px; margin: 28px 0 0; background:
  linear-gradient(90deg, transparent, var(--acid-dim) 20%, var(--acid) 50%, var(--cyan) 70%, transparent);
  background-size: 200% 100%; animation: flow 5s linear infinite; opacity: 0.7; }
@keyframes flow { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .flowline { animation: none; } .topbar .brand::before, .topbar .status::before { animation: none; } }

/* page-head (region pages) */
.page-head { margin-bottom: 8px; }
.page-head .hero-meta { margin-bottom: 16px; }

/* ============================================================ 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; }

/* meta panel (يبني فوق / يفتح) */
.panel.meta { background: var(--bg-deep); border-right: 3px solid var(--cyan); font-size: 14px; color: var(--fg-muted); padding: 16px 22px; }
.panel.meta p { margin: 0 0 6px; }
.panel.meta p:last-child { margin-bottom: 0; }

.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); position: relative;
}
.callout.warn { border-right-color: var(--amber); }
.callout.danger { border-right-color: var(--red); }
.callout.info { border-right-color: var(--cyan); }
.callout.seed { border-right-color: var(--ok); background: linear-gradient(90deg, rgba(61,220,132,0.04), transparent 60%), var(--bg-panel); }
.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.seed .label { color: var(--ok); }
.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.04em; text-align: right; padding: 12px 16px; border-bottom: 1px solid var(--line-strong); }
td { padding: 11px 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(46, 230, 220, 0.02); }

/* ============================================================ 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: 13px; line-height: 1.7; 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: 16px 20px; background: transparent; border: none; color: var(--fg); white-space: pre; overflow-x: auto; direction: ltr; text-align: left; font-size: 13px; }

/* ascii diagrams */
.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); }

/* ============================================================ BOX (puzzles) */
.box { margin: 28px 0; border: 1px solid var(--line); background: var(--bg-panel); padding: 22px 26px; 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::before { color: var(--amber); }
.box.amber { border-color: var(--amber-dim); background: linear-gradient(180deg, rgba(255,180,84,0.03), transparent 30%), var(--bg-panel); }
.box ol, .box ul { margin-bottom: 0; }
.box h3:first-child, .box h4:first-child, .box p:first-child { margin-top: 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.pass { color: var(--ok); border-color: var(--ok-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); }

/* ============================================================ MODULE GRID (index) */
.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; right: 0; width: 64px; height: 64px; background: linear-gradient(225deg, var(--acid-dim) 0%, transparent 50%); opacity: 0.16; }
.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 .mc-seed { font-size: 12.5px; color: var(--fg-dim); font-style: italic; line-height: 1.6; margin-bottom: 14px; border-right: 2px solid var(--line-strong); padding-right: 10px; }

/* ============================================================ 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: 12.5px; color: var(--fg-dim); font-style: italic; margin-top: 6px; line-height: 1.55; }
.pager .next { text-align: left; grid-column: 2; }
.pager .prev { grid-column: 1; }
.pager .next .label::before { content: "→ "; }
.pager .prev .label::after { content: " ←"; }

/* ============================================================ TOC */
.toc { background: var(--bg-panel); border: 1px solid var(--line); padding: 18px 26px; margin: 24px 0 32px; font-size: 14px; }
.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: 64px; padding: 28px 0; 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; }
.foot .sig { color: var(--acid); }

/* ============================================================ RESPONSIVE */
@media (max-width: 1000px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; top: 0; border-left: none; border-bottom: 1px solid var(--line); }
  .main { padding: 36px 22px 80px; }
  .hero { padding: 56px 22px 36px; }
  .pager { grid-template-columns: 1fr; }
  .pager .next, .pager .prev { grid-column: 1; }
}
