/* ── هوية اللعبة: ألوان مستوحاة من نظام تصميم "نيون أركيد" ── */
:root {
  --bg:          #0b1020;
  --bg-2:        #121a33;
  --bg-3:        #17204180;
  --panel:       rgba(255, 255, 255, .05);
  --panel-2:     rgba(255, 255, 255, .08);
  --border:      rgba(255, 255, 255, .09);
  --border-2:    rgba(255, 255, 255, .18);
  --text:        #eef2ff;
  --muted:       #93a0bd;
  --red:         #ff3b5c;
  --blue:        #3b82f6;
  --blue-soft:   #60a5fa;
  --cyan:        #22d3ee;
  --green:       #22c55e;
  --amber:       #fbbf24;
  --grad:        linear-gradient(135deg, #22d3ee, #3b82f6);
  --radius-sm:   10px;
  --radius:      16px;
  --radius-lg:   22px;
  --shadow:      0 4px 24px rgba(0, 0, 0, .45);
  --shadow-lg:   0 16px 50px rgba(0, 0, 0, .55);
  --font-ar:     'Cairo', 'Noto Kufi Arabic', system-ui, -apple-system, sans-serif;
  --font-pixel:  'Press Start 2P', ui-monospace, 'Courier New', monospace;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-ar);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

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

.glow {
  position: fixed;
  inset: -30% -20% auto -20%;
  height: 65vh;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse at 30% 0%, rgba(34, 211, 238, .22), transparent 55%),
    radial-gradient(ellipse at 70% 5%, rgba(59, 130, 246, .22), transparent 55%);
}

/* ── عناصر عامة ── */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--panel); border: 1px solid var(--border);
  color: var(--text); cursor: pointer;
  transition: transform .2s ease, background .2s ease, color .2s ease;
}
.icon-btn:hover { transform: translateY(-2px); background: var(--panel-2); color: var(--cyan); }
.icon-btn svg { width: 19px; height: 19px; }

/* ── الشريط العلوي ── */
.navbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; height: 62px; padding: 0 clamp(1rem, 4vw, 2.5rem);
  background: rgba(11, 16, 32, .82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.nav-logo {
  display: inline-flex; align-items: center; gap: .55rem;
  font-weight: 800; font-size: 1.05rem; color: var(--text);
  text-decoration: none;
}
.logo-dot {
  width: 12px; height: 12px; border-radius: 4px;
  background: var(--grad);
  box-shadow: 0 0 14px rgba(34, 211, 238, .8);
}
.nav-links { display: flex; gap: 1.25rem; }
.nav-link {
  color: var(--muted); font-size: .93rem; font-weight: 600;
  text-decoration: none; padding: .25rem 0;
  border-bottom: 2px solid transparent;
  transition: color .2s ease, border-color .2s ease;
}
.nav-link:hover { color: var(--text); text-decoration: none; }
.nav-link.active { color: var(--text); border-bottom-color: var(--cyan); }

/* ── الترويسة ── */
.hero { position: relative; z-index: 1; text-align: center; padding: clamp(2.5rem, 7vw, 4.5rem) 1rem 1.5rem; }
.hero-badge {
  display: inline-block; font-size: .74rem; font-weight: 700;
  letter-spacing: .08em; color: var(--cyan);
  background: rgba(34, 211, 238, .1); border: 1px solid rgba(34, 211, 238, .25);
  padding: .3rem .85rem; border-radius: 999px; margin-bottom: 1rem;
}
.hero h1 {
  font-size: clamp(2.1rem, 7vw, 3.4rem); font-weight: 800;
  letter-spacing: -.02em; line-height: 1.15; margin-bottom: .75rem;
  background: linear-gradient(135deg, #ffffff 20%, #8ed8ff 60%, #4f8bff 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 0 40px rgba(59, 130, 246, .25);
}
.hero p { color: var(--muted); font-size: clamp(.95rem, 2.4vw, 1.08rem); max-width: 620px; margin: 0 auto 1.25rem; }
.hero-badges { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; }

/* ── شرائح صغيرة ── */
.badge {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .76rem; font-weight: 600; padding: .28rem .75rem;
  border-radius: 999px; background: rgba(59, 130, 246, .14); color: var(--blue-soft);
  border: 1px solid rgba(59, 130, 246, .22);
}
.badge.green { background: rgba(34, 197, 94, .12); color: var(--green); border-color: rgba(34, 197, 94, .25); }
.badge.amber { background: rgba(251, 191, 36, .12); color: var(--amber); border-color: rgba(251, 191, 36, .25); }

/* ── منطقة اللعب ── */
.game-wrap {
  position: relative; z-index: 1;
  width: min(100%, 560px); margin: 1rem auto 0;
  padding: 0 1rem 1rem;
  display: flex; flex-direction: column; gap: .9rem;
}

/* ── لوحة الأرقام ── */
.hud {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem;
}
.stat {
  display: flex; flex-direction: column; align-items: center; gap: .1rem;
  padding: .6rem .4rem; border-radius: var(--radius-sm);
  background: var(--panel); border: 1px solid var(--border);
  backdrop-filter: blur(10px);
}
.stat-label { font-size: .7rem; letter-spacing: .08em; color: var(--muted); text-transform: uppercase; }
.stat-value {
  font-family: var(--font-pixel); font-size: 1.05rem; line-height: 1.6;
  color: var(--cyan); text-shadow: 0 0 14px rgba(34, 211, 238, .5);
}
.stat:nth-child(2) .stat-value { color: var(--amber); text-shadow: 0 0 14px rgba(251, 191, 36, .45); }
.stat:nth-child(3) .stat-value { color: var(--green); text-shadow: 0 0 14px rgba(34, 197, 94, .45); }

/* ── تبويبات السرعة ── */
.speed-row {
  display: flex; gap: .25rem; padding: .25rem;
  background: var(--panel); border: 1px solid var(--border); border-radius: 999px;
}
.tab {
  flex: 1; padding: .5rem .5rem; border: none; border-radius: 999px;
  background: transparent; color: var(--muted); font-family: inherit;
  font-size: .88rem; font-weight: 700; cursor: pointer;
  transition: background .2s ease, color .2s ease, transform .15s ease;
}
.tab:hover { color: var(--text); transform: translateY(-1px); }
.tab.active { background: var(--grad); color: #06101f; box-shadow: 0 6px 22px rgba(34, 211, 238, .3); }

/* ── اللوحة ── */
.board-wrap {
  position: relative; width: 100%; aspect-ratio: 1 / 1;
  border-radius: var(--radius-lg); overflow: hidden;
  border: 1px solid var(--border-2);
  background: radial-gradient(circle at 50% 0%, #16213f 0%, #0a0f1f 70%);
  box-shadow: var(--shadow-lg), inset 0 0 60px rgba(59, 130, 246, .12);
}
#board { display: block; width: 100%; height: 100%; touch-action: none; }

/* ── الطبقة العلوية (ابدأ / متوقف / خسرت) ── */
.overlay {
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  padding: 1.25rem; text-align: center;
  background: rgba(8, 12, 24, .78);
  backdrop-filter: blur(6px);
  transition: opacity .25s ease, visibility .25s ease;
}
.overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.overlay-card { max-width: 320px; animation: fadeUp .35s ease both; }
.overlay-card h2 {
  font-size: clamp(1.35rem, 5vw, 1.8rem); font-weight: 800; margin-bottom: .5rem;
  color: #fff;
}
.overlay-card p { font-size: .92rem; color: var(--muted); margin-bottom: 1rem; }
.ov-score {
  font-family: var(--font-pixel); font-size: 1rem; line-height: 2;
  color: var(--green); text-shadow: 0 0 16px rgba(34, 197, 94, .5);
  margin-bottom: 1rem !important;
}
.ov-score.hidden { display: none; }
.overlay.lose .overlay-card h2 { color: var(--red); text-shadow: 0 0 22px rgba(255, 59, 92, .45); }

/* ── الأزرار ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .7rem 1.4rem; border: none; border-radius: 999px;
  font-family: inherit; font-size: .92rem; font-weight: 700;
  cursor: pointer; text-decoration: none;
  transition: transform .16s ease, box-shadow .16s ease, background .2s ease, opacity .2s ease;
}
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--grad); color: #06101f; box-shadow: 0 8px 30px rgba(34, 211, 238, .32); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 14px 38px rgba(34, 211, 238, .45); text-decoration: none; }
.btn-ghost {
  background: var(--panel); color: var(--text); border: 1px solid var(--border-2);
}
.btn-ghost:hover { transform: translateY(-2px); background: var(--panel-2); text-decoration: none; }
.btn:active { transform: translateY(0) scale(.98); }
.btn:focus-visible, .tab:focus-visible, .dbtn:focus-visible, .icon-btn:focus-visible {
  outline: 2px solid var(--cyan); outline-offset: 2px;
}

/* ── التحكم ── */
.controls {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
}
.dpad {
  direction: ltr; /* حتى يكون اليسار يسارًا فعليًا داخل شبكة RTL */
  display: grid; grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(3, 44px);
  gap: 4px; position: relative;
}
.dpad-core {
  grid-area: 2 / 2; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--border);
}
.dbtn {
  display: flex; align-items: center; justify-content: center;
  background: var(--panel); border: 1px solid var(--border); color: var(--muted);
  border-radius: 12px; cursor: pointer;
  transition: transform .15s ease, background .2s ease, color .2s ease, border-color .2s ease;
}
.dbtn svg { width: 20px; height: 20px; }
.dbtn:hover { color: var(--cyan); border-color: rgba(34, 211, 238, .4); transform: translateY(-2px); }
.dbtn:active { background: rgba(34, 211, 238, .18); transform: scale(.94); }
.dbtn.up    { grid-area: 1 / 2; }
.dbtn.left  { grid-area: 2 / 1; }
.dbtn.right { grid-area: 2 / 3; }
.dbtn.down  { grid-area: 3 / 2; }

.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.actions .btn { font-size: .85rem; padding: .6rem 1.1rem; }

.hint { font-size: .8rem; color: var(--muted); text-align: center; line-height: 2.1; }
kbd {
  font-family: var(--font-pixel); font-size: .58rem;
  background: var(--panel-2); border: 1px solid var(--border-2);
  border-bottom-width: 2px; border-radius: 6px;
  padding: .18rem .38rem; color: var(--text);
}

/* ── أقسام المحتوى ── */
.section { position: relative; z-index: 1; max-width: 900px; margin: 0 auto; padding: clamp(2rem, 5vw, 3.5rem) 1.25rem; }
.section-title { font-size: clamp(1.3rem, 4vw, 1.8rem); font-weight: 800; margin-bottom: 1.5rem; text-align: center; }
.section-sub { color: var(--muted); text-align: center; max-width: 620px; margin: -.9rem auto 1.75rem; }

.grid { display: grid; gap: 1rem; }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }

.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.35rem;
  backdrop-filter: blur(12px); box-shadow: var(--shadow);
  transition: transform .22s ease, box-shadow .22s ease, border-color .22s ease;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--border-2); }
.card h3 { font-size: 1rem; font-weight: 800; margin-bottom: .35rem; }
.card p { font-size: .88rem; color: var(--muted); line-height: 1.75; }

.feature { display: flex; flex-direction: column; gap: .3rem; }
.feature > svg {
  width: 34px; height: 34px; padding: 7px; margin-bottom: .4rem;
  border-radius: 10px; color: var(--cyan);
  background: rgba(34, 211, 238, .1); border: 1px solid rgba(34, 211, 238, .22);
}

.footer {
  position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: center; gap: .75rem; flex-wrap: wrap;
  padding: 1.75rem 1rem 2.5rem; border-top: 1px solid var(--border);
  color: var(--muted); font-size: .85rem; text-align: center;
}
.footer strong { color: var(--text); }
.footer-link { font-weight: 700; }

/* ── حركات ── */
@keyframes fadeUp { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes pop { 0% { transform: scale(1); } 45% { transform: scale(1.28); } 100% { transform: scale(1); } }
.pop { animation: pop .28s ease; }
@keyframes floaty { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.fade-up { animation: fadeUp .5s ease both; }

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

/* ── استجابة الشاشات ── */
@media (max-width: 640px) {
  .nav-links { gap: .85rem; }
  .nav-link { font-size: .85rem; }
  .game-wrap { width: 100%; }
  .controls { justify-content: center; }
  .actions { width: 100%; }
  .actions .btn { flex: 1; }
  .stat-value { font-size: .9rem; }
}
@media (max-width: 380px) {
  .dpad { grid-template-columns: repeat(3, 40px); grid-template-rows: repeat(3, 40px); }
  .stat-label { font-size: .62rem; }
}
@media (hover: none) {
  .hint { display: none; }
}

/* ── صفحة الشرح ── */
.doc { position: relative; z-index: 1; max-width: 820px; margin: 0 auto; padding: 1rem 1.25rem 3rem; }
.toc { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1.5rem; justify-content: center; }
.toc a {
  font-size: .82rem; font-weight: 600; padding: .3rem .85rem;
  border-radius: 999px; background: var(--panel);
  border: 1px solid var(--border); color: var(--text); text-decoration: none;
  transition: border-color .2s ease, color .2s ease, transform .15s ease;
}
.toc a:hover { border-color: var(--cyan); color: var(--cyan); text-decoration: none; transform: translateY(-2px); }

.step {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: clamp(1rem, 3vw, 1.5rem);
  margin-bottom: 1.1rem; backdrop-filter: blur(10px);
  transition: border-color .25s ease, box-shadow .25s ease;
}
.step:hover { border-color: var(--border-2); box-shadow: var(--shadow); }
.step-head { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; margin-bottom: .6rem; }
.step-num {
  font-family: var(--font-pixel); font-size: .78rem; color: #06101f;
  background: var(--grad); width: 34px; height: 34px; flex: 0 0 auto;
  display: grid; place-items: center; border-radius: 10px;
  box-shadow: 0 6px 18px rgba(34, 211, 238, .3);
}
.step h2 { font-size: clamp(1rem, 3.2vw, 1.15rem); font-weight: 800; }
.step p { color: var(--muted); font-size: .92rem; margin-bottom: .5rem; }
.step ul { color: var(--muted); font-size: .9rem; padding-inline-start: 1.25rem; margin: .5rem 0; }
.step li { margin-bottom: .3rem; }

.file-tag {
  display: inline-flex; align-items: center; direction: ltr;
  font-family: ui-monospace, 'Courier New', monospace; font-size: .7rem;
  color: var(--cyan); background: rgba(34, 211, 238, .1);
  border: 1px solid rgba(34, 211, 238, .22);
  padding: .15rem .6rem; border-radius: 999px;
}
pre {
  direction: ltr; text-align: left; overflow-x: auto;
  background: #070c18; border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .9rem 1rem; margin: .6rem 0;
}
code { font-family: ui-monospace, 'Courier New', monospace; font-size: .8rem; line-height: 1.8; color: #cfe3ff; }
p code, li code { background: var(--panel-2); padding: .1rem .35rem; border-radius: 5px; color: var(--cyan); }
.tip {
  border-inline-start: 3px solid var(--amber); background: rgba(251, 191, 36, .07);
  padding: .7rem 1rem; border-radius: var(--radius-sm);
  font-size: .88rem; color: var(--text); margin: .7rem 0;
}
.tip strong { color: var(--amber); }
