/* ═══════════════════════════════════════════════════════════
   الأساس: المتغيّرات، الخطوط، الشريط العلوي، خط المحطات، الفهرس
   ═══════════════════════════════════════════════════════════ */

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

:root {
  --ink: #1D1B1A;
  --paper: #F6EFE2;
  --cream: #FBF6EC;
  --coral: #E8623D;
  --saffron: #F4B740;
  --teal: #1F8A8A;
  --teal-deep: #0B3F47;
  --mint: #7DE2C3;
  --palm: #2F7D5B;
  --navy: #1E2A4A;

  --font: "Alexandria", "Segoe UI", Tahoma, system-ui, sans-serif;
  --hand: "Playpen Sans Arabic", "Caveat", "Segoe Print", cursive;
  --mono: "JetBrains Mono", "Alexandria", ui-monospace, Consolas, monospace;
  --ruqaa: "Aref Ruqaa", "Alexandria", serif;

  --pad: clamp(18px, 4.6vw, 72px);
  --top: 68px;
  --dirx: 1; /* اتجاه القراءة: 1 لليسار←يمين، -1 للعربية */

  --tone-fg: var(--ink);
  --tone-glass: rgb(255 255 255 / .4);
}
[dir="rtl"] { --dirx: -1; }
body[data-tone="dark"] { --tone-fg: var(--cream); --tone-glass: rgb(0 0 0 / .3); }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: #0F0D0C;
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  overflow-x: hidden;
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg, canvas { display: block; }
button { font: inherit; color: inherit; }
a { color: inherit; }
h1, h2, h3, p, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }
:focus-visible { outline: 3px solid var(--saffron); outline-offset: 3px; border-radius: 6px; }

.skip {
  position: fixed; top: 8px; inset-inline-start: 8px; z-index: 600;
  padding: .6em 1em; border-radius: 10px;
  background: var(--ink); color: var(--cream); text-decoration: none;
  transform: translateY(-220%);
}
.skip:focus { transform: none; }

/* ── شاشة التحميل ── */
.loader {
  position: fixed; inset: 0; z-index: 500;
  display: grid; place-items: center;
  background: #F9DDBD;
  transition: opacity .5s, visibility .5s;
}
body:not(.is-loading) .loader { opacity: 0; visibility: hidden; }
.loader__badge {
  position: relative;
  inline-size: 54px; block-size: 70px; border-radius: 11px;
  display: grid; place-items: center;
  background: var(--coral); color: var(--cream);
  font: 900 28px/1 var(--font);
  transform-origin: 50% -64px;
  animation: loader-swing 1s ease-in-out infinite alternate;
}
.loader__badge::before {
  content: ""; position: absolute; left: 50%; bottom: 100%;
  inline-size: 6px; block-size: 64px; border-radius: 3px;
  background: var(--teal); translate: -50% 0;
}
@keyframes loader-swing { from { rotate: -15deg; } to { rotate: 15deg; } }

/* ── الشريط العلوي ── */
.top {
  position: fixed; inset: 0 0 auto 0; z-index: 200;
  block-size: var(--top);
  display: flex; align-items: center; justify-content: space-between;
  padding-inline: var(--pad);
  color: var(--tone-fg);
  transition: color .35s;
  pointer-events: none;
}
.top > * { pointer-events: auto; }
/* لوحة البادجات تتحرك تحت الشريط (مش مثبّتة)، فنعطيه خلفية تتلاشى */
.top::before {
  content: ""; position: absolute; inset: 0 0 -18px 0; z-index: -1;
  background: linear-gradient(180deg, #191614 45%, transparent);
  opacity: 0; transition: opacity .35s;
}
body[data-at="badges"] .top::before { opacity: 1; }
.brand {
  display: inline-flex; align-items: center; gap: .55em;
  font-weight: 800; font-size: 1.08rem; text-decoration: none;
}
.brand__icon { inline-size: 20px; block-size: 26px; }
.top__tools { display: flex; gap: 8px; }
.pill {
  display: inline-flex; align-items: center; gap: .5em;
  block-size: 38px; padding-inline: 14px;
  border: 1.5px solid currentColor; border-radius: 999px;
  background: var(--tone-glass); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  font-weight: 600; font-size: .85rem; line-height: 1;
  cursor: pointer;
  transition: transform .2s, background .35s;
}
.pill:hover { transform: translateY(-1px); }
.pill--lang { min-inline-size: 42px; justify-content: center; font-weight: 800; }

/* شريط التقدّم (يظهر على الجوال بدل خط المحطات) */
.bar { position: fixed; inset: 0 0 auto 0; z-index: 210; block-size: 3px; display: none; }
.bar i {
  display: block; block-size: 100%; background: var(--coral);
  transform: scaleX(var(--progress, 0)); transform-origin: 0 50%;
}
[dir="rtl"] .bar i { transform-origin: 100% 50%; }

/* ── خط المحطات الجانبي ── */
.line {
  position: fixed; z-index: 150;
  inset-inline-end: clamp(10px, 1.5vw, 24px); top: 50%; translate: 0 -50%;
  color: var(--tone-fg);
  transition: color .35s;
}
.line ol { position: relative; display: grid; gap: 13px; }
.line ol::before {
  content: ""; position: absolute; left: 50%; inset-block: 6px;
  inline-size: 2px; translate: -50% 0;
  background: currentColor; opacity: .28;
}
.line button {
  position: relative; display: block;
  inline-size: 14px; block-size: 14px; padding: 0;
  border: 2px solid currentColor; border-radius: 50%;
  background: var(--tone-glass);
  cursor: pointer;
  transition: scale .25s, background .25s, border-color .25s;
}
.line button::after { content: ""; position: absolute; inset: -8px; } /* مساحة ضغط أكبر */
.line li.is-done button { background: currentColor; }
.line li.is-on button { background: var(--coral); border-color: var(--coral); scale: 1.4; }
.line button span {
  position: absolute; inset-inline-end: 26px; top: 50%; translate: 0 -50%;
  padding: .32em .8em; border-radius: 999px;
  background: var(--ink); color: var(--cream);
  font-size: .74rem; font-weight: 600; white-space: nowrap;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.line button:hover span, .line button:focus-visible span { opacity: 1; }

/* ── الأزرار ── */
.btn {
  display: inline-flex; align-items: center; gap: .6em;
  padding: .85em 1.35em;
  border: 2px solid currentColor; border-radius: 999px;
  font-weight: 700; text-decoration: none;
  transition: transform .2s, background .2s, color .2s;
}
.btn:hover { transform: translateY(-3px); }
.btn--solid { background: var(--ink); border-color: var(--ink); color: var(--cream); }

/* ── الفهرس ── */
.index {
  --ox: 88%;
  inset: 0; margin: 0; padding: 0; border: 0;
  inline-size: 100vw; block-size: 100dvh; max-inline-size: none; max-block-size: none;
  background: var(--paper); color: var(--ink);
  overflow: auto;
}
[dir="rtl"] .index { --ox: 12%; }
.index[open] {
  display: flex; flex-direction: column;
  animation: index-in .55s cubic-bezier(.2, .8, .2, 1);
}
@keyframes index-in {
  from { clip-path: circle(0% at var(--ox) 34px); }
  to { clip-path: circle(150% at var(--ox) 34px); }
}
.index__head {
  display: flex; align-items: center; justify-content: space-between;
  block-size: var(--top); padding-inline: var(--pad); flex: none;
}
.index__head h2 { font-size: 1.08rem; font-weight: 800; }
.index__list {
  margin: auto; padding: 1svh var(--pad) 7svh;
  inline-size: min(700px, 100%);
}
.index__list li { position: relative; }
.index__list li + li::before {
  content: ""; position: absolute; z-index: 0;
  inset-inline-start: calc(3rem + 20px + 7.5px); bottom: 50%;
  inline-size: 3px; block-size: 100%;
  background: var(--ink); opacity: .2;
}
.index__list button {
  position: relative;
  display: grid; grid-template-columns: 3rem 18px 1fr; align-items: center; gap: 20px;
  inline-size: 100%; padding: clamp(7px, 1.35svh, 15px) 0;
  border: 0; background: none; cursor: pointer; text-align: start;
  font-weight: 800; font-size: clamp(1.35rem, 4.1svh, 2.4rem); line-height: 1.35;
  transition: color .2s, transform .25s;
}
.index__list button:hover, .index__list button:focus-visible {
  color: var(--coral); transform: translateX(calc(10px * var(--dirx)));
}
.index__list .n { font: 700 .9rem/1 var(--mono); opacity: .5; }
.index__list .dot {
  position: relative; z-index: 1;
  inline-size: 18px; block-size: 18px; border-radius: 50%;
  border: 3px solid var(--ink); background: var(--paper);
}
.index__list li.is-on .dot { background: var(--coral); border-color: var(--coral); }
.index__list li.is-done .dot { background: var(--ink); }

/* ── حبيبات الورق فوق كل شيء ── */
.grain {
  position: fixed; inset: 0; z-index: 400; pointer-events: none;
  opacity: .5;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .25  0 0 0 0 .2  0 0 0 0 .15  0 0 0 .32 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

@media (max-aspect-ratio: 1/1) {
  :root { --top: 60px; }
  .line { display: none; }
  .bar { display: block; }
  .pill { block-size: 36px; padding-inline: 12px; }
}

/* شاشات عرضية قصيرة (جوال بالعرض، نافذة صغيرة) */
@media (max-height: 480px) {
  :root { --top: 50px; }
  .pill { block-size: 32px; padding-inline: 11px; font-size: .78rem; }
  .line ol { gap: 8px; }
}

/* الوضع الهادئ (html.calm): نطفي المؤثرات المحيطة فقط. المشي والإشارات تبقى لأنها مربوطة بسكرول الزائر نفسه. */
.calm .loader__badge { animation: none; }
