/* =====================================================================
   خريطة طريق أندرويد 2026 — الأنماط
   نظام رموز: أخضر مزرق عميق (teal) كلون أساسي، صدئي دافئ للتوكيد،
   محايدات مائلة للأخضر. النظام مستوحى من Material 3 tonal palettes.
   ===================================================================== */

:root {
  /* --- الألوان: الوضع الفاتح --- */
  --bg:            #EFF2EE;
  --bg-tint:       #E4EAE4;
  --surface:       #FAFCF9;
  --surface-2:     #F0F4EF;
  --ink:           #131E1D;
  --ink-2:         #3A4947;
  --muted:         #64756F;
  --line:          #D3DBD5;
  --line-strong:   #B7C3BC;

  --primary:       #00696E;
  --primary-ink:   #FFFFFF;
  --primary-soft:  #CFE9E9;
  --accent:        #A6491A;
  --accent-soft:   #F6DECF;
  --good:          #3B7A2E;
  --good-soft:     #D6EBCE;
  --warn:          #8A6100;

  --code-bg:       #10201F;
  --code-ink:      #DCE7E2;

  /* --- الخطوط --- */
  --font-ar: "SF Arabic", "Geeza Pro", "Segoe UI", "Noto Naskh Arabic",
             "Noto Sans Arabic", "Dubai", Tahoma, system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code",
               Menlo, Consolas, monospace;

  /* --- المقاييس --- */
  --step--1: clamp(0.80rem, 0.78rem + 0.10vw, 0.86rem);
  --step-0:  clamp(0.98rem, 0.95rem + 0.15vw, 1.06rem);
  --step-1:  clamp(1.14rem, 1.08rem + 0.30vw, 1.32rem);
  --step-2:  clamp(1.36rem, 1.26rem + 0.50vw, 1.70rem);
  --step-3:  clamp(1.70rem, 1.50rem + 1.00vw, 2.40rem);
  --step-4:  clamp(2.10rem, 1.70rem + 2.00vw, 3.40rem);

  --rail: 21rem;
  --radius: 10px;
  --radius-lg: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #0C1514;
    --bg-tint:     #101B1A;
    --surface:     #14201F;
    --surface-2:   #1A2726;
    --ink:         #E3ECE8;
    --ink-2:       #C1CFCA;
    --muted:       #8CA09A;
    --line:        #253433;
    --line-strong: #354644;

    --primary:      #62D4DA;
    --primary-ink:  #003739;
    --primary-soft: #1B3D3F;
    --accent:       #F2A97A;
    --accent-soft:  #3D2416;
    --good:         #8CD07B;
    --good-soft:    #1F3419;
    --warn:         #E0BC5F;

    --code-bg:      #0A1413;
    --code-ink:     #D5E3DD;
  }
}

/* التبديل اليدوي لازم يغلب استعلام الوسائط في الاتجاهين */
:root[data-theme="dark"] {
  --bg:          #0C1514;
  --bg-tint:     #101B1A;
  --surface:     #14201F;
  --surface-2:   #1A2726;
  --ink:         #E3ECE8;
  --ink-2:       #C1CFCA;
  --muted:       #8CA09A;
  --line:        #253433;
  --line-strong: #354644;
  --primary:      #62D4DA;
  --primary-ink:  #003739;
  --primary-soft: #1B3D3F;
  --accent:       #F2A97A;
  --accent-soft:  #3D2416;
  --good:         #8CD07B;
  --good-soft:    #1F3419;
  --warn:         #E0BC5F;
  --code-bg:      #0A1413;
  --code-ink:     #D5E3DD;
}

:root[data-theme="light"] {
  --bg:            #EFF2EE;
  --bg-tint:       #E4EAE4;
  --surface:       #FAFCF9;
  --surface-2:     #F0F4EF;
  --ink:           #131E1D;
  --ink-2:         #3A4947;
  --muted:         #64756F;
  --line:          #D3DBD5;
  --line-strong:   #B7C3BC;
  --primary:       #00696E;
  --primary-ink:   #FFFFFF;
  --primary-soft:  #CFE9E9;
  --accent:        #A6491A;
  --accent-soft:   #F6DECF;
  --good:          #3B7A2E;
  --good-soft:     #D6EBCE;
  --warn:          #8A6100;
  --code-bg:       #10201F;
  --code-ink:      #DCE7E2;
}

/* ===================== الأساسيات ===================== */

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ar);
  font-size: var(--step-0);
  line-height: 1.85;
  -webkit-font-smoothing: antialiased;
}

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

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

code, kbd, pre { font-family: var(--font-mono); direction: ltr; unicode-bidi: embed; }

p > code, li > code, td > code, .note code, summary code {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0.05em 0.38em;
  font-size: 0.86em;
  display: inline-block;
  line-height: 1.5;
}

::selection { background: var(--primary); color: var(--primary-ink); }

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

/* ===================== التخطيط ===================== */

.shell {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  gap: 0;
  min-height: 100vh;
}

/* ------- الشريط الجانبي (الخريطة) ------- */

.rail {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg-tint);
  border-inline-end: 1px solid var(--line);
  padding: 1.6rem 1.3rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.brand { display: flex; flex-direction: column; gap: 0.35rem; }

.brand-mark {
  font-size: var(--step--1);
  letter-spacing: 0.14em;
  color: var(--accent);
  font-weight: 700;
}

.brand-title {
  font-size: var(--step-1);
  font-weight: 800;
  line-height: 1.35;
  margin: 0;
  text-wrap: balance;
}

/* شريط التقدّم */
.progress-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.progress-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: var(--step--1);
  color: var(--muted);
}

.progress-head b {
  color: var(--ink);
  font-size: var(--step-1);
  font-variant-numeric: tabular-nums;
}

.progress-track {
  height: 6px;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
  transition: width 0.35s ease;
}

/* البحث */
.search {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: var(--step--1);
}
.search::placeholder { color: var(--muted); }

/* المراحل */
.route-groups { display: flex; flex-direction: column; gap: 0.3rem; }

.phase-head {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  font-weight: 700;
  color: var(--accent);
  margin: 0.9rem 0 0.15rem;
  padding-inline-start: 0.4rem;
}
.phase-head:first-child { margin-top: 0; }

/* قائمة المحطات — طريق فعلي */
.route { list-style: none; margin: 0; padding: 0; position: relative; }

.route::before {
  content: "";
  position: absolute;
  inset-inline-start: 13px;
  top: 14px;
  bottom: 14px;
  width: 2px;
  background: var(--line);
}

.route-item { position: relative; }

.route-link {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 0.65rem;
  align-items: start;
  padding: 0.42rem 0.4rem;
  border-radius: 8px;
  text-decoration: none;
  color: var(--ink-2);
  transition: background 0.15s ease;
}

.route-link:hover { background: var(--surface); }

.route-link[aria-current="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line);
}

.route-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--bg-tint);
  border: 2px solid var(--line-strong);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  position: relative;
  z-index: 1;
  flex: none;
}

.route-link[aria-current="true"] .route-dot {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--surface);
}

.route-item.done .route-dot {
  background: var(--good);
  border-color: var(--good);
  color: #fff;
}

.route-text { min-width: 0; }
.route-name { display: block; font-weight: 600; font-size: 0.94rem; line-height: 1.5; }
.route-meta { display: block; font-size: 0.76rem; color: var(--muted); }

.rail-foot {
  margin-top: auto;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.btn-ghost {
  font: inherit;
  font-size: var(--step--1);
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-2);
  border-radius: 8px;
  cursor: pointer;
}
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }

/* ------- المحتوى ------- */

.main { min-width: 0; padding: 0 0 6rem; }

.wrap { max-width: 78ch; margin-inline: auto; padding-inline: clamp(1rem, 4vw, 3rem); }

/* الافتتاحية */
.hero {
  padding: clamp(3rem, 9vh, 6rem) 0 clamp(2rem, 5vh, 3.5rem);
  border-bottom: 1px solid var(--line);
}

.hero-eyebrow {
  font-size: var(--step--1);
  letter-spacing: 0.16em;
  color: var(--accent);
  font-weight: 700;
  margin: 0 0 0.9rem;
}

.hero h1 {
  font-size: var(--step-4);
  line-height: 1.2;
  font-weight: 800;
  margin: 0 0 0.5rem;
  text-wrap: balance;
  letter-spacing: -0.01em;
}

.hero-sub {
  font-size: var(--step-1);
  color: var(--ink-2);
  margin: 0 0 1.6rem;
  text-wrap: balance;
}

.hero-intro { color: var(--ink-2); max-width: 60ch; }

.hero-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0 2.5rem;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}

.stat b {
  display: block;
  font-size: var(--step-2);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
}
.stat span { font-size: var(--step--1); color: var(--muted); }

/* بطاقة المحطة */
.module { padding: clamp(2.5rem, 7vh, 4.5rem) 0; border-bottom: 1px solid var(--line); }

.module-head { margin-bottom: 2rem; }

.module-index {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-bottom: 0.7rem;
  font-size: var(--step--1);
}

.module-num {
  background: var(--primary);
  color: var(--primary-ink);
  border-radius: 6px;
  padding: 0.1rem 0.55rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.chip {
  border: 1px solid var(--line-strong);
  color: var(--muted);
  border-radius: 99px;
  padding: 0.05rem 0.6rem;
  font-size: 0.78rem;
}

.chip-live { border-color: var(--accent); color: var(--accent); }

.module h2 {
  font-size: var(--step-3);
  font-weight: 800;
  margin: 0 0 0.25rem;
  line-height: 1.3;
  text-wrap: balance;
}

.module-sub { color: var(--muted); margin: 0 0 1.4rem; font-size: var(--step-1); }

.why {
  background: var(--surface);
  border: 1px solid var(--line);
  border-inline-start: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  color: var(--ink-2);
}
.why strong { color: var(--ink); }

.section { margin-top: 2.6rem; }

.section > h3 {
  font-size: var(--step-1);
  font-weight: 700;
  margin: 0 0 0.7rem;
  line-height: 1.5;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.section > h3::before {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  background: var(--primary);
  border-radius: 2px;
  flex: none;
  transform: rotate(45deg);
}

.prose p { margin: 0 0 0.9rem; }
.prose ul, .prose ol { margin: 0 0 0.9rem; padding-inline-start: 1.4rem; }
.prose li { margin-bottom: 0.4rem; }
.prose s { color: var(--muted); }

p.tip {
  background: var(--primary-soft);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  margin: 1.2rem 0;
  color: var(--ink);
}

/* ===================== الكود ===================== */

.codeblock {
  margin: 1.2rem 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface);
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0.9rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  font-size: var(--step--1);
}

.code-title { color: var(--ink-2); font-weight: 600; min-width: 0; }

.code-tools { display: flex; gap: 0.4rem; flex: none; }

.tool {
  font: inherit;
  font-size: 0.78rem;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
.tool:hover { color: var(--primary); border-color: var(--primary); }

.tool-run {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-ink);
  font-weight: 700;
}
.tool-run:hover { color: var(--primary-ink); filter: brightness(1.08); }

pre.code {
  margin: 0;
  padding: 1rem 1.1rem;
  background: var(--code-bg);
  color: var(--code-ink);
  overflow-x: auto;
  font-size: 0.84rem;
  line-height: 1.75;
  direction: ltr;
  text-align: left;
  tab-size: 4;
  /* كل سطر بياخد اتجاهه من أول حرف قوي فيه:
     سطور الكود تفضل LTR، والتعليقات العربية تتقرا من اليمين صح */
  unicode-bidi: plaintext;
}

/* النصوص العربية جوه الكود تتعزل عشان ما تلخبطش ترتيب السطر */
pre.code .t-str,
pre.code .t-com { unicode-bidi: isolate; }

pre.code[contenteditable="true"] { outline: none; caret-color: var(--accent); }
pre.code[contenteditable="true"]:focus { box-shadow: inset 0 0 0 2px var(--primary); }

/* تلوين نحوي */
.t-key  { color: #FF9E7A; }
.t-str  { color: #97D8A0; }
.t-com  { color: #6C8481; font-style: italic; }
.t-num  { color: #E4C88A; }
.t-ann  { color: #8FC6F2; }
.t-fn   { color: #9DDCE0; }

.code-out {
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  padding: 0.75rem 1.1rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.7;
  white-space: pre-wrap;
  color: var(--ink-2);
  direction: ltr;
  text-align: left;
  unicode-bidi: plaintext;   /* كل سطر مخرجات ياخد اتجاهه الصح */
}

.code-out[hidden] { display: none; }

.out-label {
  display: block;
  font-family: var(--font-ar);
  direction: rtl;
  text-align: right;
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.06em;
  margin-bottom: 0.35rem;
}

.note {
  padding: 0.7rem 1.1rem;
  border-top: 1px dashed var(--line);
  font-size: var(--step--1);
  color: var(--ink-2);
  background: var(--surface);
}
.note::before { content: "◆ "; color: var(--accent); }

.static-hint {
  padding: 0.5rem 1.1rem;
  border-top: 1px solid var(--line);
  font-size: 0.76rem;
  color: var(--muted);
  background: var(--surface);
}

/* حاوية Kotlin Playground */
.kt-mount { background: var(--code-bg); }
.kt-mount .executable-fragment-wrapper { direction: ltr; text-align: left; }

/* ===================== الجداول ===================== */

.table-wrap { overflow-x: auto; margin: 1.2rem 0; border: 1px solid var(--line); border-radius: var(--radius-lg); }

table { border-collapse: collapse; width: 100%; font-size: 0.92rem; background: var(--surface); }

thead th {
  background: var(--surface-2);
  text-align: start;
  font-weight: 700;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}

tbody td { padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
tbody td:first-child { font-weight: 600; }

/* ===================== شجرة الملفات ===================== */

.tree {
  margin: 1.2rem 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface);
}

.tree-row {
  display: grid;
  grid-template-columns: minmax(0, 22rem) minmax(0, 1fr);
  gap: 1rem;
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--line);
  align-items: center;
}
.tree-row:last-child { border-bottom: none; }
.tree-row.hot { background: var(--primary-soft); }

.tree-path {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  direction: ltr;
  text-align: left;
  overflow-x: auto;
  white-space: nowrap;
  color: var(--ink);
}
.tree-desc { font-size: var(--step--1); color: var(--muted); }

/* ===================== الطبقات ===================== */

.layers { display: flex; flex-direction: column; gap: 0.6rem; margin: 1.2rem 0; }

.layer {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: 0.9rem 1.1rem;
  position: relative;
}

.layer + .layer::before {
  content: "↓";
  position: absolute;
  top: -1.05rem;
  inset-inline-start: 1.4rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.layer-name { font-weight: 700; margin: 0 0 0.15rem; }
.layer-parts { font-size: var(--step--1); color: var(--primary); font-weight: 600; margin: 0 0 0.35rem; }
.layer-job { font-size: var(--step--1); color: var(--ink-2); margin: 0; }

/* ===================== الغلطات ===================== */

.pitfalls { display: flex; flex-direction: column; gap: 0.7rem; margin: 1.2rem 0; }

.pitfall {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface);
}

.pitfall-pair { display: grid; grid-template-columns: 1fr 1fr; }

.pitfall-side { padding: 0.65rem 0.9rem; font-size: var(--step--1); }
.pitfall-side.bad { background: var(--accent-soft); }
.pitfall-side.good { background: var(--good-soft); border-inline-start: 1px solid var(--line); }
.pitfall-side .lbl { display: block; font-size: 0.72rem; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 0.2rem; }

.pitfall-why { padding: 0.6rem 0.9rem; font-size: var(--step--1); color: var(--ink-2); border-top: 1px solid var(--line); }

/* ===================== المعاينة التفاعلية ===================== */

.preview {
  margin: 1.2rem 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface);
}

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0.9rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  font-size: var(--step--1);
  font-weight: 600;
}

.sim-badge {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 99px;
  padding: 0.05rem 0.5rem;
  flex: none;
}

.preview-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 15rem);
  gap: 0;
  align-items: stretch;
}

.preview-stage {
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  border-inline-end: 1px solid var(--line);
  min-width: 0;
}

.preview-panel {
  padding: 0.9rem;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  font-size: var(--step--1);
}

.panel-label { font-size: 0.72rem; letter-spacing: 0.08em; color: var(--muted); }

/* شاشة موبايل مصغّرة */
.phone {
  border: 2px solid var(--line-strong);
  border-radius: 18px;
  background: var(--bg);
  padding: 0.8rem;
  min-height: 8rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.m-btn {
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.42rem 1.1rem;
  border-radius: 99px;
  border: none;
  background: var(--primary);
  color: var(--primary-ink);
  cursor: pointer;
  align-self: flex-start;
}
.m-btn:hover { filter: brightness(1.08); }
.m-btn[disabled] { background: var(--line); color: var(--muted); cursor: not-allowed; }

.m-btn.outline {
  background: transparent;
  color: var(--primary);
  box-shadow: inset 0 0 0 1px var(--primary);
}

.m-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.55rem 0.8rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  font-size: 0.9rem;
}

.m-text { font-size: 0.95rem; }
.m-muted { color: var(--muted); font-size: 0.85rem; }

.m-x {
  font: inherit;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.1rem 0.35rem;
  border-radius: 6px;
}
.m-x:hover { color: var(--accent); background: var(--accent-soft); }

.counter-val {
  font-size: 2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.seg { display: flex; gap: 0.3rem; flex-wrap: wrap; }

.seg button {
  font: inherit;
  font-size: 0.8rem;
  padding: 0.25rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
}
.seg button[aria-pressed="true"] {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-ink);
  font-weight: 600;
}

.stack-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column-reverse; gap: 0.25rem; }
.stack-list li {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.2rem 0.5rem;
  font-size: 0.78rem;
  font-family: var(--font-mono);
  direction: ltr;
  text-align: left;
}
.stack-list li:last-child { border-color: var(--primary); color: var(--primary); font-weight: 700; }

.metric { display: flex; justify-content: space-between; align-items: baseline; }
.metric b { font-variant-numeric: tabular-nums; font-size: 1.1rem; }

.spinner {
  width: 1.6rem; height: 1.6rem;
  border: 3px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.demo-box {
  background: var(--primary);
  color: var(--primary-ink);
  border-radius: 8px;
  font-size: 0.85rem;
  display: inline-block;
}
.demo-outer { border: 1px dashed var(--line-strong); border-radius: 8px; display: inline-block; }

/* ---------- عناصر مشتركة في المعاينات ---------- */

.verdict {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-inline-start: 3px solid var(--primary);
  border-radius: 8px;
  padding: 0.55rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.88rem;
}
.verdict.bad { border-inline-start-color: var(--accent); background: var(--accent-soft); }
.verdict.ok  { border-inline-start-color: var(--good); background: var(--good-soft); }
.verdict strong { font-size: 0.95rem; }

.metric b.ok  { color: var(--good); }
.metric b.bad { color: var(--accent); }

.m-input {
  font: inherit;
  font-size: 0.92rem;
  width: 100%;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}
.m-input.invalid { border-color: var(--accent); border-width: 2px; }

.field { display: flex; flex-direction: column; gap: 0.2rem; }
.field-err { font-size: 0.78rem; color: var(--accent); min-height: 1.1rem; }

.m-range { width: 100%; accent-color: var(--primary); }

.chips { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.st-chip {
  font-size: 0.76rem;
  border: 1px solid var(--line-strong);
  border-radius: 99px;
  padding: 0.12rem 0.6rem;
  color: var(--muted);
  background: var(--surface);
}
.st-chip.on { border-color: var(--good); color: var(--good); background: var(--good-soft); }

/* ---------- خط أنابيب المجموعات ---------- */

.pipe-step { display: flex; flex-direction: column; gap: 0.25rem; }
.pipe-op {
  font-size: 0.76rem;
  color: var(--primary);
  direction: ltr;
  text-align: start;
}
.pipe-vals { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.pipe-chip {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  padding: 0.08rem 0.45rem;
  font-variant-numeric: tabular-nums;
}

/* ---------- مسارات الـ Dispatchers ---------- */

.lane { display: flex; flex-direction: column; gap: 0.2rem; }
.lane-name { font-family: var(--font-mono); font-size: 0.74rem; color: var(--muted); direction: ltr; text-align: start; }
.lane-track {
  min-height: 1.9rem;
  border: 1px dashed var(--line-strong);
  border-radius: 6px;
  padding: 0.2rem 0.35rem;
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  align-items: center;
}
.lane-job {
  font-size: 0.74rem;
  background: var(--primary);
  color: var(--primary-ink);
  border-radius: 5px;
  padding: 0.1rem 0.5rem;
  animation: pop 0.25s ease;
}
.lane-job.done { background: var(--good); }
@keyframes pop { from { transform: scale(0.7); opacity: 0; } }

/* ---------- الرسم الرخامي ---------- */

.marble-track { display: flex; flex-direction: column; gap: 0.25rem; }
.marble-title { font-size: 0.76rem; color: var(--muted); }
.marble-line {
  position: relative;
  height: 2.2rem;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.marble {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  padding: 0.1rem 0.4rem;
  border-radius: 99px;
  white-space: nowrap;
  direction: ltr;
}
.marble.src { background: var(--line-strong); color: var(--ink); }
.marble.out { background: var(--primary); color: var(--primary-ink); font-weight: 700; }
.marble-op { font-size: 0.78rem; color: var(--accent); direction: ltr; text-align: start; }

/* ---------- أثر الخطأ / سطور طرفية ---------- */

.phone.trace { font-family: var(--font-mono); gap: 0.1rem; }

.trace-line {
  font-size: 0.72rem;
  line-height: 1.7;
  direction: ltr;
  text-align: left;
  white-space: pre;
  overflow-x: auto;
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
  color: var(--ink-2);
}
.trace-line.head  { color: var(--accent); font-weight: 700; }
.trace-line.cause { color: var(--ink); font-weight: 700; }
.trace-line.dim   { color: var(--muted); opacity: 0.65; }
.trace-line.hit   { background: var(--accent-soft); color: var(--ink); font-weight: 700; }

.err-code {
  display: block;
  font-size: 0.72rem;
  line-height: 1.6;
  white-space: pre-wrap;
  direction: ltr;
  text-align: left;
  color: var(--accent);
}

/* ---------- سجل دورة الحياة ---------- */

.lifelog {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  max-height: 11rem;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
}
.lifelog-line {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  line-height: 1.7;
  unicode-bidi: plaintext;
  color: var(--ink-2);
}

/* ---------- الأنيميشن ---------- */

.curve-holder { color: var(--primary); }
.curve { width: 100%; height: 3.5rem; display: block; }

.anim-track {
  position: relative;
  height: 2.6rem;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.anim-box {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 0;
  width: 3.2rem;
  height: 1.7rem;
  border-radius: 6px;
}

/* ---------- الشاشات المتكيّفة ---------- */

.adaptive-stage { align-items: stretch; }

.adaptive-frame {
  border: 2px solid var(--line-strong);
  border-radius: 10px;
  overflow: hidden;
  min-height: 7rem;
  display: flex;
  flex-direction: column;
  transition: width 0.2s ease;
  background: var(--surface);
}
.ad-split { display: flex; flex: 1; }
.ad-rail {
  background: var(--surface-2);
  border-inline-end: 1px solid var(--line);
  padding: 0.5rem 0.4rem;
  font-size: 0.75rem;
  color: var(--muted);
  white-space: pre-line;
  text-align: center;
  line-height: 2;
}
.ad-body { flex: 1; display: grid; place-items: center; font-size: 0.82rem; color: var(--ink-2); padding: 0.8rem; }
.ad-detail {
  flex: 1.4;
  display: grid;
  place-items: center;
  font-size: 0.82rem;
  background: var(--primary-soft);
  border-inline-start: 1px solid var(--line);
}
.ad-bottombar {
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  text-align: center;
  padding: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
  letter-spacing: 0.5em;
}

/* ---------- إمكانية الوصول ---------- */

.a11y-row { display: flex; gap: 0.25rem; align-items: center; flex: none; }
.a11y-target {
  font: inherit;
  display: grid;
  place-items: center;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
}
.a11y-target.small { border-style: dashed; border-color: var(--accent); }
.a11y-target.ok { border-color: var(--good); }

.talkback {
  font-size: 0.76rem;
  color: var(--ink-2);
  background: var(--surface-2);
  border-radius: 6px;
  padding: 0.15rem 0.5rem;
  unicode-bidi: plaintext;
}

/* ---------- رسم الاعتماديات ---------- */

.dep-node {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.2rem 0.5rem;
  font-size: 0.78rem;
}
.dep-node code { direction: ltr; }
.dep-idx {
  background: var(--primary);
  color: var(--primary-ink);
  border-radius: 4px;
  width: 1.2rem;
  text-align: center;
  font-size: 0.7rem;
  font-weight: 700;
  flex: none;
}

/* ---------- إعادة المحاولة ---------- */

.retry-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.76rem; }
.retry-n { color: var(--muted); flex: none; width: 4.5rem; }
.retry-bar { height: 0.7rem; background: var(--primary); border-radius: 99px; min-width: 4px; }
.retry-ms { color: var(--ink-2); font-variant-numeric: tabular-nums; flex: none; }

/* ---------- حجم الـ APK ---------- */

.size-track { height: 0.8rem; background: var(--line); border-radius: 99px; overflow: hidden; }
.size-fill { height: 100%; background: var(--primary); border-radius: 99px; transition: width 0.3s ease; }

/* ===================== قايمة الفحص ===================== */

.checklist { list-style: none; margin: 1.2rem 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }

.checklist li {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
  font-size: var(--step--1);
}
.checklist input { margin-top: 0.45rem; accent-color: var(--primary); flex: none; }
.checklist label { cursor: pointer; }

/* ===================== الخطة الزمنية ===================== */

.plan-table td:first-child {
  font-variant-numeric: tabular-nums;
  color: var(--primary);
  font-weight: 700;
  white-space: nowrap;
}

/* ===================== التمرين والكويز ===================== */

.exercise {
  margin-top: 2.4rem;
  border: 1px solid var(--primary);
  border-radius: var(--radius-lg);
  background: var(--surface);
  overflow: hidden;
}

.exercise-head {
  background: var(--primary);
  color: var(--primary-ink);
  padding: 0.5rem 1.1rem;
  font-weight: 700;
  font-size: var(--step--1);
  letter-spacing: 0.04em;
}

.exercise-body { padding: 1rem 1.1rem; }
.exercise-body p { margin: 0; }

.exercise details { margin-top: 0.9rem; }
.exercise summary {
  cursor: pointer;
  color: var(--primary);
  font-weight: 600;
  font-size: var(--step--1);
}
.exercise details p { margin-top: 0.6rem; color: var(--ink-2); font-size: var(--step--1); }

/* ===================== المشروع المتصل ===================== */

.project {
  margin-top: 1.6rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius-lg);
  background: var(--surface);
  overflow: hidden;
}

.project-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--accent-soft);
  padding: 0.5rem 1.1rem;
  font-size: var(--step--1);
  font-weight: 700;
  color: var(--ink);
}

.project-badge {
  background: var(--accent);
  color: #fff;
  border-radius: 99px;
  padding: 0.1rem 0.7rem;
  font-size: 0.76rem;
  letter-spacing: 0.04em;
}

.project-body { padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: 0.7rem; }
.project-goal { margin: 0; }
.project-body .checklist { margin: 0; }
.project-done {
  margin: 0;
  font-size: var(--step--1);
  color: var(--ink-2);
  border-inline-start: 3px solid var(--accent);
  padding-inline-start: 0.7rem;
}

/* ===================== المسرد ===================== */

.glossary {
  margin: 1.2rem 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface);
}

.glossary-row {
  display: grid;
  grid-template-columns: minmax(0, 15rem) minmax(0, 1fr);
  gap: 1rem;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--line);
}
.glossary-row:last-child { border-bottom: none; }
.glossary-row:hover { background: var(--surface-2); }

.glossary-term { display: flex; flex-direction: column; }
.g-en {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  direction: ltr;
  text-align: start;
  color: var(--primary);
  font-weight: 600;
}
.g-ar { font-size: var(--step--1); font-weight: 600; }
.glossary-def { font-size: var(--step--1); color: var(--ink-2); }

/* ===================== الكويز ===================== */

.quiz { margin-top: 1.6rem; display: flex; flex-direction: column; gap: 0.9rem; }

.quiz-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.quiz-head h3 { margin: 0; font-size: var(--step-1); font-weight: 700; }

.quiz-score {
  font-size: var(--step--1);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.quiz-score.final { color: var(--good); font-weight: 700; }

.quiz-q {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: 0.9rem 1.1rem;
}

.quiz-q > p { margin: 0 0 0.7rem; font-weight: 600; }

.quiz-opts { display: flex; flex-direction: column; gap: 0.35rem; }

.quiz-opt {
  font: inherit;
  text-align: start;
  padding: 0.45rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--bg);
  color: var(--ink-2);
  cursor: pointer;
  font-size: var(--step--1);
  line-height: 1.6;
}
.quiz-opt:hover:not([disabled]) { border-color: var(--primary); }
.quiz-opt[disabled] { cursor: default; }
.quiz-opt.right { background: var(--good-soft); border-color: var(--good); color: var(--ink); font-weight: 600; }
.quiz-opt.wrong { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }

.quiz-explain {
  margin: 0.7rem 0 0;
  font-size: var(--step--1);
  color: var(--ink-2);
  border-inline-start: 3px solid var(--primary);
  padding-inline-start: 0.7rem;
}
.quiz-explain[hidden] { display: none; }

/* المصادر */
.resources { margin-top: 1.8rem; }
.resources h4 { font-size: var(--step--1); letter-spacing: 0.08em; color: var(--muted); margin: 0 0 0.5rem; }
.resources ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.4rem; }
.resources a {
  display: inline-block;
  border: 1px solid var(--line-strong);
  border-radius: 99px;
  padding: 0.2rem 0.75rem;
  font-size: var(--step--1);
  text-decoration: none;
  color: var(--ink-2);
}
.resources a:hover { border-color: var(--primary); color: var(--primary); }
.resources a::after { content: " ↗"; color: var(--muted); font-size: 0.8em; }

/* زر إنهاء المحطة */
.done-bar {
  margin-top: 2rem;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.btn-done {
  font: inherit;
  font-weight: 700;
  padding: 0.55rem 1.3rem;
  border-radius: 99px;
  border: 2px solid var(--primary);
  background: transparent;
  color: var(--primary);
  cursor: pointer;
}
.btn-done:hover { background: var(--primary-soft); }
.btn-done[aria-pressed="true"] {
  background: var(--good);
  border-color: var(--good);
  color: #fff;
}

.done-note { font-size: var(--step--1); color: var(--muted); }

/* الخاتمة */
.outro { padding: 4rem 0; text-align: center; }
.outro p { color: var(--muted); font-size: var(--step--1); }

.hidden { display: none !important; }

/* ===================== الاستجابة ===================== */

@media (max-width: 1024px) {
  .shell { grid-template-columns: 1fr; }
  .rail {
    position: static;
    height: auto;
    border-inline-end: none;
    border-bottom: 1px solid var(--line);
  }
  .route { max-height: 17rem; overflow-y: auto; }
  .preview-body { grid-template-columns: 1fr; }
  .preview-stage { border-inline-end: none; border-bottom: 1px solid var(--line); }
}

@media (max-width: 640px) {
  body { line-height: 1.8; }
  .pitfall-pair { grid-template-columns: 1fr; }
  .pitfall-side.good { border-inline-start: none; border-top: 1px solid var(--line); }
  .tree-row { grid-template-columns: 1fr; gap: 0.15rem; }
  .glossary-row { grid-template-columns: 1fr; gap: 0.2rem; }
  .hero-stats { gap: 0 1.5rem; }
  .project-head { flex-direction: column; align-items: flex-start; gap: 0.3rem; }
}
