/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: #1a1a2e;
  color: #e0e0e0;
  font-family: 'Courier New', Courier, monospace;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  user-select: none;
}

/* ── UI bar ── */
#ui-bar {
  display: flex;
  align-items: center;
  gap: 24px;
  font-size: 0.95rem;
  letter-spacing: 0.05em;
}

#level-label  { color: #a0c4ff; font-weight: bold; }
#move-counter { color: #b0b0c0; }
#timer        { color: #80cbc4; font-variant-numeric: tabular-nums; min-width: 4ch; }

#restart-btn {
  background: none;
  border: 1px solid #444;
  color: #ccc;
  padding: 4px 12px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  border-radius: 3px;
  transition: border-color 0.15s, color 0.15s;
}
#restart-btn:hover { border-color: #a0c4ff; color: #a0c4ff; }

/* ── Difficulty filter ── */
#difficulty-filter {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.diff-btn {
  background: none;
  border: 1px solid #333;
  color: #606080;
  padding: 3px 12px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  border-radius: 3px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  white-space: nowrap;
}

/* Active state: border + text take the difficulty colour */
.diff-btn.active              { color: #e0e0e0;  border-color: #606080; background: #ffffff11; }
.diff-btn.diff-easy.active    { color: #69f0ae;  border-color: #69f0ae; background: #69f0ae18; }
.diff-btn.diff-medium.active  { color: #ffeb3b;  border-color: #ffeb3b; background: #ffeb3b18; }
.diff-btn.diff-hard.active    { color: #ff9800;  border-color: #ff9800; background: #ff980018; }
.diff-btn.diff-expert.active  { color: #f44336;  border-color: #f44336; background: #f4433618; }

/* Hover for inactive buttons */
.diff-btn:not(.active):hover { border-color: #505070; color: #909090; }

/* ── Level details bar ── */
#level-details {
  display: flex;
  gap: 20px;
  font-size: 0.8rem;
  color: #606080;
  letter-spacing: 0.04em;
}

.diff-easy   { color: #69f0ae; font-weight: bold; }
.diff-medium { color: #ffeb3b; font-weight: bold; }
.diff-hard   { color: #ff9800; font-weight: bold; }
.diff-expert { color: #f44336; font-weight: bold; }

/* ── Board wrapper ── */
#board-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Board grid ── */
#board {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--tile-size, 48px));
  grid-template-rows:    repeat(var(--rows), var(--tile-size, 48px));
  gap: 2px;
  background: #0d0d1a;
  padding: 2px;
  border: 2px solid #2a2a4a;
  border-radius: 4px;
  overflow: visible;
}

/* ── Tiles ── */
.tile {
  width:  var(--tile-size, 48px);
  height: var(--tile-size, 48px);
  border-radius: 3px;
  transition: background-color 0.04s ease;
}

.tile.floor { background: #1e1e35; }
.tile.wall  { background: #3a3a5a; }

.tile.goal {
  background: #0d3d3d;
  box-shadow: inset 0 0 8px #00bcd4;
  border: 1px solid #00bcd4;
}

.tile.player {
  background: #e040fb;
  box-shadow: 0 0 10px #e040fb88;
  border-radius: 6px;
  position: relative;
  z-index: 2;
}

.tile.player.goal {
  background: #00e5ff;
  box-shadow: 0 0 14px #00e5ffaa;
}

/* ── Overlay container ── */
#overlay {
  position: fixed;
  inset: 0;
  background: #000000aa;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
#overlay.hidden { display: none; }

#overlay-box {
  background: #16213e;
  border: 2px solid #a0c4ff;
  border-radius: 8px;
  padding: 36px 48px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  width: min(480px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
}

/* ── Overlay: shared typography ── */
.overlay-title {
  font-size: 1.4rem;
  color: #a0c4ff;
  letter-spacing: 0.06em;
}

.overlay-meta {
  font-size: 0.9rem;
  color: #909090;
}

.overlay-meta strong { color: #e0e0e0; }

/* ── Overlay: name-entry phase ── */
.name-form {
  display: flex;
  gap: 10px;
  width: 100%;
}

#name-input {
  flex: 1;
  background: #0d0d1a;
  border: 1px solid #444;
  color: #e0e0e0;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 0.9rem;
  border-radius: 4px;
  outline: none;
  transition: border-color 0.15s;
}
#name-input:focus { border-color: #a0c4ff; }

/* ── Shared button style ── */
.primary-btn {
  background: none;
  border: 1px solid #a0c4ff;
  color: #a0c4ff;
  padding: 8px 20px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  border-radius: 4px;
  transition: background 0.15s;
  white-space: nowrap;
}
.primary-btn:hover    { background: #a0c4ff22; }
.primary-btn:disabled { opacity: 0.5; cursor: default; }

/* ── Overlay: leaderboard phase ── */
.lb-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 24px;
  justify-content: center;
  font-size: 0.82rem;
  color: #808098;
}
.lb-stats strong { color: #e0e0e0; }

.lb-scroll {
  width: 100%;
  overflow-x: auto;
}

table.leaderboard {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

table.leaderboard th {
  color: #606080;
  font-weight: normal;
  padding: 4px 10px;
  border-bottom: 1px solid #2a2a4a;
  text-align: left;
}

table.leaderboard td {
  padding: 6px 10px;
  border-bottom: 1px solid #1e1e35;
  color: #c0c0d0;
}

table.leaderboard tr.lb-me td {
  color: #e040fb;
  font-weight: bold;
}

table.leaderboard th:nth-child(1),
table.leaderboard td:nth-child(1) { width: 2em; text-align: center; }

table.leaderboard th:nth-child(3),
table.leaderboard td:nth-child(3),
table.leaderboard th:nth-child(4),
table.leaderboard td:nth-child(4) { text-align: right; font-variant-numeric: tabular-nums; }

.rank-note {
  font-size: 0.82rem;
  color: #909090;
}
.rank-note strong { color: #e040fb; }

.overlay-error {
  font-size: 0.85rem;
  color: #ff7043;
}

/* ── Controls hint ── */
#controls-hint {
  font-size: 0.75rem;
  color: #505070;
  letter-spacing: 0.04em;
}
