body {
  display: flex;
  justify-content: center;
  background: #f0f4f8;
  font-family: "Courier New", Courier, monospace;
  margin: 20px;
}

.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
}

.result-container {
  max-height: 100px;
  text-align: center;
  /* background-color: #f44336; */
}

.result {
  font-size: 1.5rem;
  font-weight: bold;
}

.result.win {
  color: green;
}

.result.lose {
  color: red;
}

.board {
  display: flex;
  flex-direction: column;
  /* gap: 16px; */
  gap: 4px;
  outline: none;
}

.row {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding-left: 16px;
  padding-right: 16px;
  padding-top: 6px;
  padding-bottom: 6px;
}

.row.current {
  /* background-color: grey; */
}

@keyframes shake {
  0% {
    transform: translateX(0);
  }
  10% {
    transform: translateX(-5px);
  }
  20% {
    transform: translateX(5px);
  }
  30% {
    transform: translateX(-5px);
  }
  40% {
    transform: translateX(5px);
  }
  50% {
    transform: translateX(-5px);
  }
  60% {
    transform: translateX(5px);
  }
  70% {
    transform: translateX(-5px);
  }
  80% {
    transform: translateX(5px);
  }
  90% {
    transform: translateX(-5px);
  }
  100% {
    transform: translateX(0);
  }
}

.row.invalid {
  animation: shake 0.5s ease-in-out;
}

.tile {
  width: 60px;
  height: 60px;
  position: relative;
  transform-style: preserve-3d;
}

.front,
.back {
  position: absolute;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2em;
  font-weight: bold;
  border: 2px solid #ccc;
  border-radius: 8px;
  backface-visibility: hidden;
}

.front {
  background: white;
  color: black;
  transform: rotateX(0deg);
}

.back {
  color: white;
  transform: rotateX(180deg);
}

.back.G {
  background: #4caf50;
}

.back.Y {
  background: #ffc107;
}

.back.R {
  background: #f44336;
}

.flip .front {
  transform: rotateX(-180deg);
  transition: transform 0.8s;
}

.flip .back {
  transform: rotateX(0deg);
  transition: transform 0.8s;
}

.restart-btn {
  background-color: #4caf50;
  color: white;
  border: none;
  padding: 12px 24px;
  margin-top: 16px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.1s ease;
}

.restart-btn:hover {
  background-color: #45a049;
}

.restart-btn:active {
  transform: scale(0.97);
}

.keyboard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 90vw; /* scales with viewport */
  max-width: 480px; /* optional max */
}

.keyboard-row {
  display: flex;
  flex-direction: row;
  justify-content: center;
  width: 100%;
}

.keyboard-btn {
  flex: 1;
  height: 58px;

  font-size: 1.25em;
  font-weight: bold;
  text-transform: uppercase;

  border: 0;
  border-radius: 6px;
  padding: 0;

  cursor: pointer;

  display: flex;
  justify-content: center;
  align-items: center;

  background-color: #818384;
  color: white;

  transition: background-color 0.2s ease, transform 0.1s ease;

  margin: 0 2px;

  overflow: hidden;
}

.keyboard-btn.G {
  background: #4caf50;
}

.keyboard-btn.Y {
  background: #ffc107;
}

.keyboard-btn.R {
  background: #f44336;
}

.keyboard-btn.first {
  margin-left: 0;
}
.keyboard-btn.last {
  margin-right: 0;
}

.keyboard-btn:hover {
  background-color: #a4a6a9;
}

.keyboard-btn:active {
  transform: scale(0.95);
  background-color: #666769;
}

.keyboard-btn.wide {
  flex: 1.5;
  font-size: 0.75em;
}

.keyboard-spacer-half {
  flex: 0.5;
  margin: 0;
}

/* Popup overlay */
.popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.6); /* slightly darker */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.3s ease-out;
}

/* Popup content box */
.popup-content {
    background: #f0f4f8; /* match body bg */
    padding: 2rem 3rem;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    white-space: pre-line;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    font-family: "Courier New", monospace;
}

/* Result text inside popup */
.popup-content p {
    font-size: 2rem;
    font-weight: bold;
    margin: 0;
    color: #333;
}

.popup-content p.win {
    color: #4caf50; /* green */
}

.popup-content p.lose {
    color: #f44336; /* red */
}

/* Replay button */
.replay-btn {
    background-color: #4caf50;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 1.25rem;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.replay-btn:hover {
    background-color: #45a049;
    box-shadow: 0 6px 12px rgba(0,0,0,0.25);
}

.replay-btn:active {
    transform: scale(0.97);
    box-shadow: 0 3px 6px rgba(0,0,0,0.2);
}

/* Fade-in animation for popup */
@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}