:root {
  --maze-bg: #07111f;
  --maze-panel: #0f172a;
  --maze-line: rgba(148, 163, 184, 0.22);
  --maze-text: #e8edf5;
  --maze-muted: #94a3b8;
  --maze-accent: #3b82f6;
  --maze-accent-text: #93c5fd;
  --maze-gold: #fbbf24;
}

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

html, body {
  min-height: 100%;
  background: radial-gradient(ellipse at 50% 0%, #15233a 0%, var(--maze-bg) 70%);
  color: var(--maze-text);
  font-family: "Vazirmatn", sans-serif;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body { min-height: 100vh; min-height: 100dvh; }

.maze-stage {
  position: relative;
  z-index: 1;
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 12px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.maze-masthead {
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--maze-line);
  padding-bottom: 10px;
}

.maze-masthead h1 {
  font-size: clamp(1.2rem, 4vw, 1.6rem);
  font-weight: 800;
}

.maze-masthead p {
  color: var(--maze-muted);
  font-size: 0.82rem;
  margin-top: 2px;
}

.maze-stats { display: flex; gap: 18px; }
.maze-stat { text-align: center; min-width: 54px; }
.maze-stat .l { font-size: 0.7rem; color: var(--maze-accent-text); letter-spacing: 0.06em; }
.maze-stat .v { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.maze-frame {
  position: relative;
  padding: 10px;
  background: linear-gradient(160deg, #15233a, var(--maze-panel));
  border-radius: 14px;
  border: 1px solid var(--maze-line);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

.cw { position: relative; line-height: 0; border-radius: 8px; overflow: hidden; touch-action: none; }
canvas { display: block; }
#over { position: absolute; top: 0; left: 0; }

.wo {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(7, 17, 31, 0.78);
  backdrop-filter: blur(4px);
  opacity: 0; pointer-events: none; transition: opacity 0.35s;
}
.wo.show { opacity: 1; pointer-events: auto; }
.wc {
  background: #0f172a;
  border: 1px solid rgba(59, 130, 246, 0.35);
  border-radius: 14px;
  padding: 24px 28px;
  text-align: center;
  max-width: 280px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.45);
}
.wc h2 { color: var(--maze-accent-text); font-size: 1.15rem; margin-bottom: 6px; }
.wc p { color: var(--maze-muted); font-size: 0.85rem; margin-bottom: 14px; line-height: 1.7; }
.ws { display: flex; gap: 22px; justify-content: center; margin-bottom: 16px; }

.ctrls {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.dg {
  display: flex; gap: 5px;
  background: rgba(15, 23, 42, 0.7);
  padding: 4px; border-radius: 10px;
  border: 1px solid var(--maze-line);
}
button {
  font-family: inherit;
  font-size: 0.78rem;
  color: var(--maze-muted);
  background: transparent;
  border: 1px solid transparent;
  padding: 8px 13px;
  border-radius: 8px;
  cursor: pointer;
  transition: 0.15s ease;
}
.dg button.active {
  background: var(--maze-accent);
  color: #fff;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}
.dg button:not(.active):hover { color: #fff; background: rgba(59, 130, 246, 0.12); }
.bp { background: var(--maze-accent); color: #fff; border-color: transparent; }
.bp:hover { background: #2563eb; }
.bh { border-color: rgba(147, 197, 253, 0.35); color: var(--maze-accent-text); }
.bh:hover { background: rgba(59, 130, 246, 0.12); }
.bh.muted { opacity: 0.4; pointer-events: none; }
.ag { display: flex; gap: 8px; }

.dp {
  direction: ltr;
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(3, 56px);
  gap: 4px;
  margin-top: 2px;
}
.dp button {
  width: 56px; height: 56px; font-size: 22px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--maze-line);
  color: var(--maze-accent-text);
  background: rgba(15, 23, 42, 0.8);
  border-radius: 12px;
}
.dp button:active { background: var(--maze-accent); color: #fff; transform: scale(0.93); }
.dp .e { border: none; background: none; pointer-events: none; }

.leg {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
  font-size: 0.8rem;
  color: var(--maze-muted);
  padding-top: 6px;
  border-top: 1px solid var(--maze-line);
}
.leg .i { display: flex; align-items: center; gap: 5px; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw.hint { background: var(--maze-accent-text); }
.sw.exit { background: radial-gradient(circle, #fff8d6, var(--maze-gold)); }
.ky {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px;
  border: 1px solid var(--maze-line);
  border-radius: 4px;
  font-size: 9px;
  color: var(--maze-accent-text);
  background: rgba(15, 23, 42, 0.8);
}

@media (min-width: 641px) { .dp { display: none; } }
@media (max-width: 640px) {
  .maze-masthead { flex-direction: column; align-items: flex-start; }
  .maze-stats { align-self: stretch; justify-content: space-between; width: 100%; }
  .ctrls { flex-direction: column; align-items: stretch; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
