:root{
  --sand-50:#FBF6EC;
  --sand-100:#F4EBD9;
  --sand-200:#E8DABF;
  --sand-300:#D9C49E;
  --ink:#241C14;
  --ink-2:#3A2E22;
  --muted:#8A7A63;
  --gold:#B8873B;
  --gold-2:#DDB46A;
  --gold-3:#F3E2C2;
  --clay:#A9502F;
  --night:#1D1710;
  --radius:18px;
  --shadow-sm:0 1px 2px rgba(36,28,20,.06), 0 10px 28px rgba(36,28,20,.06);
}

*{box-sizing:border-box}
html,body{margin:0;padding:0}
body{
  font-family:'Tajawal',system-ui,-apple-system,'Segoe UI',sans-serif;
  background:var(--sand-50);
  color:var(--ink);
  line-height:1.65;
  min-height:100dvh;
  -webkit-font-smoothing:antialiased;
  text-rendering:optimizeLegibility;
}
body::before{
  content:"";
  position:fixed;inset:0;z-index:0;pointer-events:none;
  background-image:radial-gradient(circle at 1px 1px, rgba(184,135,59,.17) 1px, transparent 0);
  background-size:22px 22px;
  opacity:.8;
}
body.lock{overflow:hidden}

h1,h2,h3{font-family:'Amiri',Georgia,serif;font-weight:700;line-height:1.3;margin:0}
p{margin:0}
button{font-family:inherit;color:inherit;cursor:pointer;border:0;background:none;user-select:none;-webkit-user-select:none}
input{font-family:inherit}

.shell{
  position:relative;z-index:1;
  max-width:1060px;margin:0 auto;
  padding:0 16px 40px;
}

/* ============ الشريط العلوي ============ */
.topbar{
  position:sticky;top:0;z-index:30;
  display:flex;align-items:center;justify-content:space-between;gap:12px;
  padding:10px 0 12px;
  background:linear-gradient(180deg, rgba(251,246,236,.97) 60%, rgba(251,246,236,.75));
  backdrop-filter:blur(12px);
  -webkit-backdrop-filter:blur(12px);
}
.brand{display:flex;align-items:center;gap:10px}
.brand-mark{
  width:42px;height:42px;flex:0 0 42px;
  display:grid;place-items:center;
  border-radius:14px;
  background:linear-gradient(160deg,#332619,#1D1710);
  color:var(--gold-2);
  box-shadow:0 6px 16px rgba(29,23,16,.22), inset 0 1px 0 rgba(255,255,255,.1);
}
.brand-mark svg{width:22px;height:22px}
.brand-text{display:flex;flex-direction:column;line-height:1.15}
.brand-text strong{font-family:'Amiri',serif;font-size:21px;letter-spacing:0}
.brand-text small{font-size:12px;color:var(--muted);font-weight:500}

.icon-btn{
  width:46px;height:46px;flex:0 0 46px;
  display:grid;place-items:center;
  border-radius:14px;
  background:#FFFDF8;
  border:1px solid var(--sand-200);
  color:var(--ink-2);
  transition:transform .16s ease, border-color .16s ease, background .16s ease;
}
.icon-btn svg{width:23px;height:23px}
.icon-btn:hover{border-color:var(--gold-2);background:#FFF9EC}
.icon-btn:active{transform:scale(.94)}
.icon-btn:focus-visible{outline:3px solid rgba(184,135,59,.45);outline-offset:2px}

/* ============ الواجهة الرئيسية ============ */
.hero{
  position:relative;
  overflow:hidden;
  border-radius:26px;
  padding:26px 22px 24px;
  background-color:var(--night);
  background-image:url('assets/hero.png'), linear-gradient(165deg,#2E2318 0%,#1D1710 60%,#14100B 100%);
  background-size:cover, cover;
  background-position:center 62%, center;
  background-repeat:no-repeat, no-repeat;
  color:#FBF6EC;
  box-shadow:var(--shadow-sm);
  isolation:isolate;
}
.hero-veil{
  position:absolute;inset:0;z-index:0;
  background:linear-gradient(180deg, rgba(20,15,10,.55) 0%, rgba(20,15,10,.80) 55%, rgba(20,15,10,.94) 100%);
}
.hero-inner{position:relative;z-index:1}
.eyebrow{
  display:inline-block;
  font-size:11.5px;font-weight:700;letter-spacing:.14em;
  color:var(--gold-2);
  text-transform:uppercase;
  margin-bottom:8px;
  padding:4px 12px;
  border:1px solid rgba(221,180,106,.42);
  border-radius:999px;
}
.hero-title{
  font-size:34px;
  color:#FDF6E8;
  margin-bottom:6px;
  text-shadow:0 2px 18px rgba(0,0,0,.35);
}
.hero-sub{
  font-size:14.5px;
  color:rgba(251,246,236,.78);
  max-width:44ch;
  margin-bottom:18px;
}

.search{
  position:relative;
  display:flex;align-items:center;
  background:rgba(251,246,236,.97);
  border-radius:14px;
  padding:0 12px;
  border:1px solid rgba(184,135,59,.28);
  box-shadow:0 8px 24px rgba(0,0,0,.22);
  transition:box-shadow .18s ease, border-color .18s ease;
}
.search:focus-within{border-color:var(--gold);box-shadow:0 0 0 4px rgba(184,135,59,.2), 0 8px 24px rgba(0,0,0,.22)}
.search-icon{width:20px;height:20px;flex:0 0 20px;color:var(--muted)}
.search input{
  flex:1 1 auto;
  min-width:0;
  border:0;outline:0;background:transparent;
  font-size:16px;
  padding:14px 10px;
  color:var(--ink);
}
.search input::placeholder{color:#A2927B}
.search input::-webkit-search-cancel-button{display:none}
.clear-btn{
  width:32px;height:32px;flex:0 0 32px;
  display:grid;place-items:center;
  border-radius:9px;
  color:var(--muted);
  background:var(--sand-100);
}
.clear-btn svg{width:16px;height:16px}
.clear-btn:hover{color:var(--ink);background:var(--sand-200)}

.hero-stats{
  display:flex;align-items:center;gap:12px;
  margin-top:16px;
  font-size:13px;font-weight:500;
  color:rgba(251,246,236,.72);
}
.stat-dot{width:4px;height:4px;border-radius:50%;background:var(--gold-2);opacity:.8}

/* ============ شرائح التصفية ============ */
.chips{
  display:flex;gap:8px;
  overflow-x:auto;
  padding:18px 2px 6px;
  scrollbar-width:none;
  -ms-overflow-style:none;
}
.chips::-webkit-scrollbar{display:none}
.chip{
  flex:0 0 auto;
  display:inline-flex;align-items:center;gap:6px;
  padding:9px 15px;
  border-radius:999px;
  font-size:13.5px;font-weight:700;
  background:#FFFDF8;
  color:var(--ink-2);
  border:1px solid var(--sand-200);
  transition:background .16s ease, color .16s ease, border-color .16s ease, transform .12s ease;
  min-height:40px;
}
.chip:hover{border-color:var(--sand-300)}
.chip:active{transform:scale(.96)}
.chip:focus-visible{outline:3px solid rgba(184,135,59,.45);outline-offset:2px}
.chip.is-active{
  background:var(--night);
  color:var(--gold-3);
  border-color:var(--night);
}
.chip svg{width:15px;height:15px}

/* ============ شبكة البطاقات ============ */
.grid{
  display:grid;
  grid-template-columns:repeat(auto-fill,minmax(232px,1fr));
  gap:14px;
  padding-top:10px;
}
.card{
  position:relative;
  display:flex;flex-direction:column;gap:8px;
  text-align:start;
  background:#FFFDF8;
  border:1px solid var(--sand-200);
  border-radius:var(--radius);
  padding:16px;
  cursor:pointer;
  transition:transform .18s ease, border-color .18s ease, box-shadow .18s ease;
  animation:cardIn .32s ease both;
}
@keyframes cardIn{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}
.card:hover{transform:translateY(-3px);border-color:var(--sand-300);box-shadow:var(--shadow-sm)}
.card:active{transform:translateY(-1px)}
.card:focus-visible{outline:3px solid rgba(184,135,59,.5);outline-offset:2px}

.card--featured{
  background:linear-gradient(158deg,#FFFCF3 0%,#FBEED6 100%);
  border-color:var(--gold-2);
}
.card-top{display:flex;align-items:flex-start;justify-content:space-between;gap:8px}
.card-glyph{
  width:44px;height:44px;flex:0 0 44px;
  display:grid;place-items:center;
  border-radius:13px;
  font-family:'Amiri',serif;
  font-size:23px;
  color:var(--gold-3);
  background:linear-gradient(160deg,#3B2E22,#1D1710);
  box-shadow:inset 0 1px 0 rgba(255,255,255,.12);
}
.card--featured .card-glyph{background:linear-gradient(160deg,#C29246,#8F6726);color:#FFF8E7}
.fav-btn{
  width:36px;height:36px;flex:0 0 36px;
  display:grid;place-items:center;
  border-radius:11px;
  color:#BCAC94;
  background:transparent;
  transition:color .16s ease, background .16s ease, transform .12s ease;
}
.fav-btn svg{width:19px;height:19px}
.fav-btn:hover{color:var(--clay);background:rgba(169,80,47,.08)}
.fav-btn:active{transform:scale(.9)}
.fav-btn.is-fav{color:var(--clay)}
.fav-btn.is-fav svg{fill:currentColor}
.fav-btn:focus-visible{outline:3px solid rgba(184,135,59,.45);outline-offset:2px}

.card h3{font-size:20px;color:var(--ink)}
.card-tagline{
  font-size:13.5px;color:var(--muted);
  display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;
  overflow:hidden;
  min-height:2.9em;
}
.card-foot{
  display:flex;align-items:center;justify-content:space-between;gap:8px;
  margin-top:auto;padding-top:8px;
  border-top:1px dashed var(--sand-200);
}
.region-pill{
  font-size:11.5px;font-weight:700;
  padding:4px 10px;
  border-radius:999px;
  color:#7A5A22;
  background:var(--gold-3);
  border:1px solid rgba(184,135,59,.25);
  white-space:nowrap;
}
.card-more{font-size:12.5px;font-weight:700;color:var(--gold)}
.card:hover .card-more{color:var(--clay)}
.badge-featured{
  font-size:11px;font-weight:800;
  padding:4px 9px;border-radius:999px;
  background:var(--clay);color:#FFF3EA;
  white-space:nowrap;
}

/* ============ الحالة الفارغة ============ */
.empty{
  text-align:center;
  padding:48px 20px;
  background:#FFFDF8;
  border:1px dashed var(--sand-300);
  border-radius:var(--radius);
  margin-top:12px;
}
.empty-title{font-family:'Amiri',serif;font-size:22px;margin-bottom:4px}
.empty-sub{font-size:14px;color:var(--muted);margin-bottom:16px}

/* ============ التذييل ============ */
.footer{
  margin-top:36px;
  padding-top:18px;
  border-top:1px solid var(--sand-200);
  text-align:center;
  font-size:12.5px;
  color:var(--muted);
  line-height:1.8;
}

/* ============ الأزرار ============ */
.btn{
  display:inline-flex;align-items:center;justify-content:center;gap:8px;
  min-height:46px;
  padding:0 18px;
  border-radius:13px;
  font-size:14.5px;font-weight:700;
  transition:transform .14s ease, background .16s ease, border-color .16s ease, box-shadow .16s ease;
}
.btn svg{width:18px;height:18px}
.btn:active{transform:scale(.97)}
.btn:focus-visible{outline:3px solid rgba(184,135,59,.45);outline-offset:2px}
.btn-primary{
  background:linear-gradient(160deg,#332619,#1D1710);
  color:var(--gold-3);
  box-shadow:0 8px 20px rgba(29,23,16,.2);
  width:100%;
}
.btn-primary:hover{background:linear-gradient(160deg,#3E2F20,#241C14)}
.btn-gold{
  background:linear-gradient(160deg,#C29246,#9A6F2B);
  color:#FFF8E7;
  box-shadow:0 8px 18px rgba(184,135,59,.28);
}
.btn-gold:hover{background:linear-gradient(160deg,#CB9B4E,#A4762E)}
.btn-gold.is-on{background:linear-gradient(160deg,#A9502F,#7F3A20);box-shadow:none}
.btn-ghost{
  background:#FFFDF8;
  border:1px solid var(--sand-200);
  color:var(--ink-2);
}
.btn-ghost:hover{border-color:var(--sand-300);background:#FFF9EC}

/* ============ الطبقات المنبثقة ============ */
.overlay{
  position:fixed;inset:0;z-index:60;
  display:flex;align-items:center;justify-content:center;
  padding:16px;
  background:rgba(24,18,12,.55);
  backdrop-filter:blur(6px);
  -webkit-backdrop-filter:blur(6px);
  overflow-y:auto;
}
.overlay[hidden]{display:none !important}

.sheet{
  position:relative;
  width:100%;
  max-width:620px;
  max-height:calc(100dvh - 32px);
  overflow-y:auto;
  -webkit-overflow-scrolling:touch;
  background:var(--sand-50);
  border:1px solid var(--sand-200);
  border-radius:22px;
  padding:24px 20px 26px;
  box-shadow:0 30px 80px rgba(0,0,0,.4);
  animation:sheetIn .3s cubic-bezier(.2,.8,.3,1) both;
}
@keyframes sheetIn{from{opacity:0;transform:translateY(18px) scale(.985)}to{opacity:1;transform:none}}

.sheet-close{
  position:absolute;
  top:12px;inset-inline-start:12px;
  width:40px;height:40px;
  display:grid;place-items:center;
  border-radius:12px;
  background:rgba(255,253,248,.9);
  border:1px solid var(--sand-200);
  color:var(--ink-2);
  z-index:2;
}
.sheet-close svg{width:18px;height:18px}
.sheet-close:hover{background:#FFF9EC;border-color:var(--sand-300)}
.sheet-close:focus-visible{outline:3px solid rgba(184,135,59,.45);outline-offset:2px}

/* ============ تفاصيل القبيلة ============ */
.detail-head{padding-top:26px;text-align:center;margin-bottom:16px}
.detail-head h2{font-size:30px;margin:10px 0 4px;color:var(--ink)}
.detail-tagline{font-size:14px;color:var(--muted)}
.detail-actions{
  display:flex;flex-wrap:wrap;gap:10px;
  margin-bottom:22px;
}
.detail-actions .btn{flex:1 1 150px}

.block{margin-bottom:22px}
.block h3{
  font-size:18px;
  color:var(--gold);
  margin-bottom:6px;
  display:flex;align-items:center;gap:8px;
}
.block h3::before{
  content:"";width:6px;height:6px;border-radius:50%;
  background:var(--gold-2);flex:0 0 6px;
}
.block p{font-size:15px;color:var(--ink-2);line-height:1.85}
.block ul{margin:0;padding-inline-start:0;list-style:none;display:flex;flex-direction:column;gap:8px}
.block li{
  position:relative;
  padding-inline-start:20px;
  font-size:14.5px;color:var(--ink-2);
}
.block li::before{
  content:"";
  position:absolute;
  inset-inline-start:4px;top:.62em;
  width:7px;height:7px;
  border-radius:2px;
  transform:rotate(45deg);
  background:var(--gold-2);
}
.block.story{
  background:linear-gradient(158deg,#FFFCF3,#F7EBD6);
  border:1px solid rgba(184,135,59,.3);
  border-radius:16px;
  padding:18px 16px;
  position:relative;
}
.block.story h3{color:var(--clay)}
.block.story h3::before{background:var(--clay)}
.block.story p{font-family:'Amiri',serif;font-size:17px;line-height:2;color:#3A2E22}
.note{
  font-size:12px;color:var(--muted);
  line-height:1.8;
  border-top:1px dashed var(--sand-200);
  padding-top:12px;
}

/* ============ الاختبار ============ */
.quiz-start{text-align:center;padding-top:28px}
.quiz-emblem{
  width:78px;height:78px;margin:0 auto 16px;
  display:grid;place-items:center;
  border-radius:24px;
  background:linear-gradient(160deg,#3B2E22,#1D1710);
  color:var(--gold-2);
  box-shadow:0 12px 28px rgba(29,23,16,.28);
}
.quiz-emblem svg{width:38px;height:38px}
.quiz-start h2{font-size:26px;margin-bottom:8px}
.quiz-start p{font-size:14.5px;color:var(--muted);margin-bottom:18px}
.quiz-best{
  display:inline-block;
  font-size:13px;
  padding:8px 16px;
  border-radius:999px;
  background:var(--gold-3);
  color:#7A5A22;
  border:1px solid rgba(184,135,59,.25);
  margin-bottom:20px;
}
.quiz-best strong{font-weight:800}

.quiz-head{
  display:flex;align-items:center;justify-content:space-between;gap:10px;
  padding-top:26px;
  margin-bottom:12px;
  font-size:12.5px;font-weight:700;color:var(--muted);
}
.quiz-progress{
  flex:1 1 auto;
  height:7px;
  border-radius:999px;
  background:var(--sand-200);
  overflow:hidden;
  margin-inline-start:10px;
}
.quiz-progress i{
  display:block;height:100%;
  border-radius:999px;
  background:linear-gradient(90deg,#C29246,#8F6726);
  transition:width .3s ease;
}
.q-text{font-size:22px;line-height:1.55;margin-bottom:16px;color:var(--ink)}
.options{display:flex;flex-direction:column;gap:10px;margin-bottom:14px}
.option{
  display:flex;align-items:center;gap:12px;
  width:100%;
  text-align:start;
  padding:13px 14px;
  border-radius:14px;
  background:#FFFDF8;
  border:1px solid var(--sand-200);
  font-size:15px;font-weight:500;
  color:var(--ink-2);
  min-height:54px;
  transition:border-color .15s ease, background .15s ease, transform .12s ease;
}
.option:hover:not(:disabled){border-color:var(--gold-2);background:#FFF9EC}
.option:active:not(:disabled){transform:scale(.99)}
.option:focus-visible{outline:3px solid rgba(184,135,59,.45);outline-offset:2px}
.option:disabled{cursor:default}
.opt-letter{
  width:30px;height:30px;flex:0 0 30px;
  display:grid;place-items:center;
  border-radius:9px;
  background:var(--sand-100);
  border:1px solid var(--sand-200);
  font-size:13px;font-weight:800;
  color:var(--muted);
}
.option.correct{border-color:#4E8A5B;background:#EFF6EC}
.option.correct .opt-letter{background:#4E8A5B;border-color:#4E8A5B;color:#fff}
.option.wrong{border-color:#B4553A;background:#FBEFEA}
.option.wrong .opt-letter{background:#B4553A;border-color:#B4553A;color:#fff}
.q-feedback{
  font-size:14px;
  line-height:1.8;
  padding:12px 14px;
  border-radius:13px;
  background:#FFF9EC;
  border:1px solid rgba(184,135,59,.3);
  color:var(--ink-2);
  margin-bottom:14px;
}
.q-feedback.is-wrong{background:#FBEFEA;border-color:rgba(180,85,58,.35)}

.quiz-result{text-align:center;padding-top:28px}
.quiz-score{
  font-family:'Amiri',serif;
  font-size:54px;
  line-height:1;
  color:var(--gold);
  margin-bottom:6px;
}
.quiz-score small{font-size:20px;color:var(--muted)}
.quiz-result h2{font-size:24px;margin-bottom:8px}
.quiz-result p{font-size:14.5px;color:var(--muted);margin-bottom:22px}
.result-actions{display:flex;flex-direction:column;gap:10px}

/* ============ التنبيه ============ */
.toast{
  position:fixed;
  bottom:22px;left:50%;
  transform:translate(-50%, 20px);
  z-index:80;
  padding:11px 20px;
  border-radius:999px;
  background:rgba(29,23,16,.94);
  color:var(--gold-3);
  font-size:13.5px;font-weight:600;
  box-shadow:0 12px 30px rgba(0,0,0,.3);
  opacity:0;
  pointer-events:none;
  transition:opacity .22s ease, transform .22s ease;
  max-width:calc(100vw - 32px);
  text-align:center;
}
.toast.is-visible{opacity:1;transform:translate(-50%,0)}

/* ============ استجابة الشاشات ============ */
@media (max-width:640px){
  .shell{padding:0 14px 32px}
  .hero{border-radius:22px;padding:22px 16px 20px}
  .hero-title{font-size:28px}
  .hero-sub{font-size:13.5px}
  .grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
  .card{padding:13px;border-radius:16px}
  .card-glyph{width:38px;height:38px;flex-basis:38px;font-size:19px;border-radius:11px}
  .card h3{font-size:17px}
  .card-tagline{font-size:12px;min-height:3.1em}
  .card-more{display:none}
  .card-foot{padding-top:7px}
  .detail-head h2{font-size:26px}
  .overlay{padding:0;align-items:flex-end}
  .sheet{
    max-width:none;
    max-height:92dvh;
    border-radius:22px 22px 0 0;
    padding:22px 16px 28px;
  }
  .q-text{font-size:19px}
}
@media (max-width:360px){
  .grid{grid-template-columns:minmax(0,1fr)}
  .card-tagline{min-height:0}
}
@media (prefers-reduced-motion: reduce){
  *,*::before,*::after{
    animation-duration:.001ms !important;
    animation-iteration-count:1 !important;
    transition-duration:.001ms !important;
  }
}