:root {
  --color-correct: #6aaa64;
  --color-present: #c9b458;
  --color-absent: #787c7e;
  --color-surface: #121213;
  --color-surface-light: #272729;
  --color-text: #ffffff;
  --color-border: #3a3a3c;
  --color-key-bg: #818384;
  --font-family: 'Inter', sans-serif;
  --animation-speed: 250ms;
}

body {
  background-color: var(--color-surface);
  color: var(--color-text);
  font-family: var(--font-family);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  height: 100vh;
  margin: 0;
  overflow: hidden;
}

/* Header & Icon Buttons */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  border-bottom: 1px solid var(--color-border);
  height: 50px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text);
  padding: 4px;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.modal.hidden {
  display: none;
  opacity: 0;
  pointer-events: none;
}

.modal-content {
  background-color: var(--color-surface);
  padding: 20px;
  border-radius: 8px;
  width: 90%;
  max-width: 500px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  border: 1px solid var(--color-border);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-header h2 {
  font-size: 1.2rem;
  margin: 0;
}

.modal-body {
  font-size: 0.9rem;
  line-height: 1.5;
}

.modal-body hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 16px 0;
}

.example {
  margin-bottom: 16px;
}

.row.small {
  display: flex;
  gap: 3px;
  margin-bottom: 8px;
}

.row.small .tile {
  width: 40px;
  height: 40px;
  font-size: 1.2rem;
  line-height: 38px;
}

h1 {
  font-weight: 700;
  font-size: 36px;
  letter-spacing: 0.1em;
  margin: 0;
  text-transform: uppercase;
}

#game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-grow: 1;
  width: 100%;
  max-width: 500px;
}

#grid {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  grid-gap: 5px;
  padding: 10px;
  box-sizing: border-box;
  width: 350px;
  height: 420px;
}

.row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-gap: 5px;
}

.tile {
  width: 100%;
  height: 100%;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  font-size: 2rem;
  line-height: 2rem;
  font-weight: bold;
  vertical-align: middle;
  box-sizing: border-box;
  color: var(--color-text);
  text-transform: uppercase;
  user-select: none;
  border: 2px solid var(--color-border);
}

.tile[data-state='active'] {
  border-color: #565758;
  animation: pop 0.1s;
}

.tile[data-state='correct'] {
  background-color: var(--color-correct);
  border-color: var(--color-correct);
}

.tile[data-state='present'] {
  background-color: var(--color-present);
  border-color: var(--color-present);
}

.tile[data-state='absent'] {
  background-color: var(--color-absent);
  border-color: var(--color-absent);
}

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

#keyboard {
  margin: 0 8px;
  user-select: none;
  width: 100%;
  max-width: 500px;
  padding-bottom: 20px;
}

.keyboard-row {
  display: flex;
  width: 100%;
  margin: 0 auto 8px;
  touch-action: manipulation;
}

.key {
  font-family: inherit;
  font-weight: bold;
  border: 0;
  padding: 0;
  margin: 0 6px 0 0;
  height: 58px;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
  background-color: var(--color-key-bg);
  color: var(--color-text);
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  text-transform: uppercase;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.3);
}

.key:last-of-type {
  margin: 0;
}

.key.wide {
  flex: 1.5;
  font-size: 12px;
}

.key[data-state='correct'] {
  background-color: var(--color-correct);
}

.key[data-state='present'] {
  background-color: var(--color-present);
}

.key[data-state='absent'] {
  background-color: var(--color-surface-light);
  /* Darker for absent keys */
}

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

  50% {
    transform: scale(1.1);
  }

  100% {
    transform: scale(1);
  }
}

@keyframes flip {
  0% {
    transform: rotateX(0);
    border-color: var(--color-border);
  }

  45% {
    transform: rotateX(90deg);
    border-color: var(--color-border);
  }

  55% {
    transform: rotateX(90deg);
    /* Color change happens here in JS logic usually, but visual flip is key */
  }

  100% {
    transform: rotateX(0);
  }
}

@keyframes shake {

  10%,
  90% {
    transform: translateX(-1px);
  }

  20%,
  80% {
    transform: translateX(2px);
  }

  30%,
  50%,
  70% {
    transform: translateX(-4px);
  }

  40%,
  60% {
    transform: translateX(4px);
  }
}

.shake {
  animation: shake 0.6s;
}

@keyframes bounce {

  0%,
  20% {
    transform: translateY(0);
  }

  40% {
    transform: translateY(-30px);
  }

  50% {
    transform: translateY(5px);
  }

  60% {
    transform: translateY(-15px);
  }

  80% {
    transform: translateY(2px);
  }

  100% {
    transform: translateY(0);
  }
}

.bounce {
  animation: bounce 1s;
}

#message-container {
  position: absolute;
  top: 10%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}

.message {
  background-color: var(--color-text);
  color: var(--color-surface);
  padding: 10px 20px;
  border-radius: 4px;
  margin-bottom: 10px;
  font-weight: bold;
  opacity: 1;
  transition: opacity 0.5s;
}

.hidden {
  opacity: 0;
}