:root {
  --bg: #0b0f14;
  --panel: #10161f;
  --board: #0e1622;
  --line: rgba(148, 163, 184, 0.08);
  --accent: #a3e635;
  --accent-dark: #4d7c0f;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --danger: #ef4444;
}

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

html,
body {
  height: 100%;
}

body {
  background:
    radial-gradient(1200px 600px at 50% -10%, #16233a 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  display: flex;
  justify-content: center;
  min-height: 100%;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

.game-shell {
  width: min(480px, 100%);
  padding: 20px 16px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---------- Шапка ---------- */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hud__title {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: linear-gradient(90deg, var(--accent), #34d399);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hud__stats {
  display: flex;
  gap: 10px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px 14px;
  min-width: 76px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat__label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

.stat__value {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat__value.bump {
  animation: bump 0.25s ease;
}

@keyframes bump {
  50% { transform: scale(1.25); color: var(--accent); }
}

/* ---------- вторая строка HUD: уровень / жизни / яблоки ---------- */
.hud2 {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: -4px;
}

.chip {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

#livesChip { letter-spacing: 2px; }

/* ---------- Поле ---------- */
.board-wrap {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  box-shadow:
    0 0 0 1px var(--line),
    0 0 40px rgba(163, 230, 53, 0.07),
    0 16px 40px rgba(0, 0, 0, 0.5);
}

#board {
  display: block;
  width: 100%;
  touch-action: none;
  /* высота задаётся из JS (resize) — квадратная, без зависимости от aspect-ratio */
}

/* ---------- Оверлеи (старт / пауза / конец игры) ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 12, 18, 0.74);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  transition: opacity 0.2s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay__card {
  text-align: center;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.overlay__title {
  font-size: 30px;
  font-weight: 800;
}

.overlay__text {
  color: var(--muted);
  max-width: 280px;
  line-height: 1.45;
}

.overlay__hint {
  font-size: 12.5px;
  color: var(--muted);
  opacity: 0.8;
}

/* ---------- Кнопки ---------- */
.btn {
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  padding: 11px 26px;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease;
}

.btn:active {
  transform: scale(0.96);
}

.btn--primary {
  background: linear-gradient(180deg, var(--accent), #84cc16);
  color: #101a02;
  box-shadow: 0 6px 20px rgba(163, 230, 53, 0.25);
}

.btn--primary:hover {
  filter: brightness(1.08);
}

.btn--ghost {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 9px 18px;
}

.btn--ghost:hover {
  border-color: rgba(163, 230, 53, 0.4);
}

.overlay__btns {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.toolbar {
  display: flex;
  justify-content: center;
  gap: 10px;
}

/* ---------- Крестовина для телефона ---------- */
.dpad {
  display: none;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(2, 64px);
  gap: 8px;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
}

.dpad__btn {
  font-size: 20px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
  touch-action: manipulation;
}

.dpad__btn:active {
  background: var(--accent-dark);
  border-color: var(--accent);
}

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

@media (hover: none) and (pointer: coarse) {
  .dpad { display: grid; }
}

body.touch .dpad { display: grid; }

/* ---------- Подвал ---------- */
.footer {
  text-align: center;
  margin-top: 4px;
}

.footer__link {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  transition: color 0.15s ease;
}

.footer__link:hover {
  color: var(--accent);
}
