/* ── حامي النجوم — design tokens ── */
:root {
  --bg: #0F172A;
  --bg-deep: #070c17;
  --bg-card: rgba(255, 255, 255, .05);
  --bg-hover: rgba(255, 255, 255, .09);
  --border: rgba(255, 255, 255, .08);
  --border-strong: rgba(255, 255, 255, .18);
  --text: #FFFFFF;
  --text-muted: #94A3B8;
  --primary: #DC2626;
  --primary-soft: rgba(220, 38, 38, .18);
  --secondary: #2563EB;
  --secondary-bright: #60A5FA;
  --accent: #22C55E;
  --accent-soft: rgba(34, 197, 94, .16);
  --warning: #FBBF24;
  --radius-sm: 8px;
  --radius: 16px;
  --radius-lg: 22px;
  --shadow: 0 4px 24px rgba(0, 0, 0, .45);
  --shadow-lg: 0 18px 60px rgba(0, 0, 0, .55);
  --font: 'Cairo', 'Segoe UI', 'Noto Sans Arabic', ui-sans-serif, system-ui, sans-serif;
  --font-num: 'VT323', 'Cairo', ui-monospace, monospace;
  color-scheme: dark;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font);
  background:
    radial-gradient(circle at 15% -10%, rgba(37, 99, 235, .28), transparent 45%),
    radial-gradient(circle at 88% 4%, rgba(220, 38, 38, .22), transparent 42%),
    var(--bg-deep);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.is-hidden { display: none !important; }

/* ── Navbar ── */
.navbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .75rem 1.5rem;
  background: rgba(7, 12, 23, .78);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex; align-items: center; gap: .55rem;
  font-weight: 800; font-size: 1.05rem; letter-spacing: -.01em;
  color: var(--text); text-decoration: none; transition: opacity .2s;
}
.brand svg { color: var(--secondary-bright); filter: drop-shadow(0 0 8px rgba(96, 165, 250, .7)); }
.brand:hover { opacity: .85; }

.nav-actions { display: flex; align-items: center; gap: .65rem; }

.badge {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .78rem; font-weight: 600; color: var(--text-muted);
  padding: .3rem .7rem; border-radius: 999px;
  background: var(--bg-card); border: 1px solid var(--border);
}
.badge strong { color: var(--accent); font-family: var(--font-num); font-size: 1.05rem; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 999px; cursor: pointer;
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text);
  transition: transform .15s ease, background .2s ease, border-color .2s ease;
}
.icon-btn:hover { background: var(--bg-hover); border-color: var(--border-strong); transform: translateY(-2px); }
.icon-btn[aria-pressed="false"] { color: var(--text-muted); }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .7rem 1.5rem; border-radius: 999px; border: none;
  font-family: var(--font); font-size: .95rem; font-weight: 700;
  cursor: pointer; text-decoration: none;
  transition: transform .15s ease, box-shadow .15s ease, background .2s ease;
}
.btn-primary {
  background: linear-gradient(135deg, var(--secondary-bright), #3B82F6);
  color: #06101f; box-shadow: 0 8px 30px rgba(59, 130, 246, .38);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 14px 40px rgba(59, 130, 246, .5); }
.btn-ghost { background: transparent; border: 1.5px solid var(--border-strong); color: var(--text); }
.btn-ghost:hover { background: var(--bg-hover); transform: translateY(-2px); }
.btn:active { transform: translateY(0) scale(.98); }
.btn:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--secondary-bright); outline-offset: 2px; }

/* ── Stage layout ── */
.stage {
  max-width: 1220px; margin: 0 auto; padding: 1.5rem 1.25rem 2rem;
  display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1.5rem;
  align-items: start;
}

.board {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: .85rem;
  box-shadow: var(--shadow-lg); backdrop-filter: blur(12px);
  animation: fadeUp .5s ease both;
}

/* ── HUD ── */
.hud {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.25rem;
  padding: .35rem .6rem .8rem;
}
.hud-item { display: flex; align-items: baseline; gap: .45rem; }
.hud-label { font-size: .72rem; font-weight: 700; color: var(--text-muted); letter-spacing: .04em; }
.hud-item strong { font-family: var(--font-num); font-size: 1.5rem; line-height: 1; color: var(--text); }
#hud-score { color: var(--accent); }
.hud-item:nth-child(2) strong { color: var(--secondary-bright); }
.hud-item:nth-child(3) strong { color: var(--warning); }
.lives { display: inline-flex; gap: .3rem; align-items: center; }
.life {
  width: 13px; height: 15px; display: inline-block;
  background: var(--primary); box-shadow: 0 0 10px rgba(220, 38, 38, .75);
  clip-path: polygon(50% 100%, 0% 45%, 12% 0%, 88% 0%, 100% 45%);
}
.life.is-lost { background: rgba(255, 255, 255, .14); box-shadow: none; }

/* ── Playfield ── */
.canvas-wrap {
  position: relative; width: 100%; height: clamp(420px, 68vh, 720px);
  border-radius: var(--radius); overflow: hidden;
  background: #05080f;
  border: 1px solid rgba(96, 165, 250, .18);
  box-shadow: inset 0 0 60px rgba(37, 99, 235, .18);
  touch-action: none;
}
#game { display: block; width: 100%; height: 100%; cursor: crosshair; }

.banner {
  position: absolute; top: 18%; inset-inline: 0; text-align: center;
  font-size: clamp(1.4rem, 4vw, 2.3rem); font-weight: 900; letter-spacing: .02em;
  color: #fff; text-shadow: 0 0 24px rgba(96, 165, 250, .9), 0 0 60px rgba(37, 99, 235, .6);
  opacity: 0; pointer-events: none;
}
.banner.show { animation: bannerIn 1.6s ease forwards; }
@keyframes bannerIn {
  0% { opacity: 0; transform: scale(.8) translateY(12px); }
  22% { opacity: 1; transform: scale(1) translateY(0); }
  78% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.06); }
}

/* ── Screens (start / pause / over) ── */
.screen {
  position: absolute; inset: 0; z-index: 4;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .9rem; padding: 1.75rem 1.4rem; text-align: center;
  background: linear-gradient(180deg, rgba(7, 12, 23, .86), rgba(7, 12, 23, .95));
  backdrop-filter: blur(6px);
  animation: fadeUp .35s ease both;
}
.screen h1 { font-size: clamp(1.8rem, 5vw, 2.9rem); font-weight: 900; letter-spacing: -.03em; line-height: 1.15; }
.screen h2 { font-size: clamp(1.4rem, 4vw, 2rem); font-weight: 900; }
.eyebrow {
  font-size: .74rem; font-weight: 800; letter-spacing: .22em; text-transform: uppercase;
  color: var(--accent);
}
.lead { color: var(--text-muted); font-size: .96rem; max-width: 44ch; }
.hint-line { font-size: .8rem; color: var(--text-muted); opacity: .85; }
.screen-actions { display: flex; flex-wrap: wrap; gap: .6rem; justify-content: center; }
.screen-stats { display: flex; flex-wrap: wrap; gap: 1.75rem; justify-content: center; margin: .25rem 0; }
.screen-stats > div { display: flex; flex-direction: column; gap: .1rem; }
.screen-stats span { font-size: .72rem; font-weight: 700; color: var(--text-muted); }
.screen-stats strong { font-family: var(--font-num); font-size: 1.9rem; line-height: 1; color: var(--text); }
.record {
  font-size: .85rem; font-weight: 800; color: var(--accent);
  background: var(--accent-soft); border: 1px solid rgba(34, 197, 94, .35);
  padding: .3rem .9rem; border-radius: 999px;
}

/* ── Side panel ── */
.side {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.3rem 1.2rem;
  backdrop-filter: blur(12px); box-shadow: var(--shadow);
  animation: fadeUp .55s ease both;
}
.side-title { font-size: 1rem; font-weight: 800; margin-bottom: .8rem; }
.rules { list-style: none; display: flex; flex-direction: column; gap: .7rem; }
.rules li { display: flex; gap: .6rem; font-size: .88rem; color: var(--text-muted); line-height: 1.55; }
.dot { width: 9px; height: 9px; border-radius: 50%; margin-top: .5rem; flex: 0 0 auto; }
.dot-blue { background: var(--secondary-bright); box-shadow: 0 0 10px var(--secondary-bright); }
.dot-red { background: var(--primary); box-shadow: 0 0 10px var(--primary); }
.dot-green { background: var(--accent); box-shadow: 0 0 10px var(--accent); }

.controls { margin-top: 1.1rem; padding-top: 1.1rem; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: .9rem; }
.controls-keys p, .controls-touch p { font-size: .82rem; color: var(--text-muted); }
.keys-grid { display: inline-grid; grid-template-columns: repeat(3, 34px); gap: 5px; margin-bottom: .5rem; }
.kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 30px; height: 30px; padding: 0 .35rem; margin: 0 2px;
  font-family: var(--font-num); font-size: 1.05rem; color: var(--text);
  background: rgba(255, 255, 255, .07); border: 1px solid var(--border-strong);
  border-bottom-width: 2.5px; border-radius: var(--radius-sm);
}
.kbd.is-empty { background: transparent; border-color: transparent; }
.controls-touch { display: flex; align-items: center; gap: .7rem; color: var(--secondary-bright); }
.controls-touch p { color: var(--text-muted); }

/* ── Footer ── */
.foot {
  text-align: center; padding: 1rem 1.5rem 2.5rem;
  color: var(--text-muted); font-size: .82rem;
}

/* ── Animations ── */
@keyframes fadeUp { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

/* ── Responsive ── */
@media (max-width: 980px) {
  .stage { grid-template-columns: 1fr; padding: 1rem .85rem 1.5rem; gap: 1rem; }
  .side { order: 2; }
  .canvas-wrap { height: clamp(400px, 62vh, 620px); }
}
@media (max-width: 640px) {
  .navbar { padding: .6rem .9rem; }
  .badge { display: none; }
  .board { padding: .55rem; border-radius: var(--radius); }
  .hud { gap: .35rem .9rem; }
  .hud-item strong { font-size: 1.3rem; }
  .canvas-wrap { height: min(66vh, 540px); border-radius: var(--radius-sm); }
  .screen { padding: 1.2rem 1rem; gap: .7rem; }
  .screen-stats { gap: 1.2rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
