:root {
  --bg: #0d0b1f;
  --bg2: #17143a;
  --card: #1f1b4d;
  --line: #2f2a6b;
  --text: #f4f2ff;
  --muted: #a9a3d9;
  --lime: #c6ff3d;
  --pink: #ff3d8b;
  --cyan: #3de0ff;
  --yellow: #ffd23d;
  --good: #36e27a;
  --bad: #ff4757;
  --r: 20px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }
body {
  font-family: 'Cairo', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }

/* ===== خلفية متحركة ===== */
.bg { position: fixed; inset: 0; overflow: hidden; z-index: 0;
  background: radial-gradient(120% 80% at 50% 0%, var(--bg2), var(--bg) 70%); }
.blob { position: absolute; border-radius: 50%; filter: blur(70px); opacity: .45; animation: float 14s ease-in-out infinite alternate; }
.b1 { width: 60vmax; height: 60vmax; background: #5b2bff; top: -25vmax; right: -20vmax; }
.b2 { width: 45vmax; height: 45vmax; background: #ff2d7a; bottom: -20vmax; left: -15vmax; animation-delay: -5s; opacity: .3; }
.b3 { width: 30vmax; height: 30vmax; background: #00c2ff; top: 40%; left: 30%; animation-delay: -9s; opacity: .18; }
@keyframes float { to { transform: translate(6vmax, 4vmax) scale(1.1); } }

.flash { position: fixed; inset: 0; z-index: 40; pointer-events: none; opacity: 0; }
.flash.good { animation: flash .45s ease-out; box-shadow: inset 0 0 120px 30px rgba(54, 226, 122, .55); }
.flash.bad { animation: flash .6s ease-out; box-shadow: inset 0 0 140px 40px rgba(255, 71, 87, .7); }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }

/* ===== الحاوية ===== */
.app {
  position: relative; z-index: 1;
  height: 100%; height: 100dvh;
  max-width: 640px; margin: 0 auto;
  padding: calc(8px + var(--safe-t)) 16px calc(12px + var(--safe-b));
  display: flex; flex-direction: column;
}

.screen { display: none; flex: 1; min-height: 0; flex-direction: column; align-items: stretch; }
.screen.active { display: flex; animation: screenIn .45s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes screenIn { from { opacity: 0; transform: translateY(18px) scale(.98); } }

/* ===== الإعلانات ===== */
.ad-wrap { flex-shrink: 0; display: flex; flex-direction: column; gap: 2px; }
.ad-top-wrap { margin-bottom: 8px; }
.ad-bottom-wrap { margin-top: 20px; padding-top: 6px; border-top: 1px solid var(--line); }
.ad-label { font-size: 10px; line-height: 1; color: var(--muted); opacity: .7; text-align: center; letter-spacing: .5px; }
.ad-slot { display: flex; align-items: center; justify-content: center; overflow: hidden; }
.ad-slot ins { width: 100%; }
/* لو جوجل ما لقت إعلان (أو قبل موافقة الموقع) نخفي الخانة كاملة */
.ad-wrap:has(ins[data-ad-status="unfilled"]) { display: none; }
.ad-banner { min-height: 50px; max-height: 90px; }
.ad-placeholder {
  width: 100%; min-height: 50px;
  display: flex; align-items: center; justify-content: center;
  border: 2px dashed var(--line); border-radius: 12px;
  color: var(--muted); font-size: 13px; opacity: .7;
}

/* روابط أسفل القائمة */
.foot-links { margin-top: auto; padding-top: 16px; display: flex; justify-content: center; gap: 8px; font-size: 13px; color: var(--muted); }
.foot-links a { color: var(--muted); text-decoration: none; }
.foot-links a:hover, .foot-links a:focus-visible { color: var(--text); text-decoration: underline; }

/* ===== أزرار ===== */
.btn {
  display: block; width: 100%;
  padding: 14px 18px; border-radius: 16px;
  font-weight: 900; font-size: 18px;
  transition: transform .08s, box-shadow .08s, filter .2s;
}
.btn:active { transform: translateY(4px); }
.btn-primary {
  background: linear-gradient(180deg, #d8ff6a, var(--lime));
  color: #1a1a00;
  box-shadow: 0 6px 0 #7fae0f, 0 12px 30px rgba(198, 255, 61, .35);
}
.btn-primary:active { box-shadow: 0 2px 0 #7fae0f, 0 6px 16px rgba(198, 255, 61, .3); }
.btn-big { font-size: clamp(20px, 5.5vw, 26px); padding: 16px 18px; }
.btn-ghost { background: rgba(255, 255, 255, .06); border: 2px solid var(--line); margin-top: 12px; font-size: 16px; padding: 11px 16px; }
.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 14px;
  background: rgba(255, 255, 255, .07); border: 2px solid var(--line);
  font-size: 20px; display: grid; place-items: center;
}
.icon-btn.small { width: 40px; height: 40px; font-size: 16px; }
.icon-btn.off { opacity: .35; filter: grayscale(1); }

/* ===== القائمة ===== */
#menu { justify-content: flex-start; }
#menu, #over { overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none; }
#menu::-webkit-scrollbar, #over::-webkit-scrollbar { display: none; }
.topbar { display: flex; gap: 8px; justify-content: flex-start; }
.logo { text-align: center; margin: clamp(4px, 2vh, 24px) 0 clamp(14px, 3vh, 28px); }
.brain { font-size: clamp(56px, 16vw, 92px); line-height: 1; animation: brain 2.2s ease-in-out infinite; filter: drop-shadow(0 8px 24px rgba(255, 61, 139, .5)); }
@keyframes brain { 50% { transform: scale(1.08) rotate(-4deg); } }
.logo h1 { font-size: clamp(42px, 12vw, 68px); font-weight: 900; line-height: 1.15; letter-spacing: -1px; }
.logo h1 span { color: var(--lime); text-shadow: 0 0 24px rgba(198, 255, 61, .6); }
.tagline { color: var(--muted); font-size: clamp(15px, 4vw, 19px); }
.tagline b { color: var(--yellow); }

.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.mode {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 12px 6px; border-radius: 16px;
  background: var(--card); border: 3px solid var(--line);
  transition: transform .15s, border-color .15s, background .15s;
}
.mode-emoji { font-size: 28px; }
.mode-name { font-weight: 900; font-size: 18px; }
.mode-desc { font-size: 12px; color: var(--muted); line-height: 1.3; text-align: center; }
.mode.selected { border-color: var(--lime); background: #2a2a55; transform: translateY(-3px); box-shadow: 0 8px 22px rgba(198, 255, 61, .2); }
.mode[data-mode="hard"].selected { border-color: var(--pink); box-shadow: 0 8px 22px rgba(255, 61, 139, .3); }

.best { text-align: center; color: var(--muted); margin-bottom: 14px; font-size: 15px; }
.best b { color: var(--yellow); font-size: 18px; }

/* ===== اللعب ===== */
.hud { display: flex; align-items: center; gap: 10px; }
.lives { display: flex; gap: 2px; font-size: 22px; }
.lives .heart { transition: transform .3s, opacity .3s, filter .3s; }
.lives .heart.lost { opacity: .25; filter: grayscale(1); transform: scale(.7); }
.lives .heart.break { animation: heartBreak .6s; }
@keyframes heartBreak { 30% { transform: scale(1.5) rotate(-15deg); } 100% { transform: scale(.7); } }
.hud-mid { flex: 1; text-align: center; }
.level { display: inline-block; padding: 4px 12px; border-radius: 99px; background: rgba(61, 224, 255, .12); color: var(--cyan); font-weight: 700; font-size: 14px; }
.score-box { text-align: left; line-height: 1; }
.score-box span { font-size: 26px; font-weight: 900; color: var(--yellow); display: inline-block; }
.score-box span.bump { animation: bump .35s; }
.score-box small { display: block; font-size: 11px; color: var(--muted); }
@keyframes bump { 50% { transform: scale(1.35); } }

.timer { position: relative; height: 18px; border-radius: 99px; background: rgba(255, 255, 255, .08); margin: 12px 0 0; overflow: hidden; }
.timer-fill { position: absolute; inset: 0; transform-origin: right center; background: linear-gradient(90deg, var(--cyan), var(--lime)); border-radius: 99px; }
.timer.low .timer-fill { background: linear-gradient(90deg, var(--bad), #ff8a3d); animation: pulse .5s infinite alternate; }
.timer-num { position: absolute; inset: 0; display: grid; place-items: center; font-size: 13px; font-weight: 900; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, .8); line-height: 1; }
@keyframes pulse { to { filter: brightness(1.4); } }

.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; position: relative; padding: 10px 0; }
.combo { height: 30px; font-weight: 900; font-size: 18px; color: var(--pink); text-shadow: 0 0 16px rgba(255, 61, 139, .7); }
.combo.show { animation: comboIn .4s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes comboIn { from { transform: scale(.3); opacity: 0; } }

.card {
  width: 100%;
  background: linear-gradient(180deg, #2a2563, var(--card));
  border: 3px solid var(--line);
  border-radius: 28px;
  padding: clamp(18px, 4vh, 36px) 18px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .08);
}
.card.in { animation: cardIn .45s cubic-bezier(.2, 1.3, .4, 1); }
@keyframes cardIn { from { transform: translateX(-60%) rotate(-6deg); opacity: 0; } }
.card.shake { animation: shake .45s; border-color: var(--bad); }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
.q-num { display: inline-block; font-size: 13px; font-weight: 700; color: var(--muted); background: rgba(255, 255, 255, .06); padding: 2px 12px; border-radius: 99px; margin-bottom: 10px; }
.q-text { font-size: clamp(26px, 7.5vw, 44px); font-weight: 900; line-height: 1.35; }
.q-sub { font-size: clamp(24px, 7vw, 40px); letter-spacing: 4px; margin-top: 8px; line-height: 1.3; word-break: break-all; }
.q-sub:empty { display: none; }

.pill {
  margin-top: 14px; padding: 8px 16px; border-radius: 99px;
  font-weight: 700; font-size: clamp(14px, 3.8vw, 17px); text-align: center;
  background: rgba(255, 210, 61, .12); color: var(--yellow); border: 2px solid rgba(255, 210, 61, .35);
}
.pill.memo { background: rgba(255, 61, 139, .12); color: var(--pink); border-color: rgba(255, 61, 139, .4); animation: pulse .8s infinite alternate; }

.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding-top: 6px; }
.answers.single { grid-template-columns: 1fr; }
.opt {
  min-height: clamp(64px, 11vh, 96px);
  padding: 10px; border-radius: 18px;
  background: #fff; color: #1b1740;
  font-weight: 900; font-size: clamp(19px, 5.4vw, 28px); line-height: 1.2;
  box-shadow: 0 6px 0 #b9b4e6;
  transition: transform .08s, box-shadow .08s, background .2s;
  animation: optIn .35s backwards;
}
.opt:nth-child(2) { animation-delay: .05s; }
.opt:nth-child(3) { animation-delay: .1s; }
.opt:nth-child(4) { animation-delay: .15s; }
@keyframes optIn { from { transform: translateY(20px) scale(.9); opacity: 0; } }
.opt:active { transform: translateY(4px); box-shadow: 0 2px 0 #b9b4e6; }
.opt.correct { background: var(--good); color: #002a10; box-shadow: 0 6px 0 #17a04f, 0 0 30px rgba(54, 226, 122, .6); }
.opt.wrong { background: var(--bad); color: #fff; box-shadow: 0 6px 0 #a3212d; }
.opt.dim { opacity: .35; }
.answers.locked .opt { pointer-events: none; }
.opt.ready { background: linear-gradient(180deg, #ff6fa8, var(--pink)); color: #fff; box-shadow: 0 6px 0 #a8124e, 0 12px 30px rgba(255, 61, 139, .35); }

/* نقاط طايرة وجزيئات */
.pop-layer { position: fixed; inset: 0; pointer-events: none; z-index: 30; }
.float-pts { position: absolute; font-weight: 900; font-size: 26px; color: var(--yellow); text-shadow: 0 2px 10px rgba(0, 0, 0, .5); animation: rise 1s ease-out forwards; }
@keyframes rise { to { transform: translateY(-90px) scale(1.2); opacity: 0; } }
.spark { position: absolute; width: 10px; height: 10px; border-radius: 3px; animation: spark .8s ease-out forwards; }
@keyframes spark { to { transform: translate(var(--dx), var(--dy)) rotate(360deg); opacity: 0; } }

.app.quake { animation: quake .4s; }
@keyframes quake { 25% { transform: translate(6px, -4px); } 50% { transform: translate(-6px, 4px); } 75% { transform: translate(4px, 2px); } }

/* بانر المستوى */
.levelup-banner {
  position: fixed; left: 50%; top: 40%; z-index: 45;
  transform: translate(-50%, -50%);
  font-size: clamp(36px, 11vw, 64px); font-weight: 900; white-space: nowrap;
  color: var(--lime); text-shadow: 0 0 30px rgba(198, 255, 61, .8), 0 6px 0 #3b5200;
  animation: lvl 1.4s cubic-bezier(.2, 1.4, .4, 1) forwards; pointer-events: none;
}
@keyframes lvl { 0% { transform: translate(-50%, -50%) scale(.2); opacity: 0; } 25% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; } 75% { opacity: 1; } 100% { transform: translate(-50%, -80%) scale(1); opacity: 0; } }

/* ===== النهاية ===== */
.over-head { text-align: center; margin-top: clamp(4px, 2vh, 20px); }
.rating-emoji { font-size: clamp(64px, 18vw, 100px); line-height: 1.1; animation: brain 2s ease-in-out infinite; }
.over-head h2 { font-size: clamp(30px, 8.5vw, 46px); font-weight: 900; color: var(--lime); }
.over-head p { color: var(--muted); font-size: 16px; }
.final-score { text-align: center; margin: 12px 0 4px; line-height: 1; }
.final-score span { font-size: clamp(56px, 16vw, 84px); font-weight: 900; color: var(--yellow); text-shadow: 0 0 30px rgba(255, 210, 61, .5); }
.final-score small { display: block; color: var(--muted); font-size: 14px; margin-top: 4px; }
.new-best { display: none; text-align: center; color: var(--pink); font-weight: 900; font-size: 18px; animation: pulse .6s infinite alternate; }
.new-best.show { display: block; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0 16px; }
.stats div { background: var(--card); border: 2px solid var(--line); border-radius: 16px; padding: 10px 4px; text-align: center; }
.stats b { display: block; font-size: 24px; font-weight: 900; color: var(--cyan); }
.stats span { font-size: 12px; color: var(--muted); }

/* ===== الطبقات ===== */
.overlay { position: fixed; inset: 0; z-index: 50; display: none; align-items: center; justify-content: center; background: rgba(13, 11, 31, .82); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); padding: 16px; }
.overlay.show { display: flex; }
.count-num { font-size: clamp(120px, 40vw, 220px); font-weight: 900; color: var(--lime); text-shadow: 0 0 60px rgba(198, 255, 61, .7); }
.count-num.tick { animation: countPop .8s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes countPop { from { transform: scale(2.4); opacity: 0; } 60% { opacity: 1; } to { transform: scale(.9); } }

.sheet {
  width: 100%; max-width: 480px; max-height: 92dvh; overflow-y: auto;
  background: var(--bg2); border: 3px solid var(--line); border-radius: 26px;
  padding: 22px 18px; animation: screenIn .35s;
}
.sheet h3 { font-size: 26px; font-weight: 900; text-align: center; margin-bottom: 14px; }
.how-steps { padding-right: 22px; margin-bottom: 14px; line-height: 1.7; font-size: 16px; }
.how-steps b { color: var(--lime); }
.example { display: flex; align-items: center; gap: 6px; margin-bottom: 14px; }
.ex-card { flex: 1; background: var(--card); border: 2px solid var(--line); border-radius: 14px; padding: 8px 4px; text-align: center; font-weight: 700; font-size: 14px; line-height: 1.4; }
.ex-card small { display: block; color: var(--muted); font-size: 11px; }
.ex-card em { display: block; font-style: normal; color: var(--yellow); font-size: 12px; margin-top: 2px; }
.ex-arrow { color: var(--pink); font-weight: 900; }
.how-note { color: var(--muted); font-size: 14px; text-align: center; margin-bottom: 10px; line-height: 1.6; }
.how-note b { color: var(--pink); }
.sheet .btn-primary { margin-top: 6px; }

/* ===== صفحات النص ===== */
body.page { overflow-y: auto; user-select: text; -webkit-user-select: text; }
.doc { position: relative; z-index: 1; max-width: 680px; margin: 0 auto; padding: calc(24px + var(--safe-t)) 20px calc(40px + var(--safe-b)); line-height: 1.85; font-size: 16px; }
.doc .back { display: inline-block; margin-bottom: 20px; color: var(--lime); font-weight: 700; text-decoration: none; }
.doc h1 { font-size: clamp(30px, 8vw, 42px); font-weight: 900; line-height: 1.3; margin-bottom: 6px; text-wrap: balance; }
.doc h2 { font-size: 20px; font-weight: 900; color: var(--lime); margin: 28px 0 8px; }
.doc p, .doc li { color: #d9d5f5; }
.doc ul, .doc ol { padding-right: 22px; }
.doc a { color: var(--cyan); }
.doc .meta { color: var(--muted); font-size: 14px; }
.doc .cta { margin-top: 28px; display: inline-block; width: auto; padding: 14px 28px; text-decoration: none; text-align: center; }

/* ===== تابلت ===== */
@media (min-width: 700px) {
  .app { padding-left: 24px; padding-right: 24px; }
  .answers { gap: 16px; }
  .ad-banner, .ad-banner .ad-placeholder { min-height: 90px; }
  .ad-bottom-wrap { margin-top: 28px; }
}

/* ===== جوال بالعرض / شاشات قصيرة ===== */
@media (max-height: 560px) and (orientation: landscape) {
  .app { max-width: 900px; }
  .ad-banner, .ad-banner .ad-placeholder { min-height: 50px; max-height: 50px; }
  .ad-top-wrap { margin-bottom: 4px; }
  .ad-label { display: none; }
  .ad-bottom-wrap { display: none; }
  .answers { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .answers.single { grid-template-columns: 1fr; }
  .opt { min-height: 56px; font-size: 18px; }
  .card { padding: 10px 14px; }
  .q-text { font-size: 26px; }
  .logo { margin: 0 0 8px; }
  .brain { font-size: 44px; }
  .logo h1 { font-size: 36px; }
  .stage { padding: 4px 0; }
  .combo { display: none; }
  .hud .icon-btn.small { width: 34px; height: 34px; }
  .timer { margin-top: 6px; }
  .q-num { display: none; }
  .q-text { font-size: 24px; line-height: 1.25; }
  .q-sub { font-size: 20px; margin-top: 2px; }
  .pill { margin-top: 6px; padding: 3px 12px; font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
