/* ── Design tokens ── */
:root {
  --bg: #070b14;
  --bg-2: #0b1220;
  --card: rgba(255, 255, 255, .05);
  --hover: rgba(255, 255, 255, .09);
  --border: rgba(255, 255, 255, .08);
  --border-strong: rgba(255, 255, 255, .18);
  --text: #f0f3fa;
  --muted: #8b93a7;
  --primary: #dc2626;
  --secondary: #2563eb;
  --accent: #22c55e;
  --cyan: #22d3ee;
  --violet: #a855f7;
  --rose: #fb7185;
  --amber: #fbbf24;
  --r-sm: 8px;
  --r: 14px;
  --r-lg: 20px;
  --shadow: 0 4px 24px rgba(0, 0, 0, .45);
  --shadow-lg: 0 16px 60px rgba(0, 0, 0, .6);
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: 'Cairo', ui-sans-serif, system-ui, sans-serif;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
.glow {
  position: fixed; inset: -30% -20% auto -20%; height: 65vh; pointer-events: none; z-index: 0;
  background: radial-gradient(ellipse at 50% 0%, rgba(37, 99, 235, .30), transparent 60%),
              radial-gradient(ellipse at 80% 10%, rgba(220, 38, 38, .18), transparent 55%);
}
.mono, .hud-value, .footer-mono, .result-cell b { font-family: 'Orbitron', 'JetBrains Mono', monospace; letter-spacing: .02em; }
svg { width: 18px; height: 18px; stroke-width: 1.75; }
a { color: inherit; }

/* ── Navbar ── */
.navbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0 clamp(1rem, 4vw, 2.5rem); height: 64px;
  background: rgba(7, 11, 20, .82); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.nav-brand { display: flex; align-items: center; gap: .6rem; }
.nav-mark {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  box-shadow: 0 6px 20px rgba(220, 38, 38, .35); color: #fff;
}
.nav-mark svg { width: 19px; height: 19px; }
.nav-logo { font-weight: 800; font-size: 1.05rem; letter-spacing: -.01em; }
.nav-links { display: flex; gap: 1.4rem; }
.nav-link { color: var(--muted); text-decoration: none; font-size: .9rem; font-weight: 600; transition: color .2s; }
.nav-link:hover { color: var(--text); }
.nav-actions { display: flex; gap: .5rem; }
.icon-btn {
  display: grid; place-items: center; width: 38px; height: 38px; cursor: pointer;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px; color: var(--text);
  transition: transform .15s ease, background .2s ease, border-color .2s ease;
}
.icon-btn:hover { transform: translateY(-2px); background: var(--hover); border-color: var(--border-strong); }
.icon-btn.off { color: var(--muted); }

/* ── Buttons & badges ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem; cursor: pointer;
  padding: .62rem 1.3rem; border-radius: 999px; border: 1px solid transparent;
  font-family: inherit; font-size: .92rem; font-weight: 700;
  transition: transform .15s ease, box-shadow .15s ease, background .2s ease;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: linear-gradient(135deg, var(--primary), #f43f5e); color: #fff; box-shadow: 0 8px 30px rgba(220, 38, 38, .38); }
.btn-primary:hover { box-shadow: 0 14px 42px rgba(220, 38, 38, .5); }
.btn-ghost { background: var(--card); border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover { background: var(--hover); }
.btn-sm { padding: .45rem 1rem; font-size: .82rem; }
.btn-lg { padding: .85rem 2rem; font-size: 1rem; width: 100%; }
.btn-full { width: 100%; }
.badge {
  font-size: .66rem; font-weight: 700; letter-spacing: .14em; padding: .16rem .5rem; border-radius: 999px;
  background: rgba(34, 197, 94, .14); color: var(--accent); font-family: 'JetBrains Mono', monospace;
}

/* ── Layout ── */
.layout {
  position: relative; z-index: 1;
  display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1.5rem;
  max-width: 1280px; margin: 0 auto; padding: 1.75rem clamp(1rem, 4vw, 2.5rem);
}
.stage-wrap { min-width: 0; display: flex; flex-direction: column; gap: .9rem; }

/* ── HUD ── */
.hud {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .5rem;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r);
  backdrop-filter: blur(12px); padding: .6rem .75rem;
}
.hud-cell { display: flex; flex-direction: column; align-items: center; gap: .1rem; min-width: 0; }
.hud-label { font-size: .66rem; font-weight: 700; letter-spacing: .08em; color: var(--muted); }
.hud-value { font-size: clamp(1rem, 2.4vw, 1.3rem); font-weight: 900; color: var(--text); }
.hud-lives { display: flex; gap: .2rem; align-items: center; height: 1.6rem; }
.hud-lives svg { width: 15px; height: 15px; fill: var(--rose); stroke: var(--rose); }

/* ── Stage & canvas ── */
.stage {
  position: relative; border-radius: var(--r-lg); overflow: hidden;
  border: 1px solid var(--border-strong);
  background: radial-gradient(ellipse at 50% 0%, #131c33 0%, #070b14 60%);
  box-shadow: var(--shadow-lg);
  touch-action: none;
}
#game { display: block; width: 100%; height: clamp(380px, 62vh, 660px); cursor: crosshair; }
.overlay {
  position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; padding: 1rem;
  background: rgba(4, 7, 14, .72); backdrop-filter: blur(6px); animation: fadeIn .25s ease;
}
.overlay.hidden { display: none; }
.panel {
  width: min(520px, 94%); text-align: center; padding: 1.75rem 1.5rem;
  background: linear-gradient(180deg, rgba(23, 32, 54, .96), rgba(11, 18, 32, .96));
  border: 1px solid var(--border-strong); border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  animation: fadeUp .35s ease;
}
.panel-sm { width: min(420px, 92%); }
.panel-icon {
  display: grid; place-items: center; width: 54px; height: 54px; margin: 0 auto .75rem;
  border-radius: 16px; background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff; box-shadow: 0 10px 34px rgba(220, 38, 38, .4);
}
.panel-icon svg { width: 26px; height: 26px; }
.panel-icon.danger { background: linear-gradient(135deg, #7f1d1d, #dc2626); }
.panel-title { font-size: clamp(1.4rem, 4vw, 2rem); font-weight: 800; letter-spacing: -.02em; }
.panel-sub { color: var(--muted); font-size: .92rem; margin: .5rem auto 1.1rem; max-width: 42ch; }
.keys { margin-top: .9rem; font-size: .78rem; color: var(--muted); }
.keys b { color: var(--text); font-family: 'JetBrains Mono', monospace; }
.row-btns { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; }
.row-btns .btn { flex: 1 1 auto; min-width: 140px; }

/* ── Segmented difficulty control ── */
.seg {
  display: flex; gap: .25rem; padding: .25rem; margin-bottom: 1rem;
  background: rgba(255, 255, 255, .04); border: 1px solid var(--border); border-radius: 999px;
}
.seg-btn {
  flex: 1; padding: .45rem .5rem; cursor: pointer; border: none; background: transparent;
  border-radius: 999px; color: var(--muted); font-family: inherit; font-size: .85rem; font-weight: 700;
  transition: background .2s ease, color .2s ease;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: linear-gradient(135deg, var(--secondary), #3b82f6); color: #fff; box-shadow: 0 6px 22px rgba(37, 99, 235, .4); }

/* ── Results ── */
.result-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; margin-bottom: 1.1rem; }
.result-cell {
  display: flex; flex-direction: column; gap: .15rem; padding: .6rem;
  background: rgba(255, 255, 255, .04); border: 1px solid var(--border); border-radius: var(--r-sm);
}
.result-cell span { font-size: .7rem; color: var(--muted); font-weight: 700; }
.result-cell b { font-size: 1.25rem; }
.result-cell b.new-best { color: var(--accent); }

/* ── Toolbar ── */
.toolbar { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.toolbar-hint {
  margin-inline-start: auto; font-size: .78rem; color: var(--muted);
  padding: .3rem .7rem; border: 1px dashed var(--border-strong); border-radius: 999px;
  font-family: 'JetBrains Mono', monospace;
}
.toolbar-hint.on { color: var(--cyan); border-color: rgba(34, 211, 238, .5); }

/* ── Side cards ── */
.side { display: flex; flex-direction: column; gap: 1rem; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r);
  backdrop-filter: blur(12px); box-shadow: var(--shadow); padding: 1.1rem 1.15rem;
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--border-strong); }
.card-title { display: flex; align-items: center; gap: .5rem; font-size: .95rem; font-weight: 800; margin-bottom: .8rem; }
.card-title svg { width: 17px; height: 17px; color: var(--secondary); }
.stat-row { display: flex; align-items: center; justify-content: space-between; padding: .35rem 0; border-bottom: 1px dashed rgba(255, 255, 255, .06); font-size: .85rem; color: var(--muted); }
.stat-row:last-child { border-bottom: none; }
.stat-row b { color: var(--text); font-family: 'JetBrains Mono', monospace; }
.legend { list-style: none; display: flex; flex-direction: column; gap: .45rem; font-size: .83rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: .5rem; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: 0 0 10px currentColor; }
.c-cyan { background: var(--cyan); color: var(--cyan); }
.c-amber { background: var(--amber); color: var(--amber); }
.c-violet { background: var(--violet); color: var(--violet); }
.c-rose { background: var(--rose); color: var(--rose); }
.scores { list-style: none; display: flex; flex-direction: column; gap: .35rem; margin-bottom: .8rem; }
.scores li {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .4rem .6rem; border-radius: var(--r-sm); background: rgba(255, 255, 255, .03);
  font-size: .84rem; border: 1px solid transparent;
}
.scores li.top { border-color: rgba(251, 191, 36, .4); background: rgba(251, 191, 36, .08); }
.scores li span { color: var(--muted); font-size: .74rem; }
.scores li b { font-family: 'Orbitron', monospace; }
.scores .empty { justify-content: center; color: var(--muted); font-size: .82rem; }

/* ── Sections ── */
.section { position: relative; z-index: 1; max-width: 1280px; margin: 0 auto; padding: 2.5rem clamp(1rem, 4vw, 2.5rem) 1rem; }
.section-title { font-size: clamp(1.4rem, 3.4vw, 2rem); font-weight: 800; letter-spacing: -.02em; }
.section-lead { color: var(--muted); margin: .4rem 0 1.5rem; max-width: 62ch; }
.grid { display: grid; gap: 1.1rem; }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.feature { padding: 1.4rem 1.25rem; }
.feature-icon {
  display: grid; place-items: center; width: 44px; height: 44px; margin-bottom: .8rem; border-radius: 13px;
  background: rgba(37, 99, 235, .16); color: #7aa2ff; border: 1px solid rgba(37, 99, 235, .3);
}
.feature-icon svg { width: 22px; height: 22px; }
.feature h3 { font-size: 1.02rem; font-weight: 800; margin-bottom: .35rem; }
.feature p { color: var(--muted); font-size: .88rem; }

/* ── Footer ── */
.footer {
  position: relative; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap; max-width: 1280px; margin: 2.5rem auto 0; padding: 1.25rem clamp(1rem, 4vw, 2.5rem) 2.5rem;
  border-top: 1px solid var(--border); color: var(--muted); font-size: .82rem;
}
.footer-mono { font-size: .68rem; letter-spacing: .18em; }

/* ── Toasts ── */
.toast-wrap { position: absolute; bottom: 1rem; inset-inline-start: 1rem; z-index: 12; display: flex; flex-direction: column; gap: .5rem; pointer-events: none; }
.toast {
  padding: .55rem 1rem; border-radius: var(--r-sm); font-size: .85rem; font-weight: 600;
  background: rgba(8, 13, 24, .92); border: 1px solid var(--border-strong); box-shadow: var(--shadow-lg);
  animation: fadeUp .28s ease;
}
.toast.success { border-color: rgba(34, 197, 94, .5); color: var(--accent); }
.toast.info { border-color: rgba(34, 211, 238, .5); color: var(--cyan); }
.toast.warn { border-color: rgba(251, 113, 133, .5); color: var(--rose); }

/* ── Animations ── */
@keyframes fadeUp { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ── Responsive ── */
@media (max-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
  .nav-links { display: none; }
}
@media (max-width: 560px) {
  .hud { grid-template-columns: repeat(3, 1fr); row-gap: .5rem; }
  #game { height: 58vh; min-height: 340px; }
  .toolbar-hint { margin-inline-start: 0; width: 100%; text-align: center; }
  .navbar { height: 58px; }
  .nav-logo { font-size: .95rem; }
}
