* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: #121213;
  color: #ffffff;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

header {
  text-align: center;
  padding: 10px 0 6px;
  border-bottom: 1px solid #3a3a3c;
  width: 100%;
  max-width: 500px;
  flex-shrink: 0;
}

header h1 {
  font-size: 2rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

header .subtitle {
  font-size: 0.85rem;
  color: #818384;
  margin-top: 4px;
  font-style: italic;
}

main {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  justify-content: flex-start;
  gap: 24px;
  padding: 20px 0 12px;
  width: 100%;
  max-width: 500px;
  min-height: 0;
}

/* Board */
#board {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.row {
  display: flex;
  gap: 5px;
}

.tile {
  width: 54px;
  height: 54px;
  border: 2px solid #3a3a3c;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: bold;
  color: white;
  text-transform: uppercase;
  user-select: none;
}

.tile.filled {
  border-color: #565758;
  animation: pop 0.1s ease-in-out;
}

.tile.reveal {
  animation: flip 0.5s ease-in-out;
}

.tile.green {
  background: #538d4e;
  border-color: #538d4e;
}

.tile.yellow {
  background: #b59f3b;
  border-color: #b59f3b;
}

.tile.gray {
  background: #3a3a3c;
  border-color: #3a3a3c;
}

/* Keyboard */
#keyboard {
  width: 100%;
  max-width: 500px;
  padding: 0 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

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

.spacer-half {
  flex: 0.5;
}

.keyboard-row button {
  flex: 1;
  max-width: 43px;
  height: 50px;
  border-radius: 4px;
  border: none;
  background: #818384;
  color: white;
  font-size: 0.85rem;
  font-weight: bold;
  cursor: pointer;
  text-transform: uppercase;
  touch-action: manipulation;
  user-select: none;
  transition: background-color 0.2s;
}

.keyboard-row button.wide {
  max-width: 65px;
  flex: 1.5;
  font-size: 0.75rem;
}

.keyboard-row button.green {
  background: #538d4e;
}

.keyboard-row button.yellow {
  background: #b59f3b;
}

.keyboard-row button.gray {
  background: #3a3a3c;
}

/* Animations */
@keyframes pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.1); }
  100% { transform: scale(1); }
}

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

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

/* Toast */
#toast-container {
  position: fixed;
  top: 10%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: #ffffff;
  color: #121213;
  padding: 14px 24px;
  border-radius: 4px;
  font-weight: bold;
  font-size: 0.9rem;
  animation: fadeInOut 1.5s ease-in-out forwards;
}

@keyframes fadeInOut {
  0%   { opacity: 0; transform: translateY(-10px); }
  15%  { opacity: 1; transform: translateY(0); }
  80%  { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-10px); }
}

/* Modal */
#modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

#modal.hidden {
  display: none;
}

.modal-content {
  background: #1a1a1b;
  border: 1px solid #3a3a3c;
  border-radius: 8px;
  padding: 32px 40px;
  text-align: center;
  max-width: 400px;
  width: 90%;
}

.modal-content h2 {
  font-size: 1.4rem;
  margin-bottom: 12px;
  letter-spacing: 0.05em;
}

.modal-content p {
  color: #818384;
  margin-bottom: 24px;
  font-size: 1rem;
  line-height: 1.5;
}

#modal-play-again {
  background: #538d4e;
  color: white;
  border: none;
  border-radius: 4px;
  padding: 14px 32px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#modal-play-again:hover {
  background: #6aaf5e;
}

/* Responsive */
@media (max-width: 400px) {
  .tile {
    width: 52px;
    height: 52px;
    font-size: 1.6rem;
  }

  .keyboard-row button {
    height: 50px;
    font-size: 0.75rem;
  }

  header h1 {
    font-size: 1.5rem;
  }
}

@media (max-width: 340px) {
  .tile {
    width: 46px;
    height: 46px;
    font-size: 1.4rem;
  }

  .keyboard-row {
    gap: 4px;
  }

  .keyboard-row button {
    height: 45px;
  }
}
