:root {
  --bg: #f6f7f8;
  --panel: #ffffff;
  --text: #202327;
  --grid: #d6dade;
  --snake: #2f8f52;
  --food: #d94848;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 1rem;
}

h1 {
  margin: 0 0 0.5rem 0;
  font-size: 1.5rem;
}

.status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.status p {
  margin: 0;
}

.board-wrap {
  position: relative;
  width: min(92vw, 520px);
  height: min(92vw, 520px);
  touch-action: none;
}

.shout {
  position: absolute;
  inset: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: clamp(2.1rem, 9vw, 4.6rem);
  line-height: 1;
  white-space: nowrap;
  text-align: center;
  color: #ff3aa5;
  text-shadow: 0 1px 0 #ffffff, 0 0 12px rgba(0, 0, 0, 0.18);
  pointer-events: none;
}

.shout.shout--ok {
  color: #ff3aa5;
}

.shout.shout--bad {
  color: #d94848;
}

.math-dialog {
  position: absolute;
  inset: 20% 10%;
  background: #ffffff;
  border: 1px solid #b8bec5;
  border-radius: 6px;
  padding: 0.75rem;
  display: grid;
  gap: 0.45rem;
  z-index: 2;
}

.math-dialog--hidden {
  display: none;
}

.math-dialog__question {
  margin: 0;
  font-weight: 600;
}

.math-dialog__timer {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.math-dialog__input {
  border: 1px solid #b8bec5;
  border-radius: 4px;
  padding: 0.45rem 0.5rem;
  font: inherit;
  font-size: 16px;
}

.math-dialog__feedback {
  margin: 0;
  min-height: 1.1rem;
  font-size: 0.9rem;
}

.math-dialog__actions {
  display: flex;
  gap: 0.4rem;
}

.board {
  display: grid;
  border: 1px solid #bcc2c9;
  width: 100%;
  height: 100%;
  background: var(--panel);
}

.cell {
  border: 1px solid var(--grid);
}

.board.board--eat .cell:not(.snake):not(.food) {
  background: #a9dca9;
}

.cell.snake {
  background: var(--snake);
}

.cell.food {
  background: var(--food);
}

.cell.food.food--apple {
  background: #d94848;
}

.cell.food.food--banana {
  background: #e6c532;
}

.controls {
  margin-top: 0.75rem;
  display: grid;
  gap: 0.35rem;
  justify-items: center;
}

.controls > div {
  display: flex;
  gap: 0.35rem;
}

.controls button {
  min-width: 56px;
  min-height: 56px;
  font-size: 1.15rem;
  font-weight: 600;
}

button {
  border: 1px solid #b8bec5;
  background: #fff;
  color: var(--text);
  border-radius: 4px;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  touch-action: manipulation;
}

.actions {
  margin-top: 0.75rem;
  display: flex;
  gap: 0.5rem;
}

.ranking {
  margin-top: 0.75rem;
}

.ranking h2 {
  margin: 0 0 0.25rem 0;
  font-size: 1rem;
}

.ranking ol {
  margin: 0;
  padding-left: 1.25rem;
}

.help {
  margin-top: 0.75rem;
  font-size: 0.9rem;
}

@media (hover: hover) and (pointer: fine) {
  .controls {
    display: none;
  }
}

@media (max-width: 640px) {
  .app {
    max-width: none;
    padding: 0.75rem;
  }

  .status {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.35rem 0.6rem;
    align-items: start;
  }

  .board-wrap {
    width: 100%;
    height: min(92vw, 440px);
  }

  .shout {
    font-size: clamp(1.5rem, 8vw, 2.8rem);
    white-space: normal;
    padding: 0 0.4rem;
  }

  .math-dialog {
    inset: 14% 6%;
    padding: 0.65rem;
  }

  .actions {
    justify-content: center;
  }
}
