* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  padding: 24px 16px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #142033;
  background: #f6f8fb;
  display: flex;
  justify-content: center;
  align-items: center;
}

.game-shell {
  width: min(100%, 720px);
  min-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
}

.game-header h1 {
  margin: 0;
  font-size: clamp(2rem, 8vw, 3.25rem);
  line-height: 1;
}

.game-header p {
  margin: 8px 0 0;
  font-size: clamp(1rem, 3.8vw, 1.2rem);
  color: #4c5870;
}

.controls {
  width: min(100%, 420px);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

button {
  min-height: 52px;
  border: 0;
  border-radius: 8px;
  padding: 14px 18px;
  font: inherit;
  font-size: 1.08rem;
  font-weight: 800;
  color: white;
  background: #2267d8;
  box-shadow: 0 6px 14px rgba(34, 103, 216, 0.25);
  cursor: pointer;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  color: #f8fafc;
  background: #a9b0bd;
  box-shadow: none;
  cursor: not-allowed;
  opacity: 0.72;
  transform: none;
}

#restartBtn {
  background: #cf3d2e;
  box-shadow: 0 6px 14px rgba(207, 61, 46, 0.22);
}

#restartBtn:disabled {
  background: #a9b0bd;
}

#board {
  display: grid;
  gap: 6px;

  width: min(90vmin, 640px);
  height: min(90vmin, 640px);

  margin: 4px auto 0;
}

.size-controls {
  width: min(100%, 320px);
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 64px;
  align-items: center;
  gap: 12px;
}

.size-button {
  min-height: 52px;
  padding: 10px;
  font-size: 1.7rem;
  line-height: 1;
}

.size-label {
  min-height: 52px;
  border: 1px solid #d2d8e4;
  border-radius: 8px;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 800;
  color: #27364d;
}

.square {
  font-size: 3vmin;
  width: 100%;
  height: 100%;
  border: 1px solid #333;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden; /* IMPORTANT: prevents overflow */
}

.knight-icon {
  width: 80%;     /* scale relative to square */
  height: 80%;
  object-fit: contain; /* keeps proportions */
  pointer-events: none;
}

.visited {
  background: #4da3ff;
}

.move-number {
  font-size: 1em;
  font-weight: bold;
  color: white;
}

.available {
  background: #eeeeee;
}

.current {
  background: #2f80ed;
  color: white;
}

.dead {
  background: #e74c3c; /* red */
}

.win {
  background: gold;
}

@media (max-width: 520px) {
  body {
    padding: 10px 6px;
    align-items: center;
  }

  .game-shell {
    width: 100%;
    min-height: calc(100svh - 20px);
    justify-content: center;
    gap: 10px;
  }

  .game-header h1 {
    font-size: 2.2rem;
  }

  .game-header p {
    margin-top: 6px;
    font-size: 1.08rem;
  }

  .controls {
    width: 100%;
    gap: 8px;
  }

  button {
    min-height: 64px;
    padding: 16px 12px;
    font-size: 1.22rem;
  }

  .size-controls {
    width: 100%;
    grid-template-columns: 58px minmax(0, 1fr) 58px;
    gap: 8px;
  }

  .size-button,
  .size-label {
    min-height: 60px;
  }

  .size-button {
    font-size: 1.9rem;
  }

  .size-label {
    font-size: 1.12rem;
  }

  #board {
    width: min(calc(100vw - 12px), 540px);
    height: min(calc(100vw - 12px), 540px);
    gap: 4px;
  }

  .square {
    font-size: 4vmin;
  }
}
