:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1a1d23;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #4338ca;
  --accent-soft: #e0e7ff;
  --brand: linear-gradient(135deg, #6d28d9, #0f766e);
  --ticker-bg: #1a1d23;
  --ticker-text: #ffffff;
  --games: #6d28d9;
  --games-soft: #ede9fe;
  --cyber: #0f766e;
  --cyber-soft: #ccfbf1;
  --code: #1d4ed8;
  --law: #b45309;
  --law-soft: #fef3c7;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #181b22;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --border: #2a2e37;
  --accent: #a5b4fc;
  --accent-soft: #1e2350;
  --ticker-bg: #232733;
  --ticker-text: #e8eaed;
  --games: #c4b5fd;
  --games-soft: #2e1f4d;
  --cyber: #5eead4;
  --cyber-soft: #123833;
  --code: #93c5fd;
  --law: #fbbf24;
  --law-soft: #3a2e12;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "IBM Plex Sans Arabic", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  transition: background 0.2s, color 0.2s;
}

a { color: inherit; text-decoration: none; }
html { scroll-behavior: smooth; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .ticker-content { animation: none; }
}

.container { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

/* Header */
.site-header {
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.site-header::after { content: ""; position: absolute; inset-inline: 0; bottom: 0; height: 3px; background: var(--brand); }
.header-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 40px; height: 40px; display: block; flex-shrink: 0; }
.brand h1 { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.today { color: var(--muted); font-size: 0.85rem; }
.header-actions { display: flex; gap: 8px; }

.btn {
  font-family: inherit;
  font-size: 0.95rem;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn:hover { opacity: 0.88; }
.btn:disabled { opacity: 0.5; cursor: wait; }
.btn.icon { background: var(--bg); color: var(--text); border: 1px solid var(--border); }

/* Ticker */
.ticker { background: var(--ticker-bg); color: var(--ticker-text); overflow: hidden; }
.ticker-row { display: flex; align-items: center; gap: 12px; padding: 8px 16px; }
.ticker-label {
  background: var(--brand);
  color: #fff;
  padding: 2px 10px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.ticker-track { overflow: hidden; flex: 1; }
/* المحتوى مكرر مرتين، فتحريكه بمقدار نصف عرضه يجعل الشريط يدور بلا انقطاع */
.ticker-content {
  display: inline-block;
  white-space: nowrap;
  animation: scroll 90s linear infinite;
  font-size: 0.9rem;
}
.ticker-content a { margin-inline-end: 40px; }
.ticker-content a::before { content: "● "; color: #a78bfa; }
.ticker-track:hover .ticker-content { animation-play-state: paused; }
@keyframes scroll {
  from { transform: translateX(0); }
  to { transform: translateX(50%); }
}

/* Toolbar */
.toolbar { margin: 20px 0; }
.tabs { display: flex; gap: 20px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.tab {
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 500;
  background: none;
  color: var(--muted);
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  padding: 6px 2px 8px;
  cursor: pointer;
}
.tab.active { color: var(--text); font-weight: 700; border-image: var(--brand) 1; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  font-family: inherit;
  font-size: 0.85rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 14px;
  cursor: pointer;
}
.chip.active { background: var(--brand); border-color: transparent; color: #fff; }
.chip .count { opacity: 0.7; font-size: 0.8em; }
.toolbar-row { display: flex; gap: 8px; }
.toolbar input, .toolbar select {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
.toolbar input { flex: 1; min-width: 0; }
.status { color: var(--muted); font-size: 0.85rem; margin-top: 8px; }

/* Hero */
.hero { margin-bottom: 24px; }
.hero-card {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  background: var(--surface);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.hero-card img { width: 100%; height: 100%; min-height: 280px; object-fit: cover; display: block; }
.hero-body { padding: 24px; display: flex; flex-direction: column; justify-content: center; gap: 10px; }
.hero-body h2 { font-size: 1.6rem; line-height: 1.4; }
.hero-body p { color: var(--muted); }

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
  margin-bottom: 40px;
}
.card {
  background: var(--surface);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transition: transform 0.15s;
}
.card:hover { transform: translateY(-3px); box-shadow: 0 10px 28px rgba(0, 0, 0, 0.1); }
.card img, .thumb-placeholder { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; display: block; background: var(--border); }
.thumb-placeholder { display: grid; place-items: center; font-size: 2.2rem; color: var(--muted); }
.card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card h3 { font-size: 1.05rem; line-height: 1.5; }
.card p { color: var(--muted); font-size: 0.9rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.meta { display: flex; justify-content: space-between; align-items: center; font-size: 0.8rem; color: var(--muted); margin-top: auto; gap: 8px; }
.source-tag { background: var(--bg); color: var(--muted); border: 1px solid var(--border); padding: 1px 10px; border-radius: 999px; font-weight: 500; white-space: nowrap; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.hero-body .tags { align-self: flex-start; }
.cat-tag { padding: 2px 10px; border-radius: 999px; font-weight: 500; white-space: nowrap; }
.cat-games { background: var(--games-soft); color: var(--games); }
.cat-cyber { background: var(--cyber-soft); color: var(--cyber); }

/* صورة بديلة للأخبار التي بلا صورة، بلون القسم */
.ph-games { background: linear-gradient(135deg, #3b0f7a, #7c3aed); }
.ph-cyber { background: linear-gradient(135deg, #053b33, #0d9488); }
.hero-card .thumb-placeholder { aspect-ratio: auto; min-height: 280px; height: 100%; font-size: 4.5rem; }

/* Skeleton */
.skeleton { background: var(--surface); border-radius: 12px; height: 300px; position: relative; overflow: hidden; }
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer { from { transform: translateX(100%); } to { transform: translateX(-100%); } }

.empty { text-align: center; color: var(--muted); padding: 40px 0; }

.site-footer { background: var(--surface); border-top: 1px solid var(--border); margin-top: 24px; padding: 28px 0 20px; color: var(--muted); font-size: 0.88rem; }
.footer-grid { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; }
.footer-brand { display: flex; align-items: center; gap: 12px; }
.footer-brand img { width: 36px; height: 36px; flex-shrink: 0; }
.footer-brand strong { color: var(--text); font-size: 1rem; }
.footer-brand p { max-width: 380px; }
.footer-links { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.footer-links a { color: var(--text); font-weight: 500; }
.footer-links a:hover { color: var(--accent); }
.footer-note { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); font-size: 0.8rem; text-align: center; }

/* صفحات نصية مثل سياسة الخصوصية */
.page { max-width: 760px; margin: 32px auto 48px; background: var(--surface); padding: 28px 24px; border-radius: 14px; box-shadow: var(--shadow); }
.page h2 { font-size: 1.6rem; }
.page h3 { font-size: 1.15rem; margin: 24px 0 8px; }
.page ul { padding-inline-start: 22px; display: grid; gap: 6px; }
.page a { color: var(--accent); text-decoration: underline; }
.page .btn { text-decoration: none; color: #fff; }
.page .btn.icon { color: var(--text); }
.page .updated { color: var(--muted); font-size: 0.9rem; margin-bottom: 16px; }
/* حتى لا يختفي العنوان تحت الهيدر الثابت عند فتح رابط مثل /about#contact */
.page [id] { scroll-margin-top: 130px; }

@media (max-width: 720px) {
  /* أزرار المصادر في سطر واحد يُسحب أفقياً بدل عدة أسطر */
  .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-inline: -16px; padding-inline: 16px; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex-shrink: 0; }
  .hero-card { grid-template-columns: 1fr; }
  .hero-card .thumb-placeholder { min-height: 200px; }
  .hero-card img { min-height: 200px; max-height: 240px; }
  .hero-body h2 { font-size: 1.25rem; }
  .brand h1 { font-size: 1.2rem; }
  .btn { padding: 7px 10px; }
}

/* روابط التنقل بين الصفحات (تحت الهيدر) */
.site-nav { display: flex; gap: 8px; padding-bottom: 10px; overflow-x: auto; scrollbar-width: none; }
.site-nav::-webkit-scrollbar { display: none; }
.site-nav a { padding: 5px 14px; border-radius: 999px; color: var(--muted); font-weight: 500; font-size: 0.92rem; white-space: nowrap; }
.site-nav a:hover { color: var(--text); background: var(--bg); }
.site-nav a.active { color: var(--accent); background: var(--accent-soft); }

/* رسالة إخلاء المسؤولية في منتصف الشاشة */
.disclaimer {
  margin: auto;
  border: none;
  border-radius: 16px;
  padding: 0;
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
.disclaimer::backdrop { background: rgba(10, 12, 16, 0.6); backdrop-filter: blur(3px); }
.disclaimer-body { padding: 24px; }
.disclaimer-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.disclaimer-head img { width: 44px; height: 44px; }
.disclaimer h2 { font-size: 1.35rem; }
.disclaimer ul { padding-inline-start: 20px; display: grid; gap: 8px; font-size: 0.95rem; }
.disclaimer-foot { color: var(--muted); font-size: 0.9rem; margin-top: 14px; }
.disclaimer a { color: var(--accent); text-decoration: underline; }
.disclaimer .btn { width: 100%; margin-top: 18px; padding: 11px; font-size: 1rem; }

/* صفحة التعلّم */
.learn-hero { margin: 28px 0 8px; }
.learn-hero h2 { font-size: 1.9rem; line-height: 1.4; }
.learn-hero > p { color: var(--muted); margin-top: 6px; max-width: 720px; }
.toc { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-top: 20px; }
.toc a {
  display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 14px; row-gap: 2px;
  background: var(--surface); border-radius: 14px; padding: 14px 18px; box-shadow: var(--shadow);
  border-top: 4px solid var(--accent); transition: transform 0.15s;
}
.toc a:hover { transform: translateY(-3px); }
.toc .toc-icon { font-size: 2rem; grid-row: span 2; }
.toc strong { font-size: 1.1rem; }
.toc span:last-child { color: var(--muted); font-size: 0.9rem; }
.toc .t-code { border-top-color: var(--code); }
.toc .t-cyber { border-top-color: var(--cyber); }
.toc .t-law { border-top-color: var(--law); }

.lesson { background: var(--surface); border-radius: 16px; padding: 26px 24px; margin: 22px 0; box-shadow: var(--shadow); scroll-margin-top: 130px; }
.lesson h2 { font-size: 1.5rem; margin-bottom: 8px; }
.lesson h3 { font-size: 1.15rem; margin: 24px 0 10px; }
.lesson p, .lesson li, .lesson dd { line-height: 1.9; }
.lesson ul, .lesson ol { padding-inline-start: 22px; display: grid; gap: 6px; }
.lesson a { color: var(--accent); text-decoration: underline; }

.steps { list-style: none; counter-reset: step; padding-inline-start: 0 !important; }
.steps li { counter-increment: step; position: relative; padding-inline-start: 40px; }
.steps li::before {
  content: counter(step);
  position: absolute; inset-inline-start: 0; top: 2px;
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 0.9rem;
}
.checklist { list-style: none; padding-inline-start: 0 !important; }
.checklist li { position: relative; padding-inline-start: 28px; }
.checklist li::before { content: "✔"; position: absolute; inset-inline-start: 0; color: var(--cyber); font-weight: 700; }

.code { background: #0d1117; color: #e6edf3; padding: 16px; border-radius: 10px; overflow-x: auto; font-family: Consolas, "Courier New", monospace; font-size: 0.9rem; line-height: 1.6; text-align: left; margin: 10px 0; }
.pillars { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.pillars div { background: var(--bg); border-radius: 12px; padding: 14px 16px; }
.pillars p { color: var(--muted); font-size: 0.95rem; }
.threats dt { font-weight: 700; margin-top: 12px; }
.threats dd { color: var(--muted); }
.callout { background: var(--law-soft); border-inline-start: 4px solid var(--law); padding: 14px 16px; border-radius: 10px; margin: 14px 0; line-height: 1.9; }
.law-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; margin: 12px 0 16px; }
.law-card { background: var(--bg); border-radius: 12px; padding: 14px 16px; border-top: 3px solid var(--law); }
.law-card h4 { font-size: 1.05rem; }
.law-card .penalty { color: var(--law); font-weight: 700; margin: 4px 0 6px; line-height: 1.6; }
.law-card p:last-child { color: var(--muted); font-size: 0.93rem; line-height: 1.8; }
.note { color: var(--muted); font-size: 0.9rem; }

@media (max-width: 720px) {
  /* مساحة تحت الفوتر حتى لا يغطيه زر الرجوع للأعلى وشارة Netlify */
  .site-footer { padding-bottom: 84px; }
  .learn-hero h2 { font-size: 1.5rem; }
  .lesson { padding: 20px 16px; }
}

/* زر الرجوع لأعلى الصفحة */
.to-top {
  position: fixed; bottom: 18px; inset-inline-end: 18px; z-index: 20;
  width: 44px; height: 44px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--brand); color: #fff; font-size: 1.2rem; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  opacity: 0; transform: translateY(10px); pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
.to-top.show { opacity: 1; transform: none; pointer-events: auto; }

/* شريط فوق الكود فيه اسم اللغة وزر النسخ */
.code-block { margin: 10px 0; border-radius: 10px; overflow: hidden; background: #0d1117; }
.code-bar { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; background: #161b22; color: #8b949e; font-size: 0.8rem; direction: ltr; }
.code-bar button { font-family: inherit; font-size: 0.8rem; background: #21262d; color: #e6edf3; border: 1px solid #30363d; border-radius: 6px; padding: 2px 12px; cursor: pointer; }
.code-block .code { margin: 0; border-radius: 0; }

/* النسخة الإنجليزية (من اليسار لليمين): الشريط يتحرك لليسار */
[dir="ltr"] .ticker-content { animation-name: scroll-ltr; }
@keyframes scroll-ltr {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

/* رابط تبديل اللغة في آخر شريط الروابط */
.site-nav .lang-link { margin-inline-start: auto; border: 1px solid var(--border); }
@media (max-width: 720px) {
  .nav-long { display: none; }
}

/* تمارين كتابة الكود في صفحة التعلّم: الكود ومربع الكتابة متقابلان */
:root { --ok: #15803d; --bad: #dc2626; }
[data-theme="dark"] { --ok: #4ade80; --bad: #f87171; }
.exercises { display: grid; gap: 16px; margin: 12px 0 8px; }
.exercise { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.exercise-head { display: grid; gap: 2px; margin-bottom: 10px; }
.exercise-head span { color: var(--muted); font-size: 0.92rem; line-height: 1.7; }
.exercise-body { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.exercise .code { margin: 0; }
.exercise-input {
  width: 100%;
  min-height: 100px;
  padding: 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  text-align: left;
  resize: vertical;
  tab-size: 4;
}
.exercise-input:focus { outline: none; border-color: var(--accent); }
.exercise-input.is-correct { border-color: var(--ok); }
.exercise-input.is-wrong { border-color: var(--bad); }
.exercise-output { display: flex; align-items: flex-start; gap: 8px; margin-top: 8px; color: var(--muted); font-size: 0.85rem; }
.exercise-output pre { font-family: Consolas, "Courier New", monospace; color: var(--text); text-align: left; }
.exercise-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-top: 10px; }
.exercise-result { font-weight: 700; }
.exercise-result.ok { color: var(--ok); }
.exercise-result.bad { color: var(--bad); }
@media (max-width: 720px) {
  .exercise-body { grid-template-columns: 1fr; }
}

/* كود التمارين لا يمكن تحديده أو نسخه */
.exercise .code { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }

/* كود داخل النص (مثل الأوامر وعناوين IP) */
.lesson :not(pre) > code {
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.88em;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
  unicode-bidi: isolate;
}

/* مراحل سلسلة الهجوم: كل مرحلة ومعها طريقة الدفاع */
.kill-chain .defense { display: block; color: var(--muted); font-size: 0.92rem; margin-top: 2px; }

/* تحديات الاختيار في تحليل الشبكة */
.quizzes { display: grid; gap: 16px; margin: 12px 0 8px; }
.quiz { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.quiz-q { margin-bottom: 10px; }
.quiz-options { display: grid; gap: 8px; }
.quiz-option {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); cursor: pointer; line-height: 1.8;
}
.quiz-option input { margin-top: 7px; accent-color: #6d28d9; flex-shrink: 0; }
.quiz-option:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.quiz-explain { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--surface); border-inline-start: 4px solid var(--ok); line-height: 1.9; }

/* بطاقة التعليم الخاص (رابط تيليجرام): العنوان فوق الزر، وإطار بتدرج ألوان الشعار */
.cta-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  margin-top: 16px;
  padding: 16px 18px;
  border-radius: 14px;
  border: 2px solid transparent;
  background: linear-gradient(var(--surface), var(--surface)) padding-box, var(--brand) border-box;
  box-shadow: var(--shadow);
}
.cta-title { font-size: 1.1rem; }
.cta-btn { display: inline-block; padding: 9px 18px; }

/* صفحة "غير موجودة" */
.not-found { text-align: center; margin-top: 32px; }
.not-found .redirect-note { color: var(--muted); margin-top: 10px; }
.not-found .redirect-note strong { color: var(--accent); }
.not-found img { margin: 0 auto 12px; display: block; }
.not-found .not-found-links { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin: 18px 0; }
