@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');

* {
  box-sizing: border-box;
}

body {
  font-family: 'Roboto', sans-serif;
  background-color: #e9ecef;
  color: #495057;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  margin: 0;
  padding: 20px;
}

main {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 100%;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#game-instructions {
  margin-bottom: 20px;
  text-align: center;
  color: #333;
  font-size: 1rem;
  max-width: 400px;
  line-height: 1.5;
}

#game-instructions p {
  margin: 5px 0;
}

#button-row {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

#new-game-button,
#undo-button {
  font-size: 1.2rem;
  padding: 10px 25px;
  border-radius: 5px;
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: background-color 0.3s, box-shadow 0.3s, opacity 0.3s;
}

#new-game-button {
  background-color: #5cb85c;
  color: white;
}

#new-game-button:hover {
  background-color: #4cae4c;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

#new-game-button:active {
  background-color: #449d44;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

#undo-button {
  background-color: #f0ad4e;
  color: white;
}

#undo-button:hover:not(:disabled) {
  background-color: #ec971f;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

#undo-button:active:not(:disabled) {
  background-color: #d58512;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

#undo-button:disabled {
  background-color: #ccc;
  cursor: not-allowed;
  opacity: 0.6;
}

#game-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 8px;
  width: min(90vw, 450px);
  aspect-ratio: 1;
  box-shadow: 0px 10px 20px rgba(0, 0, 0, 0.15);
  border-radius: 8px;
  padding: 10px;
  background-color: #fff;
}

.grid-item {
  display: flex;
  justify-content: center;
  align-items: center;
  aspect-ratio: 1;
  border: 2px solid #495057;
  border-radius: 6px;
  font-size: clamp(1.5rem, 8vw, 3rem);
  text-transform: uppercase;
  font-weight: bold;
  background-color: #fefefe;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.2s ease;
  user-select: none;
}

.grid-item:hover {
  transform: scale(1.05);
  background-color: #17a2b8;
  color: #ffffff;
}

.grid-item:focus {
  outline: 3px solid #007bff;
  outline-offset: 2px;
}

.selected {
  background-color: #add8e6 !important;
  color: #000000 !important;
  border-color: #0000ff !important;
  transform: scale(1.08);
}

.valid-word {
  background-color: #90ee90 !important;
  color: #ffffff !important;
  border-color: #008000 !important;
}

#stats-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 20px;
  margin-top: 20px;
  text-align: center;
}

#move-counter,
#valid-words-counter,
#best-score {
  font-size: 1.2rem;
  font-weight: 700;
}

#best-score {
  color: #5cb85c;
}

footer {
  width: 100%;
  margin-top: 50px;
  padding: 10px;
  text-align: center;
  color: #6c757d;
  font-size: 0.9rem;
}

footer a {
  color: #17a2b8;
  text-decoration: none;
  font-weight: 500;
}

footer a:hover {
  text-decoration: underline;
  color: #138496;
}

@media (max-width: 400px) {
  #button-row {
    flex-direction: column;
    width: 100%;
  }

  #new-game-button,
  #undo-button {
    width: 100%;
  }

  #stats-row {
    flex-direction: column;
    gap: 10px;
  }

  #game-instructions {
    font-size: 0.9rem;
  }
}
