:root {
  --key-bg: #ddd;
  --key-text: #000;
  --special-key-bg: #aaa;
  --hover-bg: #ccc;
  --container-bg: #f9f9f9;
}

.game-container {
  margin: 0;
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: Arial, sans-serif;
}

#game-board {
  display: flex;
  align-items: center;
  flex-direction: column;
}

.letter-box {
  border: 2px solid gray;
  border-radius: 3px;
  margin: 2px;
  font-size: 2.5rem;
  font-weight: 700;
  height: 3rem;
  width: 3rem;
  display: flex;
  justify-content: center;
  align-items: center;
  text-transform: uppercase;
}

.filled-box {
  border: 2px solid rgb(128, 128, 128);
}

.letter-row {
  display: flex;
}

#keyboard-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px;
  background-color: var(--container-bg);
  border-radius: 15px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  margin-top: 30px;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.key {
  background-color: var(--key-bg);
  color: var(--key-text);
  font-size: 1.1rem;
  font-weight: 600;
  border-radius: 6px;
  padding: 18px;
  min-width: 45px;
  text-align: center;
  cursor: pointer;
  user-select: none;
  text-transform: uppercase;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

.key.wide-key {
  min-width: 75px;
  font-size: 0.9rem;
  background-color: var(--special-key-bg);
}

.key:hover {
  background-color: var(--hover-bg);
  transform: translateY(-2px);
}

.key:active {
  transform: translateY(1px);
}

.key svg {
  vertical-align: middle;
  pointer-events: none;
}

#toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 9999;
}
#toast.show {
  opacity: 1;
}

/* Shake animation for invalid guesses */
@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-6px);
  }
  40% {
    transform: translateX(6px);
  }
  60% {
    transform: translateX(-4px);
  }
  80% {
    transform: translateX(4px);
  }
}
.letter-row.shake {
  animation: shake 300ms ease;
}

/* Visually dim keyboard when disabled */
#keyboard-container.disabled {
  opacity: 0.6;
}

/* Popup Overlay */
#popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 10000;
}

/* Visible state */
#popup-overlay.show {
  opacity: 1;
  pointer-events: all;
}

/* Popup Box */
#popup-box {
  background: #fff;
  padding: 25px 35px;
  border-radius: 12px;
  text-align: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
  animation: popIn 0.25s ease;
  max-width: 300px;
}

#popup-word {
  color: #444;
  font-weight: bold;
  font-size: 1.2rem;
  letter-spacing: 1px;
}

#popup-box h2 {
  margin-top: 0;
  color: #333;
}

#popup-box p {
  margin: 8px 0;
  font-weight: 600;
}

#popup-btn {
  background-color: #6aaa64;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-weight: bold;
  cursor: pointer;
  margin-top: 10px;
  transition: background-color 0.2s ease;
}

#popup-btn:hover {
  background-color: #589653;
}

@keyframes popIn {
  0% {
    transform: scale(0.9);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Flip Animation for Tile Reveal */
.letter-box.flip {
  animation: flip 0.5s ease forwards;
  transform-origin: center bottom;
}

@keyframes flip {
  0% {
    transform: rotateX(0);
  }
  50% {
    transform: rotateX(90deg);
  }
  100% {
    transform: rotateX(0);
  }
}

.flip {
  animation: flip 0.5s ease;
  transform-origin: center;
}

/* Adjust only the Play Now version of back-button */
.play-button {
  padding: 0.45rem 1rem; /* smaller padding for tighter fit */
}

.back-button .arrow {
  font-size: 1.6rem; /* bigger arrow */
  margin-left: 1px;
  position: relative;
  top: 3px; /* moves arrow slightly lower */
  transition: transform 0.3s ease;
}

.back-button:hover .arrow {
  transform: translateY(4px);
}

#game-container {
  scroll-margin-top: 75px;
}

/* Reset global padding and alignment only for this page */
main#game-page > section#game-container {
  padding-left: 0 !important;
  padding-right: 0 !important;
  margin: 0 auto !important;
  display: flex !important;
  flex-direction: column;
  align-items: center;
}

/* Ensure the keyboard box doesn't stretch full width */
#keyboard-container {
  width: fit-content !important; /* box only as wide as needed */
  margin: 30px auto 0 !important; /* center horizontally */
  box-sizing: border-box;
}

/* Mobile responsive for keyboard */
@media (max-width: 768px) {
  #keyboard-container {
    width: 100% !important;
    max-width: 500px;
    padding: 15px 10px;
    margin: 20px auto 0 !important;
  }

  .keyboard-row {
    gap: 4px; /* Reduce gap between keys */
  }

  .key {
    font-size: 0.85rem;
    padding: 14px 8px;
    min-width: 28px; /* Smaller keys */
    flex: 1; /* Allow keys to shrink/grow */
  }

  .key.wide-key {
    min-width: 55px; /* Smaller wide keys */
    font-size: 0.75rem;
  }

  /* Make letter boxes smaller on mobile */
  .letter-box {
    font-size: 1.8rem;
    height: 2.5rem;
    width: 2.5rem;
    margin: 1px;
  }

  /* Fix footer spacing */
  footer {
    margin-top: 2rem;
  }

  /* Hide back button on mobile */
  .back-button.play-button {
    display: none;
  }

  /* Reduce header padding on mobile */
  #game-page .main-header {
    padding: 2rem 1rem 1.5rem;
    margin-bottom: 1.5rem;
  }
}

@media (max-width: 480px) {
  .key {
    font-size: 0.75rem;
    padding: 12px 4px;
    min-width: 24px;
  }

  .key.wide-key {
    min-width: 50px;
    font-size: 0.7rem;
  }

  .keyboard-row {
    gap: 3px;
  }

  .letter-box {
    font-size: 1.5rem;
    height: 2.2rem;
    width: 2.2rem;
  }
}
