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

*, *::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; align-items: center; gap: 18px; }
.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; }
/* أيقونة مرسومة جوّا الزر (اللغة، الخريطة): أكبر من الزر شعرة، فبتطلع منه مثل ملصق */
.pill__art { flex: none; block-size: 40px; inline-size: auto; margin-block: -6px; filter: drop-shadow(0 1px 1.5px rgb(0 0 0 / .35)); user-select: none; }
/* زر الفهرس: أيقونة الخريطة لما الخريطة شغّالة، وأيقونة المحطات الخطّية لما يرجع قائمة */
.pill__art--map, .pill.is-map .ico-line { display: none; }
.pill.is-map .pill__art--map { display: block; }
/* زرّي الشريط العلوي (اللغة والخريطة): الأيقونة والكلمة بس، بدون إطار ولا خلفية */
.top__tools .pill { border: 0; background: none; -webkit-backdrop-filter: none; backdrop-filter: none; padding-inline: 0; gap: .45em; font-weight: 700; font-size: .92rem; }

/* شريط التقدّم (يظهر على الجوال بدل خط المحطات) */
.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: 100%; block-size: 100dvh; max-inline-size: none; max-block-size: none; /* 100% مش 100vw: الـ vw بيحسب شريط التمرير، فبالعربي كانت اللوحة بتطلع 15 بكسل برّا الشاشة من اليسار */
  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); }

/* ── خريطة العالم: الفهرس كلوحة وحدة ماليّة الشاشة فيها معالم الطريق، وفوقها زر شفاف ولوحة خشب لكل محطة ──
   المواضع نسب مئوية من الصورة (--x, --y قاعدة المعلم؛ --w, --h مساحة الضغط)، فبتضل مضبوطة بأي حجم.
   نسختين من الصورة: عريضة للشاشات العريضة وطولية للجوال (nav.js بيختار وبيحط مقاساتها متغيّرات على .atlas__map).
   الخريطة نفسها ما بتنعكس مع اللغة (direction: ltr)، بس الأسماء بتتبدّل. */
.index.has-map .index__list { display: none; }
/* لما الخريطة ما بتغطّي الشاشة كلها، حواليها مش فراغ: نفس الصورة مكبّرة ومغبّشة وغامقة ماليّة الشاشة وراها */
.index.has-map { background: #24160C; color: var(--cream); overflow: hidden; }
.index.has-map::before {
  content: ""; position: fixed; inset: -8%; pointer-events: none;
  background: var(--map) center / cover no-repeat; filter: blur(28px) saturate(1.15) brightness(.6);
}
.index.has-map > * { position: relative; }
/* بوضع الخريطة ما في شريط فوق: الخريطة بتملّي الشاشة كلها. العنوان بيضل للقارئ الصوتي بس، وزر الإغلاق دائرة صغيرة بزاوية الخريطة الفاضية (فوق يسار) */
.index:focus { outline: none; }
.index.has-map .index__head { position: absolute; inset: 0 0 auto 0; z-index: 5; block-size: 0; padding: 0; }
.index.has-map .index__head h2,
.index.has-map [data-index-close] span { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.index.has-map [data-index-close] {
  position: absolute; top: max(14px, env(safe-area-inset-top)); left: 14px;
  inline-size: 42px; block-size: 42px; padding: 0; justify-content: center; border-radius: 50%;
  border: 1px solid rgb(255 243 214 / .35); background: rgb(36 22 12 / .55); color: #FFF3D6; font-size: 1.05rem;
}
.atlas { flex: 1; min-block-size: 0; overflow: hidden; container-type: size; direction: ltr; }
.atlas[hidden] { display: none; }
/* العريضة بتغطّي المساحة كلها وبتنقصّ من أطرافها حسب شكل الشاشة، بس مش أكثر من 5% من كل جهة (اللوحات والشخصية
   اللي قريبة من الأطراف لازم تضل بايّنة): لو الشاشة أضيق أو أعرض من هيك بيضل جنب الخريطة شريط من الخلفية المغبّشة.
   الطولية بتبيّن كاملة دايماً */
.atlas__map {
  position: absolute; left: 50%; top: 50%; translate: -50% -50%;
  container-type: inline-size; aspect-ratio: var(--ratio, 2);
  inline-size: min(max(100cqw, 100cqh * var(--ratio, 2)), 110cqw, 110cqh * var(--ratio, 2));
}
.atlas[data-map="tall"] .atlas__map { inline-size: min(100cqw, 100cqh * var(--ratio, .5628)); }
.atlas__img { display: block; inline-size: 100%; block-size: 100%; user-select: none; }
.atlas__hint {
  position: absolute; inset-inline: 0; bottom: max(10px, env(safe-area-inset-bottom)); margin: 0;
  text-align: center; font-size: .84rem; font-weight: 600; pointer-events: none;
}
.atlas__hint span {
  display: inline-block; padding: .45em 1.15em; border-radius: 999px;
  background: rgb(36 22 12 / .72); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
[dir="rtl"] .atlas__hint { direction: rtl; }
/* على العريضة الخريطة ماليّة الشاشة، وتحت فيها الطريق والشخصية: الإرشاد بيطلع فوق على السما */
.atlas[data-map="wide"] .atlas__hint { top: max(18px, env(safe-area-inset-top)); bottom: auto; }
.atlas__pins { position: absolute; inset: 0; margin: 0; padding: 0; list-style: none; }
/* بدون translate ولا z-index على الـ li: هيك ما بتصير كل محطة طبقة لحالها، فكل اللوحات (z-index 2) بتضل قدام كل المعالم
   المرتفعة (z-index 1)، حتى لو ارتفع معلم جنبه لوحة محطة ثانية (مثل صخور الافتتاح ولوحة الجامعة على خريطة الجوال) */
.atlas__pins li {
  position: absolute; left: calc((var(--x) - var(--w) / 2) * 1%); top: calc((var(--y) - var(--h)) * 1%);
  inline-size: calc(var(--w) * 1%); block-size: calc(var(--h) * 1%);
}
.atlas__pins button {
  position: absolute; inset: 0; inline-size: 100%; block-size: 100%;
  border: 0; padding: 0; border-radius: 14px; background: none; color: inherit; font: inherit; cursor: pointer;
}
.atlas__pins button:focus-visible { outline: 3px solid var(--coral); outline-offset: 3px; }
/* النسخة المقصوصة من المعلم (نفس صورة الخريطة، بقناع حدوده من tools/art/map_masks.py) محطوطة فوق مكانه بالضبط.
   عند المرور بتكبر شعرة من قاعدتها وبينزل تحتها ظل، فالمعلم بيرتفع لحاله. بتظهر بس وقت الحركة عشان ما يبيّن أي فرق وهي ساكنة */
.atlas__lift {
  position: absolute; z-index: 1; pointer-events: none; opacity: 0;
  transform-origin: 50% 97%;
  filter: drop-shadow(0 .3cqi .3cqi rgb(60 30 0 / 0));
  transition: transform .26s cubic-bezier(.3, .7, .3, 1), filter .26s, opacity 0s .26s;
}
.atlas__lift i {
  position: absolute; inset: 0;
  background-image: var(--map); background-repeat: no-repeat;
  -webkit-mask: var(--cut) center / 100% 100% no-repeat;
  mask: var(--cut) center / 100% 100% no-repeat;
}
.atlas__pins button:hover .atlas__lift, .atlas__pins button:focus-visible .atlas__lift {
  opacity: 1; transform: translateY(-1.6%) scale(1.075);
  filter: drop-shadow(0 .75cqi .55cqi rgb(60 30 0 / .45));
  transition: transform .26s cubic-bezier(.3, .7, .3, 1), filter .26s, opacity 0s;
}
/* لوحة المحطة: لوح خشب أبيض من نفس لوحات أول كل قسم، مغروز جنب المعلم على الطريق، وعليه اسم المحطة أو شعارها.
   --px = بكسل واحد من ملف اللوحة على الخريطة (هو اللي بيكبّر ويصغّر اللوحات)، و --post = طول العمود اللي بيبيّن تحت اللوح.
   الكتابة حجمها نسبة من عرض اللوحة (cqi جوّاتها)، ومكانها (--bt, --bh) = اللوح نفسه من ارتفاع اللوحة كلها */
.atlas__sign {
  position: absolute; z-index: 2; translate: -50% -100%; container-type: inline-size;
  inline-size: calc(440 * var(--px)); block-size: calc((225 + var(--post, 170)) * var(--px));
  filter: drop-shadow(0 .1cqi .16cqi rgb(40 20 0 / .5));
  transform-origin: calc(50% + var(--ox, 0px)) calc(100% + var(--oy, 0px));
  transition: transform .26s cubic-bezier(.3, .7, .3, 1);
}
/* مايلة شعرة، كل وحدة لجهة، مثل لوحة مغروزة باليد */
.atlas__pins li:nth-child(3n+1) .atlas__sign { rotate: -1.3deg; }
.atlas__pins li:nth-child(3n+2) .atlas__sign { rotate: 1.1deg; }
/* صورة اللوحة: العمود الطويل بينقصّ من تحت لطول --post، وآخره بيذوب بالأرض */
.atlas__wood {
  position: relative; display: block; inline-size: 100%; block-size: 100%; object-fit: cover; object-position: 50% 0;
  -webkit-mask-image: linear-gradient(#000 94%, #0000); mask-image: linear-gradient(#000 94%, #0000); user-select: none;
}
/* ظل صغير على الأرض عند أسفل العمود */
.atlas__sign::before {
  content: ""; position: absolute; left: 50%; bottom: 0; inline-size: 30%; block-size: 5%; translate: -42% 55%;
  border-radius: 50%; background: radial-gradient(closest-side, rgb(40 20 0 / .55), rgb(40 20 0 / 0));
}
/* الاسم مكتوب على اللوح بخط الرقعة، مثل لوحة مدهونة باليد */
.atlas__sign b {
  position: absolute; inset-inline: 4%; top: calc(var(--bt, 8.9) * 1%); block-size: calc(var(--bh, 48.1) * 1%);
  display: flex; align-items: center; justify-content: center; gap: 4cqi; text-align: center; white-space: nowrap;
  font: 700 calc(var(--fs, 18) * 1cqi)/1.04 var(--ruqaa); color: #3A2110;
}
[dir="rtl"] .atlas__sign b { direction: rtl; }
[data-id="kaust"] .atlas__sign b { font-family: var(--font); font-weight: 800; letter-spacing: .03em; color: #12506B; } /* مثل لوحة قسم KAUST */
/* رمز قبل الاسم (شعار الجامعة): بالعربي بيطلع على يمين الكلمة وبالإنجليزي على يسارها */
.atlas__crest { flex: none; block-size: 70%; inline-size: auto; user-select: none; }
/* شعار بدل الكتابة (AILA): بنص اللوح، ورمزه بألوانه الأصلية */
.atlas__mark { position: absolute; left: 50%; top: calc((var(--bt, 8.9) + var(--bh, 48.1) / 2) * 1%); inline-size: 76%; translate: -50% -50%; user-select: none; }
.atlas__pins button:hover .atlas__sign, .atlas__pins button:focus-visible .atlas__sign {
  transform: translateY(calc(-1 * var(--ly, .3cqi))) scale(1.075);
}
/* «أنت هنا»: نفس شخصية الطريق (نسخة من رسمتها) واقفة على الطريق قدام مبنى المحطة الحالية وبتلوّح */
.atlas__me {
  position: absolute; left: calc(var(--mx, 50) * 1%); top: calc(var(--my, 50) * 1%);
  block-size: var(--walker, 5.8cqi); aspect-ratio: 120 / 224; translate: -50% -94.6%; pointer-events: none; z-index: 4;
  filter: drop-shadow(0 0 .14cqi #FFF3D6) drop-shadow(0 .25cqi .25cqi rgb(40 20 0 / .5));
  transition: left .5s, top .5s;
  animation: atlas-bob 1.5s ease-in-out infinite alternate;
}
.atlas__me .walker__rig { filter: none; transform: none; }
@keyframes atlas-bob { to { translate: -50% -96.4%; } }
.index.has-map[open] .atlas__sign { animation: atlas-plant .5s cubic-bezier(.2, 1.4, .4, 1) backwards; animation-delay: calc(var(--i) * 70ms + .3s); }
@keyframes atlas-plant { from { opacity: 0; translate: -50% -128%; } }
html.calm .atlas__me, html.calm .atlas__me * { animation: none; } /* دخول اللوحات بيضل حتى بالوضع الهادئ: قصير وبيصير بس لما الزائر يفتح الخريطة */
html.calm .atlas__me { transition: none; } /* ارتفاع المعلم ولوحته عند المرور بيضل حتى بالوضع الهادئ: حركة صغيرة بيعملها الزائر بإيده، والثنتين لازم يتحركوا سوا */

/* ── حبيبات الورق فوق كل شيء ── */
.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; }
