/* ============================================================
   main.css - الأنماط العامة والتخطيط الرئيسي
   ============================================================ */

/* --- متغيرات الألوان --- */
:root {
  --primary:   #f67c5f;
  --primary-h: #f65e3b;
  --secondary: #edc22e;
  --bg:        #faf8f0;
  --bg-card:   #fff9f0;
  --board-bg:  #bbada0;
  --text:      #776e65;
  --text-dark: #3c3a32;
  --text-light:#999;
  --success:   #6aaa64;
  --danger:    #e07070;
  --gold:      #f0b429;
  --radius:    12px;
  --shadow:    0 4px 20px rgba(0,0,0,.12);
  --shadow-sm: 0 2px 8px rgba(0,0,0,.08);
  --transition: .2s ease;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* --- إعادة ضبط عامة --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  direction: rtl;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-dark);
  min-height: 100vh;
  line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; }

/* ============================================================
   الأزرار
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: 2px solid transparent;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  font-family: var(--font);
  line-height: 1;
}

.btn-primary   { background: var(--primary);   color: #fff; }
.btn-primary:hover { background: var(--primary-h); }

.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover { filter: brightness(.92); }

.btn-outline   { background: transparent; border-color: var(--primary); color: var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }

.btn-ghost     { background: transparent; color: var(--text); border-color: transparent; }
.btn-ghost:hover { background: rgba(0,0,0,.06); }

.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.9); }

.btn-block     { width: 100%; }
.btn-large     { padding: 14px 28px; font-size: 17px; border-radius: 12px; }
.btn-sm        { padding: 6px 12px; font-size: 13px; }
.btn-icon      { padding: 8px; width: 40px; height: 40px; border-radius: 50%; font-size: 18px; }

.btn:disabled  { opacity: .4; cursor: not-allowed; }

/* ============================================================
   التخطيط العام
   ============================================================ */
.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

#app { min-height: 100vh; }

/* ============================================================
   رأس الموقع (الصفحة الرئيسية)
   ============================================================ */
.site-header {
  background: var(--board-bg);
  padding: 12px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.logo {
  display: flex;
  gap: 4px;
}

.logo-tile {
  width: 36px; height: 36px;
  background: #eee4da;
  color: var(--text-dark);
  font-weight: 900;
  font-size: 18px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.logo-tile.t4  { background: #ede0c8; }
.logo-tile.t8  { background: #f2b179; color: #f9f6f2; }

.header-nav {
  display: flex;
  gap: 8px;
  align-items: center;
}

.nav-user {
  font-size: 14px;
  color: var(--text-dark);
  font-weight: 600;
}

/* ============================================================
   الصفحة الرئيسية
   ============================================================ */
.home-main {
  flex: 1;
  max-width: 1000px;
  margin: 0 auto;
  padding: 30px 20px 60px;
  width: 100%;
}

.hero {
  text-align: center;
  padding: 50px 20px 40px;
}

.hero-title {
  font-size: clamp(2.2rem, 6vw, 3.5rem);
  font-weight: 900;
  color: var(--text-dark);
  margin-bottom: 16px;
}

.highlight { color: var(--primary); }

.hero-desc {
  font-size: clamp(1rem, 2.5vw, 1.2rem);
  color: var(--text);
  max-width: 500px;
  margin: 0 auto 30px;
}

.hero-actions {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
}

/* بطاقات الميزات */
.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 18px;
  margin: 40px 0;
}

.feature-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px 18px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.feature-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }

.feature-icon { font-size: 2.4rem; margin-bottom: 10px; }
.feature-card h3 { font-size: 1.05rem; color: var(--text-dark); margin-bottom: 6px; }
.feature-card p  { font-size: .9rem; color: var(--text); }

/* كيف تلعب */
.how-to-play {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 30px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 30px;
}

.how-to-play h2 {
  font-size: 1.4rem;
  text-align: center;
  margin-bottom: 20px;
  color: var(--text-dark);
}

.steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
}

.step {
  display: flex;
  align-items: center;
  gap: 12px;
}

.step-num {
  width: 36px; height: 36px;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px;
  flex-shrink: 0;
}

.step p { font-size: .9rem; color: var(--text); }

/* فوتر */
.site-footer {
  text-align: center;
  padding: 20px;
  color: var(--text-light);
  font-size: .85rem;
  background: var(--board-bg);
  color: #f9f6f2;
}

/* ============================================================
   صفحة المصادقة (تسجيل الدخول / إنشاء حساب)
   ============================================================ */
.auth-page {
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 30px 16px;
}

.auth-card {
  background: #fff;
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 36px 32px;
  width: 100%;
  max-width: 400px;
}

.auth-logo {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-bottom: 20px;
}

.auth-title {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-dark);
  margin-bottom: 24px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-dark);
}

.form-group input {
  padding: 12px 14px;
  border: 2px solid #e0d8cf;
  border-radius: 10px;
  font-size: 15px;
  font-family: var(--font);
  transition: var(--transition);
  color: var(--text-dark);
  direction: ltr;
  text-align: right;
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(246,124,95,.15);
}

.form-error {
  color: var(--danger);
  font-size: .88rem;
  min-height: 20px;
  font-weight: 600;
}

.auth-links {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: center;
  font-size: .9rem;
  color: var(--text);
}

/* ============================================================
   صفحة اللعب
   ============================================================ */
.game-page {
  background: var(--bg);
}

.game-header {
  background: var(--board-bg);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.game-title-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.game-title-logo {
  font-size: 1.5rem;
  font-weight: 900;
  color: #f9f6f2;
}

.status-bar {
  font-size: .8rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 20px;
}

.status-info  { background: rgba(255,255,255,.2); color: #f9f6f2; }
.status-warn  { background: rgba(246,124,95,.3);  color: #fff3e0; }
.status-win   { background: rgba(106,170,100,.4); color: #e8f5e9; }
.status-over  { background: rgba(224,112,112,.4); color: #ffebee; }

.header-user-btns { display: flex; gap: 6px; align-items: center; }

/* تخطيط صفحة اللعب */
.game-layout {
  display: flex;
  gap: 20px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

.game-sidebar {
  width: 200px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-info h3 {
  font-size: .95rem;
  color: var(--text-dark);
  margin-bottom: 8px;
  font-weight: 700;
}

.sidebar-info ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-info ul li {
  font-size: .85rem;
  color: var(--text);
}

.game-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

/* اختيار الوضع */
.mode-selector {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 480px;
}

.mode-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 8px;
  background: var(--bg-card);
  border: 2px solid #e0d8cf;
  border-radius: 10px;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font);
}

.mode-btn:hover { border-color: var(--primary); }
.mode-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.mode-name  { font-size: .9rem; font-weight: 700; }
.mode-label { font-size: .75rem; opacity: .8; }
.mode-best  { font-size: .7rem; opacity: .75; }

/* لوحة النقاط */
.score-panel {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 480px;
}

.score-card {
  flex: 1;
  background: var(--board-bg);
  border-radius: 10px;
  padding: 10px 12px;
  text-align: center;
}

.score-label { font-size: .72rem; color: #f0e6d2; font-weight: 600; text-transform: uppercase; }
.score-value { font-size: 1.4rem; font-weight: 900; color: #fff; }

/* شريط XP */
.level-bar-wrap {
  width: 100%;
  max-width: 480px;
  background: var(--bg-card);
  border-radius: 10px;
  padding: 10px 14px;
  box-shadow: var(--shadow-sm);
}

.level-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.level-badge {
  background: var(--secondary);
  color: #fff;
  font-size: .8rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 20px;
}

.level-title { font-size: .85rem; font-weight: 600; color: var(--text-dark); }
.level-xp    { font-size: .78rem; color: var(--text); margin-right: auto; }

.level-bar-bg {
  height: 10px;
  background: #e0d8cf;
  border-radius: 5px;
  overflow: hidden;
}

.level-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--secondary), var(--primary));
  border-radius: 5px;
  transition: width .5s ease;
}

/* لوحة اللعبة */
.board-wrapper {
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 4px;
}

/* أزرار التحكم المرئية */
.mobile-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
  max-width: 200px;
}

.ctrl-row {
  display: flex;
  gap: 6px;
}

.ctrl-btn {
  width: 56px; height: 56px;
  background: var(--board-bg);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 1.4rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font);
}

.ctrl-btn:hover  { background: var(--text-dark); }
.ctrl-btn:active { transform: scale(.92); }

/* أزرار الإجراءات */
.game-actions {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 480px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ============================================================
   البلاطات
   ============================================================ */
.tile {
  transition: transform .1s ease;
}

.tile-new {
  animation: tileAppear .2s ease forwards;
}

@keyframes tileAppear {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.tile-2048 {
  box-shadow: 0 0 20px rgba(237,194,46,.7);
}

/* ============================================================
   Modal
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  animation: fadeIn .3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-box {
  background: #fff;
  border-radius: 20px;
  padding: 36px 28px;
  text-align: center;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 10px 50px rgba(0,0,0,.3);
  animation: slideUp .3s ease;
}

@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.modal-icon { font-size: 3rem; margin-bottom: 12px; }

.modal-box h2 {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-dark);
  margin-bottom: 8px;
}

.modal-box p {
  color: var(--text);
  margin-bottom: 6px;
  font-size: 1rem;
}

.xp-earned {
  color: var(--secondary);
  font-weight: 700;
  font-size: 1.1rem !important;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 20px;
}

/* ============================================================
   الإعلانات
   ============================================================ */
.ad-box {
  width: 100%;
  border-radius: 10px;
  overflow: hidden;
}

.ad-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px;
  background: linear-gradient(135deg, #f0ece4, #e8e0d5);
  border: 2px dashed #bfb0a0;
  border-radius: 10px;
  text-align: center;
}

.ad-icon  { font-size: 1.6rem; }
.ad-label { font-size: 1rem; font-weight: 800; color: #999; letter-spacing: 2px; text-transform: uppercase; }
.ad-sub   { font-size: .75rem; color: #aaa; }

.ad-header       { margin-bottom: 0; }
.ad-sidebar      { min-height: 200px; }
.ad-bottom       { max-height: 100px; }

/* Interstitial */
.interstitial-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 16px;
}

.interstitial-box {
  background: #fff;
  border-radius: 20px;
  padding: 30px;
  max-width: 360px;
  width: 100%;
  text-align: center;
}

.btn-close-ad {
  margin-top: 16px;
  padding: 10px 24px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
}

/* ============================================================
   Toast
   ============================================================ */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--text-dark);
  color: #fff;
  padding: 12px 24px;
  border-radius: 30px;
  font-size: .95rem;
  font-weight: 600;
  z-index: 9999;
  transition: transform .3s ease, opacity .3s ease;
  opacity: 0;
  white-space: nowrap;
  max-width: 90vw;
  text-align: center;
}

#toast.toast-show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

#toast.toast-success { background: var(--success); }
#toast.toast-warn    { background: #f0a030; }
#toast.toast-error   { background: var(--danger); }
#toast.toast-info    { background: var(--text-dark); }

/* ============================================================
   صفحة الملف الشخصي
   ============================================================ */
.profile-page, .stats-page {
  background: var(--bg);
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--board-bg);
  position: sticky;
  top: 0;
  z-index: 100;
}

.page-header h1 {
  font-size: 1.2rem;
  color: #f9f6f2;
  font-weight: 800;
}

.profile-content, .stats-content {
  max-width: 700px;
  margin: 0 auto;
  padding: 24px 16px 60px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* بطاقة المستخدم */
.profile-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  box-shadow: var(--shadow-sm);
}

.profile-avatar {
  width: 70px; height: 70px;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 800;
  flex-shrink: 0;
}

.profile-name  { font-size: 1.2rem; font-weight: 800; color: var(--text-dark); }
.profile-email { font-size: .85rem; color: var(--text); }

.profile-badge {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
}

/* XP في الملف الشخصي */
.xp-section {
  background: #fff;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.xp-labels {
  display: flex;
  justify-content: space-between;
  font-size: .9rem;
  color: var(--text);
  margin-bottom: 8px;
}

.xp-total {
  text-align: center;
  margin-top: 8px;
  font-size: .9rem;
  color: var(--text);
}

/* إحصائيات */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.stat-box {
  background: #fff;
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.stat-box.green { border-top: 4px solid var(--success); }
.stat-box.red   { border-top: 4px solid var(--danger); }
.stat-box.gold  { border-top: 4px solid var(--gold); }

.stat-num { font-size: 2rem; font-weight: 900; color: var(--text-dark); }
.stat-lbl { font-size: .82rem; color: var(--text); margin-top: 4px; }

/* جداول */
.profile-section, .stats-section {
  background: #fff;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.profile-section h3, .stats-section h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 14px;
}

.scores-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}

.scores-table th, .scores-table td {
  padding: 10px 12px;
  text-align: center;
  border-bottom: 1px solid #f0ece4;
}

.scores-table th {
  font-weight: 700;
  color: var(--text);
  font-size: .82rem;
  text-transform: uppercase;
}

.scores-table tr:last-child td { border-bottom: none; }
.scores-table tr:hover td { background: #faf8f0; }

.table-scroll { overflow-x: auto; }

.badge-win  { color: var(--success); font-weight: 700; }
.badge-loss { color: var(--danger); font-weight: 700; }

.empty-msg {
  text-align: center;
  color: var(--text);
  padding: 30px;
  font-size: 1rem;
}

.profile-actions, .stats-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
