/* =========================================================
   Sport IQ — Base Styles
   الأنماط الأساسية للتطبيق: RTL، Reset، Typography، Layout
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;500;600;700;900&family=IBM+Plex+Sans+Arabic:wght@300;400;500;600;700&display=swap');

/* -------------------------------------------------------
   CSS Reset
   ------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* -------------------------------------------------------
   HTML & Body — الأساس
   ------------------------------------------------------- */
html {
  direction: rtl;          /* RTL كامل للتطبيق */
  lang: ar;
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  color-scheme: dark;
}

body {
  font-family: var(--font-arabic);
  font-size: var(--text-base);
  font-weight: var(--font-regular);
  line-height: var(--leading-normal);
  color: var(--color-text-primary);
  background-color: var(--color-bg-primary);
  background-image: var(--gradient-bg);
  min-height: 100vh;
  min-height: 100dvh;    /* dynamic viewport height للموبايل */
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* منع تحديد النص العرضي في ألعاب الأسئلة */
  -webkit-user-select: none;
  user-select: none;
}

/* السماح بتحديد النص في المحتوى القرائي */
p, .selectable, input, textarea {
  -webkit-user-select: text;
  user-select: text;
}

/* -------------------------------------------------------
   Container الرئيسي — Mobile-first مع حد أقصى
   ------------------------------------------------------- */
.app-container {
  width: 100%;
  max-width: var(--app-max-width);
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  background-color: var(--color-bg-primary);
  /* ظل جانبي للتفريق في شاشات الديسكتوب الكبيرة */
  box-shadow: -8px 0 48px rgba(0,0,0,0.5), 8px 0 48px rgba(0,0,0,0.5);
}

/* خلفية الديسكتوب خلف الـ Container */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(123,47,247,0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(177,78,255,0.05) 0%, transparent 50%),
    var(--color-bg-primary);
  z-index: -1;
}

/* -------------------------------------------------------
   Page Layout — هيكل الصفحة العامة
   ------------------------------------------------------- */
.page {
  padding-top: var(--header-height);
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom));
  min-height: 100vh;
  min-height: 100dvh;
}

.page--no-header {
  padding-top: 0;
}

.page--no-nav {
  padding-bottom: 0;
}

/* -------------------------------------------------------
   Header الصفحة
   ------------------------------------------------------- */
.page-header {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  height: var(--header-height);
  max-width: var(--app-max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-4);
  background: rgba(10, 6, 18, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--color-divider);
  z-index: var(--z-sticky);
}

.page-header__logo {
  font-size: var(--text-xl);
  font-weight: var(--font-black);
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-decoration: none;
}

.page-header__title {
  font-size: var(--text-lg);
  font-weight: var(--font-bold);
  color: var(--color-text-primary);
}

.page-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* -------------------------------------------------------
   Typography — النصوص
   ------------------------------------------------------- */
h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-bold);
  line-height: var(--leading-tight);
  color: var(--color-text-primary);
}

h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-base); }
h6 { font-size: var(--text-sm); }

p {
  color: var(--color-text-secondary);
  line-height: var(--leading-loose);
}

a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--color-primary-to);
}

/* -------------------------------------------------------
   القائمة
   ------------------------------------------------------- */
ul, ol {
  list-style: none;
}

/* -------------------------------------------------------
   الصور
   ------------------------------------------------------- */
img {
  display: block;
  max-width: 100%;
  height: auto;
}

/* -------------------------------------------------------
   الأزرار
   ------------------------------------------------------- */
button {
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  border: none;
  background: none;
  color: inherit;
  padding: 0;
  transition: var(--transition-base);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* الزر الأساسي */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-full);
  font-family: var(--font-arabic);
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  transition: var(--transition-base);
  position: relative;
  overflow: hidden;
  white-space: nowrap;
}

.btn--primary {
  background: var(--gradient-primary);
  color: white;
  box-shadow: var(--glow-primary);
}

.btn--primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 30px var(--color-primary-glow), 0 0 60px rgba(155,63,255,0.25);
}

.btn--primary:active {
  transform: translateY(0);
}

.btn--gold {
  background: var(--gradient-gold);
  color: var(--color-text-inverse);
  font-weight: var(--font-bold);
  box-shadow: var(--glow-gold);
}

.btn--gold:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 30px var(--color-gold-glow), 0 0 60px rgba(255,191,0,0.25);
}

.btn--outline {
  background: transparent;
  border: 1.5px solid var(--color-border-strong);
  color: var(--color-text-primary);
}

.btn--outline:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  color: var(--color-primary-to);
}

.btn--ghost {
  background: transparent;
  color: var(--color-text-secondary);
}

.btn--ghost:hover {
  background: rgba(255,255,255,0.06);
  color: var(--color-text-primary);
}

.btn--danger {
  background: var(--gradient-danger);
  color: white;
  box-shadow: var(--glow-danger);
}

.btn--success {
  background: var(--gradient-success);
  color: white;
  box-shadow: var(--glow-success);
}

.btn--sm {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
}

.btn--lg {
  padding: var(--space-4) var(--space-8);
  font-size: var(--text-lg);
}

.btn--full {
  width: 100%;
}

.btn--icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-md);
  flex-shrink: 0;
}

.btn--icon-round {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

/* تأثير Ripple على الأزرار */
.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(255,255,255,0.2) 0%, transparent 70%);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.btn:active::after {
  opacity: 1;
}

/* -------------------------------------------------------
   الإدخالات (Forms)
   ------------------------------------------------------- */
input, textarea, select {
  font-family: var(--font-arabic);
  font-size: var(--text-base);
  color: var(--color-text-primary);
  background: rgba(255, 255, 255, 0.06);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  width: 100%;
  outline: none;
  transition: var(--transition-base);
  direction: rtl;
}

input::placeholder, textarea::placeholder {
  color: var(--color-text-muted);
}

input:focus, textarea:focus, select:focus {
  border-color: var(--color-primary);
  background: rgba(155, 63, 255, 0.08);
  box-shadow: 0 0 0 3px rgba(155, 63, 255, 0.15);
}

/* -------------------------------------------------------
   البطاقات (Cards)
   ------------------------------------------------------- */
.card {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--glass-shadow);
  transition: var(--transition-base);
}

.card:hover {
  border-color: var(--color-border-strong);
  box-shadow: var(--glow-card-hover);
}

.card--gold {
  border-color: rgba(255, 191, 0, 0.3);
  background: linear-gradient(145deg, rgba(255,191,0,0.08) 0%, var(--glass-bg) 100%);
}

/* -------------------------------------------------------
   الشارات (Badges)
   ------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.2rem var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  white-space: nowrap;
}

.badge--primary {
  background: var(--color-primary-light);
  color: var(--color-primary-to);
  border: 1px solid rgba(155,63,255,0.3);
}

.badge--gold {
  background: var(--color-gold-light);
  color: var(--color-gold);
  border: 1px solid rgba(255,191,0,0.3);
}

.badge--success {
  background: var(--color-success-light);
  color: var(--color-success);
}

.badge--danger {
  background: var(--color-danger-light);
  color: var(--color-danger);
}

.badge--live {
  background: var(--color-danger);
  color: white;
  animation: pulse-badge 1.5s ease-in-out infinite;
}

/* -------------------------------------------------------
   التبويبات (Tabs)
   ------------------------------------------------------- */
.tabs {
  display: flex;
  gap: var(--space-1);
  padding: var(--space-1);
  background: rgba(255,255,255,0.05);
  border-radius: var(--radius-xl);
  border: 1px solid var(--color-divider);
}

.tabs--scroll {
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  border-radius: var(--radius-lg);
  background: transparent;
  border: none;
  gap: var(--space-2);
  padding: 0;
}

.tabs--scroll::-webkit-scrollbar {
  display: none;
}

.tab {
  flex: 1;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--color-text-muted);
  transition: var(--transition-base);
  text-align: center;
  white-space: nowrap;
  cursor: pointer;
}

.tab--active {
  background: var(--gradient-primary);
  color: white;
  font-weight: var(--font-semibold);
  box-shadow: var(--glow-primary);
}

.tabs--scroll .tab {
  flex: none;
  padding: var(--space-2) var(--space-5);
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-full);
}

.tabs--scroll .tab--active {
  background: var(--gradient-primary);
  border-color: transparent;
}

/* -------------------------------------------------------
   الفاصل (Divider)
   ------------------------------------------------------- */
.divider {
  height: 1px;
  background: var(--color-divider);
  margin: var(--space-4) 0;
}

/* -------------------------------------------------------
   Avatar
   ------------------------------------------------------- */
.avatar {
  border-radius: var(--radius-full);
  overflow: hidden;
  background: var(--color-bg-tertiary);
  flex-shrink: 0;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar--sm  { width: 32px;  height: 32px; }
.avatar--md  { width: 40px;  height: 40px; }
.avatar--lg  { width: 48px;  height: 48px; }
.avatar--xl  { width: 64px;  height: 64px; }
.avatar--2xl { width: 80px;  height: 80px; }

.avatar--ring {
  box-shadow: 0 0 0 2.5px var(--color-bg-primary), 0 0 0 4px var(--color-primary);
}

.avatar--ring-gold {
  box-shadow: 0 0 0 2.5px var(--color-bg-primary), 0 0 0 4px var(--color-gold);
}

/* -------------------------------------------------------
   شاشة التحميل (Loading States)
   ------------------------------------------------------- */
.skeleton {
  background: linear-gradient(90deg,
    rgba(255,255,255,0.04) 25%,
    rgba(255,255,255,0.08) 50%,
    rgba(255,255,255,0.04) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-md);
}

/* -------------------------------------------------------
   الحالات الخاصة
   ------------------------------------------------------- */

/* حالة فارغة */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-12) var(--space-6);
  text-align: center;
}

.empty-state__icon {
  font-size: 3rem;
  opacity: 0.4;
  filter: grayscale(0.5);
}

.empty-state__title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--color-text-secondary);
}

.empty-state__desc {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  max-width: 260px;
}

/* حالة خطأ */
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-8) var(--space-4);
  text-align: center;
}

.error-state__icon {
  font-size: 2.5rem;
  color: var(--color-danger);
  opacity: 0.7;
}

.error-state__message {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* -------------------------------------------------------
   شريط التنقل السفلي
   ------------------------------------------------------- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  right: 0;
  left: 0;
  max-width: var(--app-max-width);
  margin: 0 auto;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(10, 6, 18, 0.95);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--color-divider);
  display: flex;
  align-items: flex-start;
  justify-content: space-around;
  z-index: var(--z-nav);
  padding-top: var(--space-2);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  font-size: 10px;
  font-weight: var(--font-medium);
  transition: var(--transition-base);
  cursor: pointer;
  text-decoration: none;
  flex: 1;
}

.nav-item__icon {
  width: 24px;
  height: 24px;
  transition: var(--transition-spring);
}

.nav-item--active {
  color: var(--color-primary-to);
}

.nav-item--active .nav-item__icon {
  transform: scale(1.1);
  filter: drop-shadow(0 0 6px var(--color-primary-glow));
}

/* زر اللعب في المنتصف (أكبر) */
.nav-item--play {
  position: relative;
  margin-top: -20px;
}

.nav-item--play .nav-item__play-btn {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-full);
  background: var(--gradient-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--glow-primary);
  transition: var(--transition-spring);
}

.nav-item--play:hover .nav-item__play-btn,
.nav-item--play.nav-item--active .nav-item__play-btn {
  transform: scale(1.1);
  box-shadow: 0 0 30px var(--color-primary-glow);
}

/* -------------------------------------------------------
   Section Headers
   ------------------------------------------------------- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-4) var(--space-3);
}

.section-title {
  font-size: var(--text-lg);
  font-weight: var(--font-bold);
  color: var(--color-text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.section-title::before {
  content: '';
  width: 4px;
  height: 18px;
  background: var(--gradient-primary);
  border-radius: 2px;
  display: inline-block;
}

.section-link {
  font-size: var(--text-sm);
  color: var(--color-primary-to);
  font-weight: var(--font-medium);
}

/* -------------------------------------------------------
   شريط التمرير المخصص
   ------------------------------------------------------- */
::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--color-primary-light);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-primary);
}

/* -------------------------------------------------------
   Modal الأساسي
   ------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 3, 12, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  animation: modal-fade-in var(--transition-base) ease;
}

.modal-overlay--center {
  align-items: center;
  padding: var(--space-4);
}

.modal {
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
  width: 100%;
  max-width: var(--app-max-width);
  max-height: 90vh;
  overflow-y: auto;
  animation: modal-slide-up var(--transition-slow) cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal--center {
  border-radius: var(--radius-2xl);
  max-height: 85vh;
}

.modal__handle {
  width: 36px;
  height: 4px;
  background: var(--color-text-disabled);
  border-radius: var(--radius-full);
  margin: var(--space-3) auto;
}

.modal__header {
  padding: var(--space-4) var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--color-divider);
}

.modal__title {
  font-size: var(--text-xl);
  font-weight: var(--font-bold);
}

.modal__body {
  padding: var(--space-6);
}

.modal__footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-divider);
  display: flex;
  gap: var(--space-3);
}

/* -------------------------------------------------------
   شاشة تحميل أولي (Splash)
   ------------------------------------------------------- */
.splash-screen {
  position: fixed;
  inset: 0;
  background: var(--color-bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  gap: var(--space-4);
}

.splash-logo {
  font-size: 3rem;
  font-weight: var(--font-black);
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -2px;
}

.splash-loader {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-primary-light);
  border-top-color: var(--color-primary);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
}

/* -------------------------------------------------------
   الأيقونات SVG الأساسية (Inline)
   ------------------------------------------------------- */
.icon {
  display: inline-block;
  vertical-align: middle;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon--filled {
  fill: currentColor;
  stroke: none;
}

.icon--xs  { width: 14px; height: 14px; }
.icon--sm  { width: 18px; height: 18px; }
.icon--md  { width: 22px; height: 22px; }
.icon--lg  { width: 26px; height: 26px; }
.icon--xl  { width: 32px; height: 32px; }

/* -------------------------------------------------------
   شريط التقدم (Progress Bar)
   ------------------------------------------------------- */
.progress-bar {
  height: 6px;
  background: rgba(255,255,255,0.08);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar__fill {
  height: 100%;
  background: var(--gradient-primary);
  border-radius: var(--radius-full);
  transition: width var(--transition-base);
}

.progress-bar--gold .progress-bar__fill {
  background: var(--gradient-gold);
}

.progress-bar--success .progress-bar__fill {
  background: var(--gradient-success);
}

/* -------------------------------------------------------
   أرقام الرصيد (Points & Diamonds)
   ------------------------------------------------------- */
.balance-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  background: rgba(255,255,255,0.07);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
}

.balance-chip--points {
  color: var(--color-primary-to);
  border-color: rgba(155,63,255,0.2);
}

.balance-chip--diamonds {
  color: var(--color-gold);
  border-color: rgba(255,191,0,0.2);
}

/* -------------------------------------------------------
   Utility Classes
   ------------------------------------------------------- */
.text-primary   { color: var(--color-text-primary); }
.text-secondary { color: var(--color-text-secondary); }
.text-muted     { color: var(--color-text-muted); }
.text-success   { color: var(--color-success); }
.text-danger    { color: var(--color-danger); }
.text-gold      { color: var(--color-gold); }
.text-purple    { color: var(--color-primary-to); }
.text-center    { text-align: center; }
.text-start     { text-align: right; }  /* RTL: start = right */
.text-end       { text-align: left; }   /* RTL: end = left */

.font-bold    { font-weight: var(--font-bold); }
.font-semibold { font-weight: var(--font-semibold); }
.font-medium  { font-weight: var(--font-medium); }

.text-xs  { font-size: var(--text-xs); }
.text-sm  { font-size: var(--text-sm); }
.text-lg  { font-size: var(--text-lg); }
.text-xl  { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }

.flex         { display: flex; }
.flex-col     { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center  { justify-content: center; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

.p-4  { padding: var(--space-4); }
.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }
.py-3 { padding-top: var(--space-3); padding-bottom: var(--space-3); }
.py-4 { padding-top: var(--space-4); padding-bottom: var(--space-4); }
.mt-4 { margin-top: var(--space-4); }
.mb-4 { margin-bottom: var(--space-4); }

.w-full { width: 100%; }
.hidden { display: none !important; }

.gradient-text {
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.gold-text {
  background: var(--gradient-gold);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* -------------------------------------------------------
   الاستجابة (Responsive) — تابلت وديسكتوب
   ------------------------------------------------------- */
@media (min-width: 768px) {
  :root {
    --text-base: 1.0625rem;
    --app-max-width: 480px;
  }
}

/* -------------------------------------------------------
   Safe Area — iPhone notch
   ------------------------------------------------------- */
@supports (padding: max(0px)) {
  .page-header {
    padding-top: max(0px, env(safe-area-inset-top));
  }
}
