:root {
  --bg-color: #0f172a;
  --panel-bg: #1e293b;
  --wall-color: #334155;
  --path-color: #f8fafc;
  --primary: #38bdf8;
  --success: #4ade80;
  --warning: #fb923c;
  --purple: #a855f7;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-color);
  color: white;
  font-family: 'Montserrat', 'Segoe UI', system-ui, sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  touch-action: manipulation;
}

.game-wrapper {
  width: 100%;
  /* лабиринт квадратный: ширину ограничиваем высотой окна минус табло и кнопки */
  max-width: max(280px, min(500px, 100vh - 250px));
  padding: 15px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.stats-panel {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat-box {
  background: var(--panel-bg);
  padding: 10px;
  border-radius: 12px;
  text-align: center;
  box-shadow: 0 4px 6px rgba(0,0,0,0.3);
  border-bottom: 3px solid transparent;
}

.stat-box.glow-green { border-color: var(--success); }
.stat-box.glow-blue { border-color: var(--primary); }
.stat-box.glow-orange { border-color: var(--warning); }
.stat-box.glow-purple { border-color: var(--purple); }

.label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  color: #94a3b8;
  letter-spacing: 1px;
  margin-bottom: 5px;
}

.value {
  font-size: 14px;
  font-weight: 600;
}

.board-container {
  position: relative;
  background: var(--panel-bg);
  padding: 10px;
  border-radius: 16px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.5);
  aspect-ratio: 1 / 1;
}

#game-board {
  display: grid;
  width: 100%;
  height: 100%;
  gap: 2px;
  background-color: #000;
  border-radius: 8px;
  overflow: hidden;
}

.cell {
  border-radius: 2px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: clamp(10px, 3.5vw, 24px);
}

.wall { background-color: var(--wall-color); }
.path { background-color: var(--path-color); }

.robot { animation: bounce 0.3s ease-in-out; }
@keyframes bounce {
  0% { transform: scale(0.8); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.d-pad {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(2, 52px);
  gap: 10px;
  justify-content: center;
}

.btn-dir {
  background: var(--panel-bg);
  border: none;
  border-radius: 12px;
  color: white;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 0 #0f172a, inset 0 2px 0 rgba(255,255,255,0.1);
  transition: transform 0.1s, box-shadow 0.1s;
}

.btn-dir:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 #0f172a, inset 0 2px 0 rgba(255,255,255,0.1);
}

.up { grid-column: 2; grid-row: 1; }
.left { grid-column: 1; grid-row: 2; }
.down { grid-column: 2; grid-row: 2; }
.right { grid-column: 3; grid-row: 2; }

.hint {
  text-align: center;
  color: #64748b;
  font-size: 12px;
  margin-top: 10px;
}

#overlay {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border-radius: 16px;
  z-index: 10;
}

#overlay.hidden { display: none; }

#overlay h2 { color: var(--success); margin: 0 0 10px 0; font-size: 28px; }
#overlay p { color: #fff; margin-bottom: 20px; }

#restart-btn {
  background: var(--primary);
  color: #0f172a;
  border: none;
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 800;
  border-radius: 8px;
  cursor: pointer;
}
/* Широкое окно (компьютер, фрейм на сайте): лабиринт слева, табло и кнопки справа */
@media (min-aspect-ratio: 5/4) {
  body { height: 100vh; overflow: hidden; }
  .game-wrapper {
    max-width: none;
    width: auto;
    display: grid;
    grid-template-columns: calc(100vh - 30px) 240px;
    grid-template-rows: auto 1fr;
    grid-template-areas: "board stats" "board controls";
  }
  .board-container { grid-area: board; box-sizing: border-box; }
  .stats-panel { grid-area: stats; grid-template-columns: 1fr; }
  .controls { grid-area: controls; justify-content: flex-end; }
  .cell { font-size: min(3vh, 24px); }
}
