/* ===========================================================
   Urealm — شاشة الدخول.

   أوّل شاشةٍ تُرى، وقد تكون الوحيدة التي يراها من لم يقتنع بعد. فهي
   تُبنى بعنايةٍ أكثر من غيرها — لا زخرفةً، بل لأنّ أوّل انطباعٍ يُدفع
   ثمنُه مرّةً واحدة.

   ▸ **والحركة تشرح ولا تستعرض.** كلّ حركةٍ هنا تقول شيئًا: البطاقة
     تدخل من حيث ستستقرّ، والخطوة تنزلق في اتّجاه سيرها، والزرّ يهبط
     تحت الإصبع. وحركةٌ لا تقول شيئًا تُحذف.

   ▸ **و`prefers-reduced-motion` ليست حالةً استثنائيّة.** من طلبها
     يصاب بالدوار من غيرها. فتبقى الشاشة كاملةً ويسقط ما يتحرّك —
     ولا يسقط معه معنًى.

   ▸ **ولا شيء يُرسم قبل أوانه.** الهالة خلف البطاقة `will-change`
     محدود، وطبقةٌ واحدة تتحرّك: شاشةُ دخولٍ تُسخّن الجهاز تُقرأ
     رداءةً حتّى لو بدت جميلة.
   =========================================================== */

.auth {
  position: relative;
  display: grid;
  place-items: center;
  min-block-size: 100dvh;
  inline-size: 100%;
  padding: var(--sp-6);
  overflow: hidden;
  isolation: isolate;
}

/* ----------------------- الخلفية ----------------------- */

/* هالتان تتنفّسان ببطء. طبقتان اثنتان لا خمس: ما بعدهما لا يُرى
   ويُدفع ثمنه في كلّ إطار. */
.auth__glow {
  position: absolute;
  z-index: -1;
  inline-size: min(60rem, 120vw);
  aspect-ratio: 1;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.5;
  will-change: transform;
  pointer-events: none;
}

.auth__glow--one {
  background: radial-gradient(circle, color-mix(in oklab, var(--accent) 55%, transparent), transparent 62%);
  inset-block-start: -28%;
  inset-inline-start: -18%;
  animation: auth-drift-a 24s ease-in-out infinite;
}

.auth__glow--two {
  background: radial-gradient(circle, color-mix(in oklab, var(--accent) 32%, #a855f7 40%), transparent 64%);
  inset-block-end: -32%;
  inset-inline-end: -22%;
  animation: auth-drift-b 30s ease-in-out infinite;
}

@keyframes auth-drift-a {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
  50% { transform: translate3d(6%, 8%, 0) scale(1.12); }
}

@keyframes auth-drift-b {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1.06); }
  50% { transform: translate3d(-7%, -6%, 0) scale(1); }
}

/* ----------------------- البطاقة ----------------------- */

.auth__card {
  position: relative;
  inline-size: min(26.5rem, 100%);
  padding: var(--sp-7) var(--sp-6) var(--sp-6);
  border: 1px solid var(--line);
  border-radius: var(--r-xl, 22px);
  background: color-mix(in oklab, var(--bg-surface) 88%, transparent);
  backdrop-filter: blur(20px) saturate(1.3);
  box-shadow: var(--shadow-3);
  animation: auth-rise 620ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* تدخل من حيث ستستقرّ: أسفلَ قليلًا وأصغرَ قليلًا. */
@keyframes auth-rise {
  from { opacity: 0; transform: translateY(18px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

/* خيطٌ يمرّ على الحافّة العليا مرّةً عند الدخول: يقول «حيّ». */
.auth__card::before {
  content: '';
  position: absolute;
  inset-block-start: -1px;
  inset-inline: 12%;
  block-size: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.7;
  animation: auth-sweep 2.4s ease-out 400ms both;
}

@keyframes auth-sweep {
  from { transform: scaleX(0); opacity: 0; }
  40% { opacity: 0.9; }
  to { transform: scaleX(1); opacity: 0.35; }
}

/* ----------------------- الترويسة ----------------------- */

.auth__mark {
  inline-size: 46px;
  block-size: 46px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(145deg, var(--accent), color-mix(in oklab, var(--accent) 55%, #a855f7));
  color: var(--accent-contrast);
  font-size: 1.35rem;
  font-weight: 800;
  margin-inline: auto;
  box-shadow: 0 8px 24px -10px color-mix(in oklab, var(--accent) 70%, transparent);
  animation: auth-pop 700ms cubic-bezier(0.34, 1.56, 0.64, 1) 120ms both;
}

@keyframes auth-pop {
  from { opacity: 0; transform: scale(0.5) rotate(-12deg); }
  to { opacity: 1; transform: none; }
}

.auth__title {
  margin: var(--sp-4) 0 var(--sp-2);
  font-size: var(--fs-5, 1.45rem);
  font-weight: 700;
  text-align: center;
  letter-spacing: -0.01em;
}

.auth__lead {
  margin: 0 0 var(--sp-6);
  color: var(--fg-soft);
  text-align: center;
  font-size: var(--fs-2, 0.925rem);
  line-height: 1.65;
}

/* ----------------------- المزوّدون ----------------------- */

.auth__providers {
  display: grid;
  gap: var(--sp-3);
}

.auth-provider {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  inline-size: 100%;
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-inset);
  color: var(--fg);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: start;
  transition: border-color 160ms, background 160ms, transform 160ms;
  /* تدخل واحدةً بعد أخرى: العين تتبعها بدل أن تُفاجأ بها دفعةً. */
  animation: auth-slide 480ms cubic-bezier(0.16, 1, 0.3, 1) both;
  animation-delay: calc(var(--i, 0) * 70ms + 260ms);
}

@keyframes auth-slide {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.auth-provider:hover { border-color: var(--line-strong); background: var(--hover); }
.auth-provider:active { transform: scale(0.985); }
.auth-provider:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.auth-provider__icon {
  inline-size: 22px;
  block-size: 22px;
  display: grid;
  place-items: center;
  flex: none;
}

.auth-provider__label { flex: 1; min-inline-size: 0; }

/* السهم يميل مع اتّجاه القراءة، ويتقدّم عند اللمس. */
.auth-provider__go {
  color: var(--fg-faint);
  transition: transform 160ms, color 160ms;
}

.auth-provider:hover .auth-provider__go {
  color: var(--fg-soft);
  transform: translateX(-3px);
}

:dir(ltr) .auth-provider:hover .auth-provider__go { transform: translateX(3px); }

/* ----------------------- الفاصل ----------------------- */

.auth__or {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin: var(--sp-5) 0;
  color: var(--fg-faint);
  font-size: var(--fs-1, 0.8rem);
}

.auth__or::before,
.auth__or::after {
  content: '';
  flex: 1;
  block-size: 1px;
  background: var(--line);
}

/* ----------------------- الاستمارة ----------------------- */

.auth__form { display: grid; gap: var(--sp-4); }

.auth__row { display: grid; gap: var(--sp-2); }

.auth__label {
  font-size: var(--fs-1, 0.8rem);
  font-weight: 600;
  color: var(--fg-soft);
}

.auth__input {
  inline-size: 100%;
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-sunken);
  color: var(--fg);
  font: inherit;
  transition: border-color 160ms, box-shadow 160ms;
}

.auth__input:focus {
  outline: none;
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.auth__input[aria-invalid='true'] {
  border-color: color-mix(in oklab, var(--danger) 60%, transparent);
}

/* الرسالة تنزل تحت حقلها، ولا تُزيح ما بعدها فجأة. */
.auth__hint {
  font-size: var(--fs-1, 0.8rem);
  color: var(--fg-faint);
  min-block-size: 1.2em;
  animation: auth-fade 220ms ease-out both;
}

.auth__hint--bad { color: var(--danger); }
.auth__hint--good { color: var(--success); }

@keyframes auth-fade {
  from { opacity: 0; transform: translateY(-3px); }
  to { opacity: 1; transform: none; }
}

.auth__submit {
  inline-size: 100%;
  padding: var(--sp-3) var(--sp-4);
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-contrast);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: filter 160ms, transform 160ms;
}

.auth__submit:hover { filter: brightness(1.08); }
.auth__submit:active { transform: scale(0.985); }
.auth__submit[disabled] { opacity: 0.5; cursor: not-allowed; }

.auth__switch {
  margin-block-start: var(--sp-4);
  text-align: center;
  font-size: var(--fs-1, 0.85rem);
  color: var(--fg-soft);
}

.auth__link {
  color: var(--accent-fg);
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ----------------------- الخطوات ----------------------- */

.auth__steps {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-block-end: var(--sp-5);
}

.auth__step {
  inline-size: 28px;
  block-size: 3px;
  border-radius: 2px;
  background: var(--line);
  transition: background 300ms, inline-size 300ms;
}

.auth__step.is-on { background: var(--accent); inline-size: 40px; }
.auth__step.is-done { background: color-mix(in oklab, var(--accent) 45%, transparent); }

/* الخطوة تنزلق في اتّجاه سيرها: إلى الأمام أو إلى الخلف. */
.auth__panel { animation: auth-step-in 380ms cubic-bezier(0.16, 1, 0.3, 1) both; }
.auth__panel[data-back='1'] { animation-name: auth-step-back; }

@keyframes auth-step-in {
  from { opacity: 0; transform: translateX(-22px); }
  to { opacity: 1; transform: none; }
}

@keyframes auth-step-back {
  from { opacity: 0; transform: translateX(22px); }
  to { opacity: 1; transform: none; }
}

:dir(ltr) .auth__panel { animation-name: auth-step-in-ltr; }
:dir(ltr) .auth__panel[data-back='1'] { animation-name: auth-step-back-ltr; }

@keyframes auth-step-in-ltr {
  from { opacity: 0; transform: translateX(22px); }
  to { opacity: 1; transform: none; }
}

@keyframes auth-step-back-ltr {
  from { opacity: 0; transform: translateX(-22px); }
  to { opacity: 1; transform: none; }
}

/* ----------------------- الصورة ----------------------- */

.auth__avatar {
  inline-size: 88px;
  block-size: 88px;
  border-radius: 50%;
  margin-inline: auto;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--bg-inset);
  cursor: pointer;
  position: relative;
  transition: border-color 160ms, transform 160ms;
}

.auth__avatar:hover { border-color: var(--accent-line); transform: scale(1.03); }
.auth__avatar img { inline-size: 100%; block-size: 100%; object-fit: cover; }

.auth__avatar-hint {
  margin-block-start: var(--sp-3);
  text-align: center;
  font-size: var(--fs-1, 0.8rem);
  color: var(--fg-faint);
}

/* ----------------------- من أين عرفتنا ----------------------- */

.auth__sources {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  justify-content: center;
}

.auth__source {
  padding: var(--sp-2) var(--sp-4);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-inset);
  color: var(--fg-soft);
  font: inherit;
  font-size: var(--fs-1, 0.85rem);
  cursor: pointer;
  transition: border-color 160ms, background 160ms, color 160ms, transform 160ms;
  animation: auth-slide 380ms cubic-bezier(0.16, 1, 0.3, 1) both;
  animation-delay: calc(var(--i, 0) * 45ms);
}

.auth__source:hover { border-color: var(--line-strong); color: var(--fg); }
.auth__source:active { transform: scale(0.95); }

.auth__source.is-on {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent-fg);
}

/* ----------------------- الانتظار والنجاح ----------------------- */

.auth__spinner {
  inline-size: 18px;
  block-size: 18px;
  border: 2px solid color-mix(in oklab, var(--accent-contrast) 35%, transparent);
  border-block-start-color: var(--accent-contrast);
  border-radius: 50%;
  display: inline-block;
  vertical-align: -3px;
  animation: auth-spin 700ms linear infinite;
}

@keyframes auth-spin { to { transform: rotate(360deg); } }

/* علامةٌ تُرسم لا تظهر: الرسم يقول «تمّ الآن». */
.auth__check {
  inline-size: 64px;
  block-size: 64px;
  margin-inline: auto;
  display: block;
  color: var(--success);
}

.auth__check circle,
.auth__check path {
  fill: none;
  stroke: currentcolor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.auth__check circle {
  stroke-dasharray: 166;
  stroke-dashoffset: 166;
  animation: auth-draw 620ms cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.auth__check path {
  stroke-dasharray: 48;
  stroke-dashoffset: 48;
  animation: auth-draw 340ms cubic-bezier(0.65, 0, 0.45, 1) 480ms forwards;
}

@keyframes auth-draw { to { stroke-dashoffset: 0; } }

/* ----------------------- الملاحظة ----------------------- */

.auth__note {
  margin-block-start: var(--sp-5);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-inset);
  font-size: var(--fs-1, 0.8rem);
  line-height: 1.7;
  color: var(--fg-faint);
}

.auth__error {
  margin-block-end: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid color-mix(in oklab, var(--danger) 40%, transparent);
  border-radius: 12px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: var(--fs-1, 0.85rem);
  animation: auth-shake 420ms ease-out both;
}

/* هزّةٌ واحدة صغيرة: تلفت ولا تُفزع. */
@keyframes auth-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
}

/* ----------------------- من طلب السكون ----------------------- */

@media (prefers-reduced-motion: reduce) {
  .auth__glow--one,
  .auth__glow--two,
  .auth__card,
  .auth__card::before,
  .auth__mark,
  .auth-provider,
  .auth__source,
  .auth__panel,
  /* والصنفان الموجّهان أعلى تخصيصًا من `.auth__panel` وحدها، فلا
     يكفي أن يُطفأ العامّ: يُطفأ كلٌّ بتخصيصه. */
  :dir(ltr) .auth__panel,
  :dir(ltr) .auth__panel[data-back='1'],
  .auth__panel[data-back='1'],
  .auth__hint,
  .auth__error,
  .auth__check circle,
  .auth__check path {
    animation: none;
  }

  /* وما كان يُرسم بالحركة يظهر مرسومًا. */
  .auth__check circle,
  .auth__check path { stroke-dashoffset: 0; }

  .auth__spinner { animation-duration: 1.6s; }

  .auth-provider:active,
  .auth__submit:active,
  .auth__source:active { transform: none; }
}
