/* ─────────────────────────────────────────────────────────────
   تنسيق الموقع كامل — ملف واحد لكل الصفحات.
   الألوان مكتوبة مرة واحدة في الأعلى (متغيرات)، فلو أردت
   تغيير لون الموقع كله، غيّر السطر هنا فقط.
   ───────────────────────────────────────────────────────────── */

:root {
  --bg:        #F7F5EF;
  --surface:   #FFFFFF;
  --ink:       #14211F;
  --muted:     #66756F;
  --line:      #E3E0D6;

  --brand:     #1E6F5C;
  --brand-ink: #165546;
  --brand-bg:  #E1EFE9;
  --accent:    #C77C1E;
  --accent-bg: #F7EAD6;

  --danger:    #B4402F;
  --danger-bg: #F8E4E0;

  --radius: 6px;
  --shadow: 0 1px 2px rgba(20,33,31,.05), 0 10px 30px -16px rgba(20,33,31,.25);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0E1412;
    --surface:   #16201D;
    --ink:       #E9EEEA;
    --muted:     #94A39D;
    --line:      #26312D;

    --brand:     #56C0A2;
    --brand-ink: #7BD3B9;
    --brand-bg:  #122C25;
    --accent:    #E0A25C;
    --accent-bg: #2E2314;

    --danger:    #E0836F;
    --danger-bg: #2E1A16;

    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px -16px rgba(0,0,0,.7);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Cairo", "Segoe UI", Tahoma, sans-serif;
  font-weight: 400;
  line-height: 1.85;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: "Reem Kufi", "Cairo", sans-serif;
  font-weight: 600;
  line-height: 1.45;
  text-wrap: balance;
  margin: 0;
}

/* النصوص الإنجليزية تأخذ خطاً مختلفاً حتى تتميّز عن العربية */
.en {
  font-family: "Lora", Georgia, serif;
  direction: ltr;
  unicode-bidi: isolate;
}

a { color: var(--brand); }

.setup-warning {
  background: var(--danger-bg);
  color: var(--danger);
  padding: .85rem 1.25rem;
  font-size: .9rem;
  text-align: center;
  border-bottom: 1px solid var(--danger);
}

/* ── الشعار ─────────────────────────────────────────────── */
.logo { display: flex; align-items: center; gap: .6rem; }
.logo .mark {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--brand);
  display: grid; place-items: center;
  flex-shrink: 0;
}
.logo .name {
  font-family: "Reem Kufi", sans-serif;
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -.01em;
}
.logo .name span { color: var(--brand); }

/* ── شريط علوي ──────────────────────────────────────────── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.topbar .inner {
  max-width: 1000px; margin: 0 auto;
  padding: .85rem 1.25rem;
  display: flex; align-items: center; gap: 1rem;
}
.topbar nav { margin-inline-start: auto; display: flex; align-items: center; gap: .35rem; }
.topbar nav a {
  padding: .45rem .85rem;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--muted);
  font-size: .93rem;
  font-weight: 600;
}
.topbar nav a:hover { background: var(--brand-bg); color: var(--brand); }
.topbar nav a.active { background: var(--brand-bg); color: var(--brand); }

.who {
  font-size: .82rem; color: var(--muted);
  padding-inline-end: .5rem;
  border-inline-end: 1px solid var(--line);
  margin-inline-end: .35rem;
}
@media (max-width: 620px) { .who { display: none; } }

/* ── أزرار ──────────────────────────────────────────────── */
.btn {
  font-family: inherit; font-size: .95rem; font-weight: 600;
  padding: .7rem 1.4rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  transition: background .15s, border-color .15s;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-ink); }
@media (prefers-color-scheme: dark) { .btn-primary { color: #0E1412; } }

.btn-ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--brand); color: var(--brand); }

.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ── صفحة الدخول ────────────────────────────────────────── */
.auth-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
@media (max-width: 860px) { .auth-page { grid-template-columns: 1fr; } }

/* هذه اللوحة تبقى بلون واحد في الوضعين الفاتح والداكن،
   حتى يبقى النص الأبيض واضحاً عليها دائماً. */
.auth-side {
  background: #1E6F5C;
  color: #fff;
  padding: 3.5rem 3rem;
  display: flex; flex-direction: column; justify-content: center; gap: 1.5rem;
}
@media (max-width: 860px) { .auth-side { display: none; } }
.auth-side .logo .mark { background: rgba(255,255,255,.16); }
.auth-side .logo svg { stroke: #fff; }
.auth-side .logo .name, .auth-side .logo .name span { color: #fff; }
.auth-side blockquote {
  margin: 0; font-family: "Lora", Georgia, serif;
  font-size: 1.5rem; line-height: 1.65; direction: ltr; text-align: left;
}
.auth-side .quote-ar { font-size: 1rem; opacity: .8; margin: 0; }
.auth-side .note { font-size: .88rem; opacity: .7; margin-top: auto; }

.auth-main {
  display: grid; place-items: center;
  padding: 2.5rem 1.5rem;
}
.auth-box { width: 100%; max-width: 380px; }
.auth-box > .logo { margin-bottom: 2rem; }
@media (min-width: 861px) { .auth-box > .logo { display: none; } }
.auth-box h1 { font-size: 1.7rem; margin-bottom: .4rem; }
.auth-box .sub { color: var(--muted); font-size: .93rem; margin: 0 0 1.75rem; }

.tabs {
  display: grid; grid-template-columns: 1fr 1fr;
  background: var(--line); border-radius: var(--radius);
  padding: 3px; gap: 3px; margin-bottom: 1.5rem;
}
.tabs button {
  font-family: inherit; font-size: .92rem; font-weight: 600;
  padding: .5rem; border: 0; border-radius: 4px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.tabs button.active { background: var(--surface); color: var(--ink); }

.field { margin-bottom: 1rem; }
.field label {
  display: block; font-size: .85rem; font-weight: 600;
  margin-bottom: .35rem; color: var(--muted);
}
.field input {
  width: 100%;
  font-family: inherit; font-size: .95rem;
  padding: .7rem .85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}
.field input:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: transparent; }
.field .hint { font-size: .78rem; color: var(--muted); margin-top: .3rem; }

.msg {
  padding: .8rem 1rem; border-radius: var(--radius);
  font-size: .88rem; margin-bottom: 1rem; display: none;
}
.msg.show { display: block; }
.msg.error { background: var(--danger-bg); color: var(--danger); }
.msg.ok { background: var(--brand-bg); color: var(--brand-ink); }

/* ── تخطيط عام للصفحات الداخلية ─────────────────────────── */
.page { max-width: 1000px; margin: 0 auto; padding: 3rem 1.25rem 5rem; }

.hero { text-align: center; padding: 2rem 0 3rem; }
.hero .mark-big {
  width: 76px; height: 76px; border-radius: 20px;
  background: var(--brand); display: grid; place-items: center;
  margin: 0 auto 1.5rem;
}
.hero h1 { font-size: clamp(1.9rem, 5vw, 2.7rem); margin-bottom: .6rem; }
.hero p { color: var(--muted); font-size: 1.05rem; max-width: 30em; margin: 0 auto; }

.quote-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2.5rem 2rem;
  text-align: center;
  margin: 2.5rem 0;
}
.quote-card .q {
  font-family: "Lora", Georgia, serif;
  font-size: clamp(1.2rem, 3.5vw, 1.6rem);
  line-height: 1.6; direction: ltr; margin: 0 0 .9rem;
}
.quote-card .q-ar { color: var(--muted); font-size: .97rem; margin: 0; }
.quote-card .q-by { color: var(--accent); font-size: .82rem; font-weight: 600; margin-top: 1rem; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin: 2.5rem 0; }
@media (max-width: 620px) { .stats { grid-template-columns: 1fr; } }
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.5rem; text-align: center;
}
.stat .n {
  font-family: "Reem Kufi", sans-serif; font-size: 2rem;
  font-weight: 600; color: var(--brand); line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.stat .l { font-size: .88rem; color: var(--muted); }

.cta-row { display: flex; gap: .75rem; justify-content: center; flex-wrap: wrap; margin-top: 2rem; }

/* ── صفحة التعلم ────────────────────────────────────────── */
.section-head { margin-bottom: 2rem; }
.section-head h1 { font-size: clamp(1.7rem, 4.5vw, 2.2rem); margin-bottom: .4rem; }
.section-head p { color: var(--muted); margin: 0; }

.topics { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }

.topic {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem;
  cursor: pointer;
  text-align: right;
  font-family: inherit;
  color: inherit;
  display: flex; flex-direction: column; gap: .5rem;
  transition: border-color .15s, transform .15s;
}
.topic:hover { border-color: var(--brand); transform: translateY(-2px); }
.topic:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.topic .icon { font-size: 1.6rem; line-height: 1; }
.topic .t-en {
  font-family: "Lora", Georgia, serif; direction: ltr; text-align: right;
  font-size: 1.15rem; font-weight: 600; color: var(--brand);
}
.topic .t-ar { font-family: "Reem Kufi", sans-serif; font-size: 1rem; font-weight: 600; }
.topic .t-sum { font-size: .88rem; color: var(--muted); line-height: 1.7; }
.topic .count {
  margin-top: auto; padding-top: .75rem; font-size: .8rem;
  color: var(--accent); font-weight: 600;
}

/* ── النافذة المنبثقة للدرس ─────────────────────────────── */
dialog.lesson {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 0;
  max-width: 560px; width: calc(100% - 2rem);
  box-shadow: var(--shadow);
}
dialog.lesson::backdrop { background: rgba(20,33,31,.55); backdrop-filter: blur(2px); }

.lesson-head {
  padding: 1.5rem 1.75rem 1.25rem;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: flex-start; gap: 1rem;
}
.lesson-head .h-en {
  font-family: "Lora", Georgia, serif; direction: ltr;
  font-size: 1.35rem; font-weight: 600; color: var(--brand);
}
.lesson-head .h-ar { font-family: "Reem Kufi", sans-serif; font-size: 1rem; }
.lesson-head .h-sum { font-size: .9rem; color: var(--muted); margin-top: .35rem; }
.lesson-close {
  margin-inline-start: auto; background: transparent; border: 0;
  font-size: 1.5rem; line-height: 1; color: var(--muted); cursor: pointer;
  padding: 0 .25rem;
}
.lesson-close:hover { color: var(--ink); }

.lesson-body { padding: 1.25rem 1.75rem 1.75rem; max-height: 60vh; overflow-y: auto; }
.example {
  padding: 1rem 0;
  border-bottom: 1px solid var(--line);
}
.example:last-child { border-bottom: 0; padding-bottom: 0; }
.example .e-en {
  font-family: "Lora", Georgia, serif; direction: ltr; text-align: left;
  font-size: 1.08rem; margin: 0 0 .25rem;
}
.example .e-ar { color: var(--muted); font-size: .93rem; margin: 0; }
.example .e-note {
  font-size: .82rem; color: var(--accent);
  background: var(--accent-bg); display: inline-block;
  padding: .15rem .55rem; border-radius: 4px; margin-top: .5rem;
}

/* ── حالات ──────────────────────────────────────────────── */
.loading, .empty {
  text-align: center; color: var(--muted);
  padding: 4rem 1rem; font-size: .95rem;
}
.error-box {
  background: var(--danger-bg); color: var(--danger);
  padding: 1.25rem; border-radius: var(--radius);
  font-size: .9rem; line-height: 1.8;
}

.skeleton {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); height: 168px;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
