:root {
  --primary: #5B3DF5;
  --secondary: #00D9C0;
  --accent: #FFC93C;
  --danger: #FF5A5F;
  --bg-light: #F7F7FC;
  --bg-dark: #12111A;
  --text-dark: #23213A;
  --text-light: #FFFFFF;
  --radius: 18px;
  --shadow: 0 8px 24px rgba(91, 61, 245, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Tajawal', 'Cairo', 'Segoe UI', sans-serif;
  background: var(--bg-light);
  color: var(--text-dark);
  direction: rtl;
  -webkit-tap-highlight-color: transparent;
}

body.dark {
  background: var(--bg-dark);
  color: var(--text-light);
}

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: 80px;
  position: relative;
  background: inherit;
}

/* ===== شريط علوي ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--primary);
  color: #fff;
  border-radius: 0 0 var(--radius) var(--radius);
}
.topbar .stat {
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
  font-size: 14px;
  background: rgba(255,255,255,0.15);
  padding: 6px 10px;
  border-radius: 20px;
}
.topbar .level-badge {
  background: var(--accent);
  color: var(--text-dark);
  font-weight: 800;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
}
.xp-bar-wrap {
  padding: 0 16px;
  margin-top: -6px;
}
.xp-bar-bg {
  height: 8px;
  background: rgba(255,255,255,0.25);
  border-radius: 10px;
  overflow: hidden;
}
.xp-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 10px;
  transition: width .4s ease;
}

/* ===== محتوى ===== */
.content { padding: 16px; }

.card {
  background: #fff;
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
body.dark .card { background: #1D1B2A; }

.daily-challenge-card {
  background: linear-gradient(135deg, var(--primary), #8B6BFF);
  color: #fff;
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.daily-challenge-card h3 { margin: 0 0 6px; font-size: 16px; }
.daily-challenge-card p { margin: 0 0 12px; font-size: 13px; opacity: .9; }

.btn {
  display: inline-block;
  border: none;
  border-radius: 14px;
  padding: 12px 20px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: transform .1s ease;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--accent); color: var(--text-dark); }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-outline { background: transparent; border: 2px solid #fff; color: #fff; }
.btn-block { display: block; width: 100%; }
.btn-danger { background: var(--danger); color: #fff; }

/* ===== شبكة الألعاب ===== */
.games-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.game-tile {
  background: #fff;
  border-radius: var(--radius);
  padding: 14px 8px;
  text-align: center;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text-dark);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
body.dark .game-tile { background: #1D1B2A; color: var(--text-light); }
.game-tile .icon { font-size: 28px; }
.game-tile .name { font-size: 12px; font-weight: 700; }

/* ===== أسفل التنقل ===== */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  max-width: 480px;
  margin: 0 auto;
  background: #fff;
  display: flex;
  justify-content: space-around;
  padding: 10px 0 14px;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.08);
  border-radius: var(--radius) var(--radius) 0 0;
}
body.dark .bottom-nav { background: #1D1B2A; }
.bottom-nav a {
  text-decoration: none;
  color: #9A98B5;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.bottom-nav a.active { color: var(--primary); font-weight: 800; }
.bottom-nav a .icon { font-size: 20px; }

/* ===== نماذج تسجيل الدخول ===== */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--primary), #2C1E8C);
  color: #fff;
}
.auth-wrap h1 { text-align: center; font-size: 30px; margin-bottom: 4px; }
.auth-wrap p.tagline { text-align: center; opacity: .85; margin-bottom: 28px; }
.input-field {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: none;
  margin-bottom: 12px;
  font-size: 14px;
  background: rgba(255,255,255,0.15);
  color: #fff;
}
.input-field::placeholder { color: rgba(255,255,255,0.7); }

/* ===== شاشة اللعب ===== */
.puzzle-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
}
.puzzle-topbar .timer { font-weight: 800; font-size: 18px; color: var(--danger); }
.game-board {
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

/* ===== النتيجة (فوز/خسارة) ===== */
.result-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: #fff;
}
.result-screen.win { background: linear-gradient(160deg, #00D9C0, #1AA98F); }
.result-screen.lose { background: linear-gradient(160deg, #5B3DF5, #2C1E8C); }
.result-screen .big-score { font-size: 48px; font-weight: 900; margin: 12px 0; }
.reward-row { display: flex; gap: 12px; justify-content: center; margin: 16px 0 28px; }
.reward-chip {
  background: rgba(255,255,255,0.2);
  padding: 10px 16px;
  border-radius: 14px;
  font-weight: 700;
}

/* ===== عام ===== */
h2.section-title { font-size: 16px; margin: 6px 0 12px; }
.leaderboard-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: 14px;
  margin-bottom: 8px;
  background: #fff;
}
body.dark .leaderboard-row { background: #1D1B2A; }
.leaderboard-row.me { border: 2px solid var(--accent); }
.mission-row {
  padding: 12px 14px;
  border-radius: 14px;
  background: #fff;
  margin-bottom: 10px;
}
body.dark .mission-row { background: #1D1B2A; }
.mission-progress-bg { height: 8px; background: #EDEBFC; border-radius: 8px; overflow: hidden; margin-top: 8px; }
body.dark .mission-progress-bg { background: #2A2840; }
.mission-progress-fill { height: 100%; background: var(--secondary); }

.toast {
  position: fixed;
  bottom: 90px; left: 50%;
  transform: translateX(-50%);
  background: var(--text-dark);
  color: #fff;
  padding: 10px 18px;
  border-radius: 14px;
  font-size: 13px;
  z-index: 999;
  opacity: 0;
  transition: opacity .3s ease;
}
.toast.show { opacity: 1; }
