* {
  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: 14px;
}

.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(86vmin, 620px);
  height: min(86vmin, 620px);
  margin: 2px auto 0;
}

.square {
  min-height: 0;
  width: 100%;
  height: 100%;
  border: 1px solid #2f3848;
  border-radius: 0;
  padding: 0;
  background: white;
  box-shadow: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
}

.square:active {
  transform: none;
}

.square.attacked {
  background: #e4e7ec;
}

.square.danger {
  background: #e74c3c;
}

.crown-icon {
  width: 82%;
  height: 82%;
  object-fit: contain;
  pointer-events: none;
}

.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;
}

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

  .game-shell {
    width: 100%;
    min-height: calc(100svh - 20px);
    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;
  }

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

  .square {
    min-height: 0;
    padding: 0;
    font-size: 1rem;
  }

  .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;
  }
}
