/* ═══════════════════════════════════════════════
   MAZE – Dark Retro Theme
   ═══════════════════════════════════════════════ */

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

html, body {
  margin: 0;
  padding: 0;
  background: #080808;
  color: #e2e8f0;
  font-family: monospace;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Account Bar ── */
.account-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 42px;
  background: rgba(8,8,8,0.97);
  border-bottom: 1px solid rgba(0,255,65,0.15);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  z-index: 1000;
}
.acc-btn {
  background: transparent;
  border: 1px solid rgba(0,255,65,0.35);
  color: #00ff41;
  font-family: monospace;
  font-size: .72rem;
  padding: 4px 10px;
  cursor: pointer;
  letter-spacing: 1px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.acc-btn:hover { background: rgba(0,255,65,0.1); }
.acc-btn.acc-dim { color: #94a3b8; border-color: rgba(148,163,184,0.3); }
.acc-btn.acc-dim:hover { background: rgba(148,163,184,0.08); }
.acc-btn.acc-cyan { color: #22d3ee; border-color: rgba(34,211,238,0.4); }
.acc-name {
  font-family: monospace;
  font-size: .8rem;
  color: #00ff41;
  margin-left: 4px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Auth Modal ── */
.mz-auth-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  backdrop-filter: blur(4px);
}
.mz-auth-modal.hidden { display: none; }
.mz-auth-box {
  background: #0a0a0a;
  border: 1px solid rgba(0,255,65,0.25);
  padding: 24px 20px;
  width: min(360px, 94vw);
  position: relative;
}
.mz-auth-close {
  position: absolute; top: 8px; right: 12px;
  background: none; border: none;
  color: #00ff41; font-size: 1.1rem; cursor: pointer;
}
.mz-auth-tabs { display: flex; gap: 0; margin-bottom: 16px; }
.mz-auth-tab {
  flex: 1; background: transparent;
  border: 1px solid rgba(0,255,65,0.2);
  color: #64748b; font-family: monospace;
  font-size: .75rem; padding: 7px; cursor: pointer;
  letter-spacing: 1px;
}
.mz-auth-tab.active { color: #00ff41; border-color: #00ff41; background: rgba(0,255,65,0.06); }
.mz-auth-content { display: flex; flex-direction: column; gap: 8px; }
.mz-auth-content.hidden { display: none; }
.mz-auth-error { color: #f87171; font-size: .8rem; }
.mz-auth-error.hidden { display: none; }

/* ── Inputs ── */
.mz-input {
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(0,255,65,0.2);
  color: #e2e8f0;
  font-family: monospace;
  font-size: .85rem;
  padding: 9px 12px;
  width: 100%;
  outline: none;
}
.mz-input:focus { border-color: rgba(0,255,65,0.5); }

/* ── Buttons ── */
.btn-primary {
  background: transparent;
  border: 1px solid #00ff41;
  color: #00ff41;
  font-family: monospace;
  font-size: .8rem;
  padding: 9px 18px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: background .15s;
}
.btn-primary:hover { background: rgba(0,255,65,0.1); }
.btn-primary:disabled { opacity: .45; cursor: default; }

.btn-secondary {
  background: transparent;
  border: 1px solid rgba(148,163,184,0.35);
  color: #94a3b8;
  font-family: monospace;
  font-size: .8rem;
  padding: 9px 18px;
  cursor: pointer;
  letter-spacing: 1px;
}
.btn-secondary:hover { background: rgba(148,163,184,0.08); color: #e2e8f0; }

/* ═══════════════════════════════════════════════
   LEVEL SELECTION
   ═══════════════════════════════════════════════ */
#level-select-screen {
  max-width: 860px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}
.mz-header { text-align: center; margin-bottom: 20px; }
.mz-logo { font-size: 2.4rem; color: #00ff41; margin-bottom: 8px; }
.mz-header h1 {
  font-size: 2rem;
  color: #e2e8f0;
  letter-spacing: 4px;
  margin: 0 0 6px;
}
.mz-subtitle { color: #64748b; font-size: .85rem; margin: 0; }

.diff-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 20px;
}
.diff-tab {
  background: transparent;
  border: 1px solid rgba(148,163,184,0.25);
  color: #64748b;
  font-family: monospace;
  font-size: .75rem;
  padding: 6px 14px;
  cursor: pointer;
  letter-spacing: 1px;
}
.diff-tab.active { border-color: #00ff41; color: #00ff41; background: rgba(0,255,65,0.07); }
.diff-tab[data-diff="easy"].active    { border-color: #22c55e; color: #22c55e; }
.diff-tab[data-diff="medium"].active  { border-color: #f59e0b; color: #f59e0b; }
.diff-tab[data-diff="hard"].active    { border-color: #f97316; color: #f97316; }
.diff-tab[data-diff="extreme"].active { border-color: #ef4444; color: #ef4444; }

#level-grid-wrapper {
  overflow-y: auto;
  max-height: calc(100vh - 280px);
}
#level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
  gap: 6px;
}

.level-cell {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(148,163,184,0.18);
  background: rgba(15,23,42,0.6);
  cursor: pointer;
  transition: border-color .15s, background .15s;
  position: relative;
  gap: 2px;
}
.level-cell:hover { border-color: #00ff41; background: rgba(0,255,65,0.07); }
.level-cell .lvl-num {
  font-size: .8rem;
  font-weight: bold;
  color: #94a3b8;
}
.level-cell .lvl-diff-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
}
/* difficulty colors */
.diff-easy    { background: #22c55e; }
.diff-medium  { background: #f59e0b; }
.diff-hard    { background: #f97316; }
.diff-extreme { background: #ef4444; }

.level-cell.completed {
  border-color: rgba(34,197,94,0.4);
  background: rgba(34,197,94,0.07);
}
.level-cell.completed .lvl-num { color: #22c55e; }
.level-cell.completed::after {
  content: '✓';
  position: absolute;
  top: 2px; right: 4px;
  font-size: .6rem;
  color: #22c55e;
}
.level-cell.best-time .lvl-time {
  font-size: .58rem;
  color: #22c55e;
}

.mz-status {
  text-align: center;
  color: #475569;
  font-size: .8rem;
  margin-top: 16px;
}

/* ═══════════════════════════════════════════════
   GAME SCREEN
   ═══════════════════════════════════════════════ */
#game-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 8px 20px;
  min-height: calc(100vh - 42px);
}
#game-screen.hidden { display: none; }

#game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 640px;
  margin-bottom: 10px;
  gap: 8px;
}
#level-badge {
  font-size: .75rem;
  color: #64748b;
  letter-spacing: 1px;
  min-width: 60px;
}
#timer-display {
  font-size: 1.5rem;
  color: #00ff41;
  letter-spacing: 2px;
  font-variant-numeric: tabular-nums;
}
#lives-display {
  display: flex;
  gap: 4px;
  min-width: 60px;
  justify-content: flex-end;
}
.life {
  font-size: 1.1rem;
  color: #ef4444;
  transition: color .2s, transform .2s;
}
.life.lost {
  color: #1e293b;
  transform: scale(0.7);
}

#penalty-banner {
  background: rgba(239,68,68,0.15);
  border: 1px solid rgba(239,68,68,0.4);
  color: #fca5a5;
  font-size: .8rem;
  padding: 6px 16px;
  margin-bottom: 8px;
  text-align: center;
  animation: fadeIn .2s;
  max-width: 640px;
  width: 100%;
}
#penalty-banner.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* ── Maze Grid ── */
#maze-wrapper {
  overflow: auto;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 4px;
}

#maze-grid {
  display: grid;
  /* columns set by JS via style */
  gap: 0;
  position: relative;
}

.mz-cell {
  width: var(--cell-size, 36px);
  height: var(--cell-size, 36px);
  background: #0f172a;
  position: relative;
  cursor: pointer;
  transition: background .1s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mz-cell:hover { background: #1e293b; }

/* Walls as borders */
.mz-cell.wall-top    { border-top:    2px solid #334155; }
.mz-cell.wall-bottom { border-bottom: 2px solid #334155; }
.mz-cell.wall-left   { border-left:   2px solid #334155; }
.mz-cell.wall-right  { border-right:  2px solid #334155; }

/* Outer maze border */
.mz-cell.outer-top    { border-top:    2px solid #475569; }
.mz-cell.outer-bottom { border-bottom: 2px solid #475569; }
.mz-cell.outer-left   { border-left:   2px solid #475569; }
.mz-cell.outer-right  { border-right:  2px solid #475569; }

/* Path visited */
.mz-cell.visited { background: #0d2034; }
.mz-cell.visited:hover { background: #1a3050; }

/* Dead-end shake animation */
.mz-cell.deadend-flash {
  animation: deadendFlash .4s;
}
@keyframes deadendFlash {
  0%   { background: rgba(239,68,68,0.3); }
  100% { background: #0d2034; }
}

/* Current player position */
.mz-cell.current .cell-player {
  width: 60%;
  height: 60%;
  border-radius: 50%;
  background: #00ff41;
  box-shadow: 0 0 8px rgba(0,255,65,0.7);
}

/* Exit cell */
.mz-cell.exit-cell { background: rgba(34,197,94,0.08); }
.mz-cell.exit-cell::after {
  content: '★';
  position: absolute;
  font-size: .9rem;
  color: rgba(34,197,94,0.5);
  pointer-events: none;
}

/* Start cell */
.mz-cell.start-cell { background: rgba(0,255,65,0.04); }

/* Dead-end indicator */
.mz-cell.dead-end-marker {
  background: rgba(239,68,68,0.04);
}

/* Cell inner content */
.cell-player {
  width: 60%;
  height: 60%;
  border-radius: 50%;
  position: absolute;
  pointer-events: none;
}
.cell-player.self  { background: #00ff41; box-shadow: 0 0 8px rgba(0,255,65,0.6); }
.cell-player.opp   { background: #f97316; box-shadow: 0 0 8px rgba(249,115,22,0.6); opacity: .7; }

#game-footer {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ═══════════════════════════════════════════════
   RESULT OVERLAY
   ═══════════════════════════════════════════════ */
#result-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1500;
  backdrop-filter: blur(6px);
  padding: 16px;
}
#result-overlay.hidden { display: none; }
#result-card {
  background: #0a0a0a;
  border: 1px solid rgba(0,255,65,0.25);
  padding: 24px 20px;
  width: min(420px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#result-icon { font-size: 2rem; text-align: center; }
#result-title {
  text-align: center;
  font-size: 1.2rem;
  color: #00ff41;
  letter-spacing: 2px;
  margin: 0;
}
#result-stats {
  font-size: .85rem;
  color: #94a3b8;
  text-align: center;
  line-height: 1.7;
}
#result-stats strong { color: #e2e8f0; }
#result-rank {
  text-align: center;
  font-size: .9rem;
  color: #f59e0b;
}

/* Leaderboard */
.lb-title {
  font-size: .75rem;
  color: #475569;
  letter-spacing: 1px;
  border-bottom: 1px solid #1e293b;
  padding-bottom: 4px;
  margin-bottom: 6px;
}
.lb-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .78rem;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.lb-rank { color: #475569; min-width: 24px; }
.lb-rank.gold   { color: #f59e0b; }
.lb-rank.silver { color: #94a3b8; }
.lb-rank.bronze { color: #b45309; }
.lb-name { flex: 1; color: #e2e8f0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-name.own { color: #00ff41; }
.lb-time { color: #22c55e; font-variant-numeric: tabular-nums; }
.lb-penalty { color: #f87171; font-size: .72rem; }

/* Snackbar */
#snackbar {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #e2e8f0;
  padding: 10px 20px;
  font-family: monospace;
  font-size: .85rem;
  border: 1px solid rgba(0,255,65,0.2);
  z-index: 9999;
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
  white-space: nowrap;
}
#snackbar.show { opacity: 1; }

/* ── Responsive ── */
@media (max-width: 480px) {
  #timer-display { font-size: 1.2rem; }
  .level-cell { min-width: 48px; }
}
