@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800;900&family=Tajawal:wght@400;500;700;800&display=swap');

/* ============================================================
   متغيرات الألوان — مستخرجة بالظبط من شعار "الفارس المعاصر"
   (بني غامق + ذهبي/تان + كريمي). لو حبيت تغيّر الألوان يومًا،
   غيّرها من هنا بس ومش هتحتاج تلمس باقي الملف.
   ============================================================ */
:root {
  --brown-950: #140c08;
  --brown-900: #1d130c;
  --brown-800: #2a1a10;
  --brown-700: #482018;   /* اللون الأساسي من الشعار */
  --brown-600: #6b3226;
  --gold-500: #c09860;    /* لون التمييز (accent) من الشعار */
  --gold-400: #d4b482;
  --gold-300: #e6cd9f;
  --cream-100: #f0e0b8;   /* كريمي من الشعار */
  --cream-50: #f7ecd8;

  --bg-main: var(--brown-950);
  --bg-card: rgba(42, 26, 16, 0.55);
  --bg-card-solid: #241610;
  --border-color: rgba(212, 180, 130, 0.18);

  --text-main: var(--cream-50);
  --text-muted: #b8a58c;

  --success: #3f9a5c;
  --danger: #c94f4f;
  --warning: #d9a441;

  --radius-lg: 22px;
  --radius-md: 14px;
  --font-main: 'Cairo', 'Tajawal', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-main);
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  direction: rtl;
  text-align: right;
  line-height: 1.7;
  overflow-x: hidden;
  background-image:
    radial-gradient(at 12% 8%, rgba(192, 152, 96, 0.16) 0px, transparent 45%),
    radial-gradient(at 90% 90%, rgba(72, 32, 24, 0.35) 0px, transparent 50%);
  background-attachment: fixed;
  -webkit-user-select: none;
  user-select: none;
}

/* السماح بتحديد النص جوه حقول الإدخال فقط */
input, textarea { -webkit-user-select: text; user-select: text; }

[hidden] { display: none !important; }

img { max-width: 100%; }

.container { max-width: 1100px; margin: 0 auto; padding: 0 1.1rem; }

/* ---------- الشريط العلوي ---------- */
.top-bar {
  text-align: center;
  padding: 0.6rem 1rem;
  font-size: 0.85rem;
  color: var(--gold-300);
  background: rgba(20, 12, 8, 0.6);
  border-bottom: 1px solid var(--border-color);
}

.navbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(20, 12, 8, 0.9);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 0;
}

.nav-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 0.75rem; }

.brand img.brand-logo {
  width: 42px;
  height: 42px;
  object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.5));
}

.brand-title h1 {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--cream-50);
}

.brand-title p {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ---------- عناصر عامة ---------- */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.7rem 1.3rem;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-weight: 800;
  font-size: 0.9rem;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  text-decoration: none;
  color: inherit;
}

.btn-primary {
  background: linear-gradient(135deg, var(--brown-700), var(--brown-600));
  color: #fff;
  box-shadow: 0 4px 16px rgba(72, 32, 24, 0.5);
  border: 1px solid rgba(212, 180, 130, 0.3);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(72, 32, 24, 0.7); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-gold {
  background: linear-gradient(135deg, var(--gold-500), var(--gold-400));
  color: var(--brown-950);
  box-shadow: 0 4px 16px rgba(192, 152, 96, 0.35);
}
.btn-gold:hover { transform: translateY(-2px); }

.btn-success {
  background: linear-gradient(135deg, #1f6b3a, var(--success));
  color: #fff;
}
.btn-success:hover { transform: translateY(-2px); }

.btn-secondary {
  background: rgba(255,255,255,0.06);
  color: var(--cream-100);
  border: 1px solid var(--border-color);
}
.btn-secondary:hover { background: rgba(255,255,255,0.12); }

.btn-flag {
  background: rgba(217, 164, 65, 0.14);
  color: var(--warning);
  border: 1px solid rgba(217, 164, 65, 0.35);
}
.btn-flag.active { background: var(--warning); color: var(--brown-950); }

.hint { font-size: 0.8rem; color: var(--text-muted); }

/* ============================================================
   شاشة 1: اختيار الصف الدراسي
   ============================================================ */
.landing {
  padding: 2.5rem 0 3rem;
  text-align: center;
}

.ayah {
  font-size: 1.05rem;
  color: var(--gold-300);
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.landing h2 {
  font-size: 1.6rem;
  font-weight: 900;
  margin: 1rem 0 0.3rem;
  color: var(--cream-50);
}

.landing .slogan {
  color: var(--text-muted);
  margin-bottom: 2rem;
  font-size: 0.95rem;
}

.landing-logo {
  width: 96px;
  margin: 0 auto 0.75rem;
  display: block;
}

.grade-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-top: 1.5rem;
}

@media (max-width: 720px) {
  .grade-cards { grid-template-columns: 1fr; }
}

.grade-card {
  padding: 2rem 1.5rem;
  cursor: pointer;
  transition: all 0.25s ease;
  text-align: center;
}

.grade-card:hover {
  transform: translateY(-6px);
  border-color: var(--gold-500);
  box-shadow: 0 14px 34px rgba(192, 152, 96, 0.2);
}

.grade-card .grade-icon { font-size: 2.6rem; margin-bottom: 0.75rem; }

.grade-card h3 {
  font-size: 1.25rem;
  font-weight: 900;
  color: var(--cream-50);
  margin-bottom: 0.35rem;
}

.grade-card p { color: var(--text-muted); font-size: 0.85rem; }

/* ============================================================
   شاشة 2: بداية الامتحان (بيانات الطالب)
   ============================================================ */
.start-screen { padding: 2rem 0 3rem; max-width: 640px; margin: 0 auto; }

.start-card { padding: 2rem; }

.exam-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.85rem;
  margin: 1.25rem 0;
}

.info-box {
  background: rgba(20, 12, 8, 0.55);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  text-align: center;
}
.info-box .label { font-size: 0.7rem; color: var(--text-muted); margin-bottom: 0.3rem; }
.info-box .value { font-size: 1.1rem; font-weight: 900; color: var(--gold-300); }

.status-banner {
  padding: 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.25rem;
  font-weight: 700;
  font-size: 0.9rem;
  border: 1px solid;
}
.status-banner.open { background: rgba(63, 154, 92, 0.14); border-color: rgba(63, 154, 92, 0.4); color: #8fe0a8; }
.status-banner.closed { background: rgba(201, 79, 79, 0.14); border-color: rgba(201, 79, 79, 0.4); color: #f2a3a3; }

.form-field { margin-bottom: 1.1rem; text-align: right; }
.form-field label { display: block; font-weight: 700; margin-bottom: 0.4rem; font-size: 0.9rem; }
.form-field input {
  width: 100%;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: rgba(10, 6, 4, 0.6);
  border: 1px solid var(--border-color);
  color: #fff;
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
}
.form-field input:focus { border-color: var(--gold-500); }
.form-error { display: none; color: #f2a3a3; font-size: 0.8rem; margin-top: 0.3rem; font-weight: 700; }

/* ============================================================
   شاشة الامتحان
   ============================================================ */
.exam-header-bar {
  display: none;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: space-between;
  padding: 0.6rem 0;
}

.timer-badge {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: monospace;
  font-size: 1.2rem;
  font-weight: 900;
  background: rgba(10, 6, 4, 0.75);
  border: 1px solid rgba(192, 152, 96, 0.4);
  padding: 0.4rem 0.9rem;
  border-radius: var(--radius-md);
  color: var(--gold-300);
}
.timer-badge.warning { background: rgba(217, 164, 65, 0.16); border-color: rgba(217,164,65,0.5); color: var(--warning); }
.timer-badge.critical { background: rgba(201, 79, 79, 0.2); border-color: rgba(201,79,79,0.6); color: #f2a3a3; animation: pulseGlow 1.1s infinite; }

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 8px rgba(201,79,79,0.3); }
  50% { box-shadow: 0 0 20px rgba(201,79,79,0.7); }
}

.progress-box { min-width: 160px; display: flex; flex-direction: column; gap: 0.3rem; flex: 1; }
.progress-info { display: flex; justify-content: space-between; font-size: 0.72rem; font-weight: 700; color: var(--text-muted); }

/* أرقام على شكل "١ / ١٥" لازم تتفرض LTR، وإلا خوارزمية اتجاه النص (bidi)
   بتقلب ترتيب الرقمين شكليًا جوه صفحة RTL (مثلاً 1/15 بتظهر 15/1) */
.ltr-nums { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.progress-track { width: 100%; height: 8px; background: rgba(255,255,255,0.08); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--brown-700), var(--gold-500)); border-radius: 999px; transition: width 0.3s ease; }

.main-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 1.25rem;
  margin-top: 1.25rem;
  margin-bottom: 3rem;
}
@media (max-width: 900px) { .main-layout { grid-template-columns: 1fr; } }

.question-card { padding: 1.75rem; display: flex; flex-direction: column; gap: 1.4rem; }

.question-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.9rem;
}

.question-num-tag {
  background: rgba(192, 152, 96, 0.16);
  color: var(--gold-300);
  font-weight: 800;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  font-size: 0.82rem;
  border: 1px solid rgba(192, 152, 96, 0.3);
}

.question-text { font-size: 1.1rem; font-weight: 700; color: var(--cream-50); line-height: 1.85; }

.options-list { display: flex; flex-direction: column; gap: 0.75rem; }

.option-btn {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.15rem;
  background: rgba(10, 6, 4, 0.5);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--cream-100);
  font-size: 0.93rem;
  font-weight: 600;
  cursor: pointer;
  text-align: right;
  transition: all 0.2s ease;
  width: 100%;
}
.option-btn:hover { background: rgba(72, 32, 24, 0.4); border-color: var(--gold-500); color: #fff; }
.option-btn.selected { background: rgba(192, 152, 96, 0.2); border-color: var(--gold-500); color: #fff; box-shadow: 0 0 14px rgba(192, 152, 96, 0.25); }

.option-letter {
  width: 30px; height: 30px; border-radius: 9px;
  background: rgba(255,255,255,0.07);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 0.85rem; flex-shrink: 0; color: var(--text-muted);
}
.option-btn.selected .option-letter { background: var(--gold-500); color: var(--brown-950); }

.question-footer {
  display: flex; justify-content: space-between; gap: 1rem;
  border-top: 1px solid var(--border-color); padding-top: 1rem;
}

.sidebar-grid-card { padding: 1.4rem; height: fit-content; }
.grid-title { font-size: 0.95rem; font-weight: 800; margin-bottom: 1rem; display: flex; align-items: center; justify-content: space-between; }
.question-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.55rem; }

.grid-item {
  aspect-ratio: 1; border-radius: 9px;
  background: rgba(10, 6, 4, 0.7);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-weight: 800; font-size: 0.8rem;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all 0.2s ease;
}
.grid-item:hover { border-color: var(--gold-500); color: #fff; }
.grid-item.answered { background: rgba(63, 154, 92, 0.18); border-color: rgba(63,154,92,0.5); color: #8fe0a8; }
.grid-item.current { border: 2px solid var(--gold-500); box-shadow: 0 0 10px rgba(192,152,96,0.5); color: #fff; }
.grid-item.flagged { background: rgba(217,164,65,0.22); border-color: rgba(217,164,65,0.6); color: var(--warning); }

.legend { margin-top: 1.25rem; border-top: 1px solid var(--border-color); padding-top: 1rem; font-size: 0.72rem; color: var(--text-muted); display: flex; flex-direction: column; gap: 0.4rem; }
.legend-dot { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }

/* ============================================================
   المودالات
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(5, 3, 2, 0.85);
  backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center;
  padding: 1.25rem;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease;
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }

.modal-content {
  width: 100%; max-width: 620px; max-height: 90vh; overflow-y: auto;
  transform: scale(0.96);
  transition: transform 0.25s ease;
  background: var(--bg-card-solid);
  border: 1px solid var(--border-color);
  border-radius: 22px;
}
.modal-overlay.active .modal-content { transform: scale(1); }
.modal-body { padding: 1.75rem; }

.violation-modal .modal-content { border-color: rgba(201,79,79,0.5); text-align: center; }
.violation-modal .icon { font-size: 3rem; margin-bottom: 0.75rem; }
.violation-modal h3 { color: #f2a3a3; font-size: 1.3rem; font-weight: 900; margin-bottom: 0.6rem; }
.violation-modal p { color: var(--text-muted); font-size: 0.9rem; }

/* ============================================================
   شاشة النتيجة
   ============================================================ */
.result-card { text-align: center; padding: 2.25rem 1.5rem; }

.result-badge {
  background: rgba(63,154,92,0.14); color: #8fe0a8;
  padding: 0.35rem 1rem; border-radius: 999px;
  font-weight: 800; font-size: 0.82rem;
  border: 1px solid rgba(63,154,92,0.35);
  display: inline-block;
}

.score-circle {
  width: 150px; height: 150px; border-radius: 50%;
  margin: 1.5rem auto; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: radial-gradient(circle, rgba(192,152,96,0.22) 0%, rgba(20,12,8,0.9) 70%);
  border: 4px solid var(--gold-500);
  box-shadow: 0 0 30px rgba(192,152,96,0.35);
}
.score-num { font-size: 2.1rem; font-weight: 900; color: #fff; }
.score-total { font-size: 0.82rem; color: var(--text-muted); }

.grade-badge { font-size: 1.15rem; font-weight: 900; margin-bottom: 1.4rem; }

.closing-note {
  margin-top: 2rem;
  padding: 1.5rem;
  background: rgba(192,152,96,0.08);
  border: 1px solid rgba(192,152,96,0.25);
  border-radius: var(--radius-md);
  color: var(--cream-100);
  font-size: 0.95rem;
  text-align: center;
  line-height: 1.9;
}
.closing-note .signature { margin-top: 0.6rem; font-weight: 900; color: var(--gold-300); }

.review-item {
  background: rgba(10,6,4,0.55);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.1rem; margin-bottom: 0.9rem; text-align: right;
}
.review-item.correct { border-right: 4px solid var(--success); }
.review-item.wrong { border-right: 4px solid var(--danger); }

/* ============================================================
   تنبيه فتح أدوات المطور
   ============================================================ */
.devtools-banner {
  position: fixed; bottom: 0; right: 0; left: 0; z-index: 200;
  background: var(--danger); color: #fff; text-align: center;
  padding: 0.75rem; font-weight: 800; font-size: 0.85rem;
}

footer {
  text-align: center; padding: 2rem 0; color: var(--text-muted);
  font-size: 0.8rem; border-top: 1px solid var(--border-color); margin-top: 2rem;
}
footer .disclaimer { max-width: 640px; margin: 0.75rem auto 0; font-size: 0.72rem; opacity: 0.75; }

.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: var(--gold-500);
  animation: spin 0.8s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media print {
  body { background: #fff !important; color: #000 !important; }
  .no-print { display: none !important; }
  .glass-card, .review-item { background: #fff !important; color: #000 !important; border: 1px solid #ddd !important; box-shadow: none !important; }
}
