/* ============================================================
   تحدي العقول — نظام التصميم
   ============================================================ */
:root {
  --blue:      #2563EB;
  --blue-2:    #60A5FA;
  --violet:    #7C3AED;
  --violet-2:  #A78BFA;
  --gold:      #F59E0B;
  --gold-2:    #FBBF24;
  --emerald:   #10B981;
  --sky:       #0EA5E9;
  --red:       #EF4444;
  --green:     #22C55E;

  --r-sm: 10px; --r: 16px; --r-lg: 22px; --r-xl: 28px;
  --sp: 8px;
  --ease: cubic-bezier(.16, 1, .3, 1);
  --icon: 20px;
  font-size: 16px;
}

/* الوضع الداكن (افتراضي) */
[data-theme="dark"], :root {
  --bg:        #0B1020;
  --bg-2:      #101833;
  --surface:   rgba(255, 255, 255, .055);
  --surface-2: rgba(255, 255, 255, .09);
  --border:    rgba(255, 255, 255, .10);
  --border-2:  rgba(255, 255, 255, .20);
  --text:      #F2F5FF;
  --text-2:    #A9B4D0;
  --shadow:    0 10px 34px rgba(0, 0, 0, .45);
  --glow:      rgba(37, 99, 235, .30);
}

/* الوضع الفاتح */
[data-theme="light"] {
  --bg:        #EFF6FF;
  --bg-2:      #FFFFFF;
  --surface:   rgba(255, 255, 255, .92);
  --surface-2: rgba(37, 99, 235, .07);
  --border:    #DCE7FA;
  --border-2:  #C3D6F5;
  --text:      #0F172A;
  --text-2:    #5A6B8C;
  --shadow:    0 10px 30px rgba(23, 47, 96, .12);
  --glow:      rgba(37, 99, 235, .18);
}

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

html, body { height: 100%; }

body {
  font-family: 'Cairo', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  transition: background .3s var(--ease), color .3s var(--ease);
}

.bg-glow {
  position: fixed; inset: -30% -20% auto -20%; height: 62vh;
  pointer-events: none; z-index: 0;
  background: radial-gradient(ellipse at 50% 0%, var(--glow), transparent 62%);
}

button, input, select { font-family: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
ul { list-style: none; }

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
  border-radius: 6px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ── الهيكل العام ── */
.view {
  position: relative; z-index: 1;
  max-width: 720px; margin: 0 auto;
  padding: 18px 16px calc(30px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 16px;
  min-height: 100dvh;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  position: sticky; top: 0; z-index: 20;
  margin: -18px -16px 0; padding: 10px 16px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar__side { display: flex; align-items: center; gap: 8px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; }
.brand__mark {
  width: 34px; height: 34px; border-radius: 11px; flex: none;
  background: linear-gradient(135deg, var(--blue), var(--violet));
  display: grid; place-items: center; box-shadow: 0 6px 18px rgba(37, 99, 235, .35);
}
.brand__mark svg { width: 20px; height: 20px; color: #fff; }
.brand__txt { font-size: 1rem; line-height: 1.2; display: flex; flex-direction: column; }
.brand__txt small { font-size: .62rem; font-weight: 600; color: var(--text-2); letter-spacing: .02em; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text);
  transition: transform .18s var(--ease), background .18s, border-color .18s;
}
.icon-btn:hover { background: var(--surface-2); transform: translateY(-2px); }
.icon-btn:active { transform: translateY(0) scale(.96); }
.icon-btn svg { width: var(--icon); height: var(--icon); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: .82rem; font-weight: 700;
}
.pill svg { width: 15px; height: 15px; }
.pill--gold { color: var(--gold-2); border-color: color-mix(in srgb, var(--gold) 40%, transparent); }
.pill--green { color: var(--green); border-color: color-mix(in srgb, var(--green) 40%, transparent); }

/* ── الأزرار ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 12px 20px; border-radius: 999px;
  font-size: .95rem; font-weight: 700; letter-spacing: 0;
  border: 1px solid transparent;
  transition: transform .18s var(--ease), box-shadow .18s var(--ease), background .18s;
}
.btn svg { width: var(--icon); height: var(--icon); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn--primary {
  background: linear-gradient(135deg, var(--blue), var(--violet));
  color: #fff; box-shadow: 0 8px 26px rgba(37, 99, 235, .34);
}
.btn--primary:hover { transform: translateY(-2px); box-shadow: 0 14px 34px rgba(37, 99, 235, .46); }
.btn--gold { background: linear-gradient(135deg, var(--gold), var(--gold-2)); color: #241703; }
.btn--gold:hover { transform: translateY(-2px); }
.btn--ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn--ghost:hover { background: var(--surface-2); transform: translateY(-2px); }
.btn--block { width: 100%; }

/* ── البطاقات ── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 18px;
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}
.hero { text-align: center; padding: 18px 8px 6px; }
.hero__title {
  font-family: 'Noto Naskh Arabic', 'Cairo', serif;
  font-size: clamp(1.9rem, 7vw, 2.7rem); font-weight: 700; line-height: 1.25;
  margin-bottom: 10px;
  background: linear-gradient(100deg, var(--gold-2), #fff 40%, var(--blue-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
[data-theme="light"] .hero__title { background: linear-gradient(100deg, #B45309, #1E3A8A 45%, #2563EB); -webkit-background-clip: text; background-clip: text; }
.hero__sub { color: var(--text-2); font-size: .95rem; max-width: 40ch; margin: 0 auto; }

.section-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 1.02rem; font-weight: 800; margin-bottom: 12px;
}
.section-title svg { width: 18px; height: 18px; color: var(--gold); }

.stat-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 12px 8px; text-align: center;
}
.stat__num { font-size: 1.3rem; font-weight: 800; line-height: 1.2; }
.stat__lbl { font-size: .7rem; color: var(--text-2); font-weight: 600; }

/* ── بطاقات الأنماط ── */
.modes { display: grid; gap: 12px; }
.mode {
  display: flex; align-items: center; gap: 14px; text-align: right; width: 100%;
  padding: 15px; border-radius: var(--r-lg);
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: transform .2s var(--ease), border-color .2s, background .2s;
}
.mode:hover { transform: translateY(-3px); border-color: var(--border-2); background: var(--surface-2); }
.mode:active { transform: translateY(-1px) scale(.995); }
.mode__ico {
  width: 48px; height: 48px; border-radius: 15px; flex: none;
  display: grid; place-items: center; color: #fff;
}
.mode__ico svg { width: 23px; height: 23px; }
.mode__body { flex: 1; min-width: 0; }
.mode__name { font-weight: 800; font-size: .98rem; display: flex; align-items: center; gap: 7px; }
.mode__desc { font-size: .78rem; color: var(--text-2); }
.mode__go { color: var(--text-2); flex: none; }
.mode__go svg { width: 20px; height: 20px; }
.tag {
  font-size: .6rem; font-weight: 800; padding: 2px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--gold) 20%, transparent); color: var(--gold-2);
  border: 1px solid color-mix(in srgb, var(--gold) 35%, transparent);
}
[data-theme="light"] .tag { color: #92400E; }

/* ── شبكة التصنيفات ── */
.cats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.cat {
  position: relative; overflow: hidden; width: 100%;
  padding: 16px 14px; border-radius: var(--r-lg); text-align: right;
  border: 1px solid var(--border); background: var(--surface);
  box-shadow: var(--shadow);
  transition: transform .2s var(--ease), border-color .2s;
}
.cat:hover { transform: translateY(-3px); border-color: var(--border-2); }
.cat__ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: #fff; margin-bottom: 10px; }
.cat__ico svg { width: 21px; height: 21px; }
.cat__name { font-weight: 800; font-size: .92rem; }
.cat__count { font-size: .72rem; color: var(--text-2); }
.cat__bar { height: 5px; border-radius: 999px; background: var(--surface-2); margin-top: 10px; overflow: hidden; }
.cat__bar > i { display: block; height: 100%; border-radius: 999px; transition: width .5s var(--ease); }

/* ── شاشة اللعب ── */
.hud { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hud__q { font-size: .78rem; font-weight: 700; color: var(--text-2); }
.hud__score { font-size: 1.15rem; font-weight: 800; display: flex; align-items: center; gap: 6px; }
.hud__score svg { width: 17px; height: 17px; color: var(--gold); }

.timer { height: 9px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.timer > i { display: block; height: 100%; width: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--green), var(--gold-2)); transition: width .25s linear, background .3s; }
.timer.is-low > i { background: linear-gradient(90deg, var(--gold), var(--red)); }

.qcard { position: relative; }
.qmeta { display: flex; gap: 7px; margin-bottom: 12px; flex-wrap: wrap; }
.chip {
  font-size: .68rem; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.qtext { font-size: clamp(1.08rem, 4.4vw, 1.34rem); font-weight: 700; line-height: 1.65; }

.opts { display: grid; gap: 10px; margin-top: 16px; }
.opt {
  display: flex; align-items: center; gap: 12px; text-align: right; width: 100%;
  padding: 14px 15px; border-radius: var(--r); min-height: 56px;
  background: var(--surface); border: 1.5px solid var(--border); color: var(--text);
  font-size: .96rem; font-weight: 600; line-height: 1.5;
  transition: transform .16s var(--ease), background .16s, border-color .16s, opacity .2s;
}
.opt:hover:not(:disabled) { background: var(--surface-2); border-color: var(--border-2); transform: translateY(-2px); }
.opt:disabled { cursor: default; }
.opt__key {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  display: grid; place-items: center; font-size: .8rem; font-weight: 800;
  background: var(--surface-2); border: 1px solid var(--border);
}
.opt__txt { flex: 1; }
.opt__mark { flex: none; display: grid; place-items: center; }
.opt__mark svg { width: 20px; height: 20px; }
.opt.is-correct { background: color-mix(in srgb, var(--green) 18%, var(--surface)); border-color: var(--green); }
.opt.is-correct .opt__key { background: var(--green); color: #04180c; }
.opt.is-wrong { background: color-mix(in srgb, var(--red) 16%, var(--surface)); border-color: var(--red); }
.opt.is-wrong .opt__key { background: var(--red); color: #fff; }
.opt.is-gone { opacity: .3; }
.opt.is-reveal { border-color: color-mix(in srgb, var(--green) 55%, transparent); }

/* ── وسائل المساعدة ── */
.lifelines { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.life {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 11px 6px; border-radius: var(--r); text-align: center;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  font-size: .7rem; font-weight: 700;
  transition: transform .16s var(--ease), background .16s, border-color .16s, opacity .2s;
}
.life svg { width: 19px; height: 19px; color: var(--gold-2); }
.life span small { display: block; font-size: .62rem; color: var(--text-2); font-weight: 600; }
.life:hover:not(:disabled) { background: var(--surface-2); transform: translateY(-2px); border-color: var(--border-2); }
.life:disabled { opacity: .38; }

/* ── الشرح ── */
.explain {
  display: flex; gap: 10px; align-items: flex-start;
  margin-top: 14px; padding: 13px 14px; border-radius: var(--r);
  background: color-mix(in srgb, var(--blue) 14%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--blue) 34%, transparent);
  font-size: .87rem; line-height: 1.7;
  animation: fadeUp .35s var(--ease) both;
}
.explain svg { width: 18px; height: 18px; flex: none; color: var(--blue-2); margin-top: 4px; }
.explain strong { color: var(--text); }

/* ── النتيجة ── */
.result-hero { text-align: center; padding: 20px 10px 8px; }
.ring { position: relative; width: 168px; height: 168px; margin: 0 auto 14px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 12; stroke-linecap: round; }
.ring .bgc { stroke: var(--surface-2); }
.ring .fgc { stroke: var(--gold); transition: stroke-dashoffset .9s var(--ease); }
.ring__mid { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring__pct { font-size: 2.1rem; font-weight: 800; line-height: 1; }
.ring__lbl { font-size: .74rem; color: var(--text-2); font-weight: 600; }
.verdict { font-size: 1.06rem; font-weight: 800; }
.verdict-sub { color: var(--text-2); font-size: .85rem; }
.record {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 8px;
  padding: 6px 13px; border-radius: 999px; font-size: .78rem; font-weight: 800;
  background: linear-gradient(135deg, var(--gold), var(--gold-2)); color: #241703;
}
.record svg { width: 15px; height: 15px; }
.res-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.res-grid .stat__num { font-size: 1.15rem; }
.actions { display: grid; gap: 10px; }

/* ── الإحصائيات ── */
.bar-row { display: grid; gap: 6px; margin-bottom: 13px; }
.bar-row__top { display: flex; justify-content: space-between; font-size: .8rem; font-weight: 700; }
.bar-row__top span:last-child { color: var(--text-2); font-weight: 600; }
.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; transition: width .6s var(--ease); }
.lvl-wrap { display: flex; align-items: center; gap: 14px; }
.lvl-badge {
  width: 54px; height: 54px; border-radius: 17px; flex: none; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--gold), var(--violet)); color: #fff; font-weight: 800; font-size: 1.2rem;
}
.empty { text-align: center; color: var(--text-2); font-size: .86rem; padding: 22px 10px; }
.empty svg { width: 34px; height: 34px; margin: 0 auto 10px; display: block; opacity: .5; }

/* ── الإعدادات ── */
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 2px; border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: none; }
.row__k { font-size: .9rem; font-weight: 700; }
.row__k small { display: block; font-size: .72rem; font-weight: 500; color: var(--text-2); }
.switch { position: relative; width: 52px; height: 30px; flex: none; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); transition: background .22s; }
.switch::after { content: ''; position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--text-2); transition: transform .22s var(--ease), background .22s; }
.switch[aria-pressed="true"] { background: linear-gradient(135deg, var(--blue), var(--violet)); }
.switch[aria-pressed="true"]::after { transform: translateX(-22px); background: #fff; }

/* ── التنبيهات ── */
.toast-wrap {
  position: fixed; bottom: calc(18px + env(safe-area-inset-bottom)); right: 50%; transform: translateX(50%);
  z-index: 90; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 9px;
  padding: 12px 16px; border-radius: var(--r);
  font-size: .86rem; font-weight: 700;
  background: var(--bg-2); border: 1px solid var(--border-2); box-shadow: var(--shadow);
  animation: fadeUp .28s var(--ease) both;
}
.toast svg { width: 18px; height: 18px; flex: none; }
.toast--ok { color: var(--green); }
.toast--err { color: var(--red); }
.toast--info { color: var(--blue-2); }

/* ── الحركات ── */
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes pop { 0% { transform: scale(.9); } 60% { transform: scale(1.03); } 100% { transform: scale(1); } }
@keyframes shake { 10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(3px); } 30%, 50%, 70% { transform: translateX(-4px); } 40%, 60% { transform: translateX(4px); } }
.fade-up { animation: fadeUp .45s var(--ease) both; }
.d1 { animation-delay: .06s; } .d2 { animation-delay: .12s; } .d3 { animation-delay: .18s; } .d4 { animation-delay: .24s; }
.pop { animation: pop .3s var(--ease) both; }
.shake { animation: shake .5s both; }
.qcard.enter { animation: fadeUp .34s var(--ease) both; }
.skip-link { position: absolute; inset-inline-start: -999px; }
.skip-link:focus { inset-inline-start: 12px; top: 12px; z-index: 100; background: var(--bg-2); padding: 8px 14px; border-radius: 8px; }

/* ── الاستجابة ── */
@media (min-width: 640px) {
  .view { padding-inline: 22px; }
  .modes { grid-template-columns: repeat(2, 1fr); }
  .cats { grid-template-columns: repeat(3, 1fr); }
  .lifelines { gap: 12px; }
  .actions { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 380px) {
  .stat-strip { grid-template-columns: repeat(3, 1fr); gap: 7px; }
  .stat__num { font-size: 1.1rem; }
  .lifelines { gap: 6px; }
  .life { font-size: .64rem; }
}
