:root {
  --color-correct: #6aaa64;
  --color-present: #f59e0b;
  --color-absent: #787c7e;
  --color-tile-border: #d3d6da;
  --color-text: #1a1a1b;
  --color-bg: #ffffff;
  --tile-size: clamp(3.5rem, 14vw, 4.25rem);
  --tile-gap: 0.35rem;
  --font-tile: 1.75rem;
  --key-height: 3rem;
  --max-board-width: 32rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Clear Sans", "Helvetica Neue", Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body {
  overflow-x: hidden;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 100vw;
}

.header {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-tile-border);
}

.title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.trial-badge {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  color: #5a5a5a;
}

.app.locked .board-wrap,
.app.locked .keyboard {
  pointer-events: none;
  opacity: 0.45;
}

.paywall-price {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 1rem;
}

.btn-pay {
  display: block;
  width: 100%;
  padding: 0.875rem 1.25rem;
  font-size: 1rem;
  font-weight: 700;
  border: 2px solid var(--color-text);
  border-radius: 2rem;
  background: var(--color-present);
  color: #fff;
  text-align: center;
  text-decoration: none;
  font-family: inherit;
  touch-action: manipulation;
  box-sizing: border-box;
}

.btn-pay:active {
  opacity: 0.9;
}

.message {
  min-height: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.25rem 0.5rem;
  color: var(--color-text);
}

.message.error {
  animation: shake 0.4s ease;
}

.board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
}

.board {
  display: grid;
  grid-template-rows: repeat(6, var(--tile-size));
  gap: var(--tile-gap);
  width: min(100%, calc(5 * var(--tile-size) + 4 * var(--tile-gap)));
  max-width: var(--max-board-width);
}

.row {
  display: grid;
  grid-template-columns: repeat(5, var(--tile-size));
  gap: var(--tile-gap);
  perspective: 1000px;
}

.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--color-tile-border);
  font-size: var(--font-tile);
  font-weight: 700;
  text-transform: uppercase;
  user-select: none;
  background: #fff;
  color: var(--color-text);
  transition: transform 0.1s ease;
}

.tile.filled {
  border-color: #878a8c;
  animation: pop 0.08s ease;
}

.tile.reveal {
  color: #fff;
  border-color: transparent;
  animation: flip 0.5s ease forwards;
}

.tile.correct {
  background: var(--color-correct);
  border-color: var(--color-correct);
}

.tile.present {
  background: var(--color-present);
  border-color: var(--color-present);
}

.tile.absent {
  background: var(--color-absent);
  border-color: var(--color-absent);
}

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.5rem 0.35rem calc(0.75rem + env(safe-area-inset-bottom));
  max-width: 32rem;
  margin: 0 auto;
  width: 100%;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 0.3rem;
}

.key {
  min-height: var(--key-height);
  min-width: 1.75rem;
  flex: 1;
  max-width: 2.5rem;
  border: none;
  border-radius: 0.25rem;
  background: #d3d6da;
  color: var(--color-text);
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;
  padding: 0 0.15rem;
  font-family: inherit;
}

.key.wide {
  flex: 1.5;
  max-width: 4.25rem;
  font-size: 0.7rem;
}

.key:active {
  opacity: 0.85;
}

.key.correct {
  background: var(--color-correct);
  color: #fff;
}

.key.present {
  background: var(--color-present);
  color: #fff;
}

.key.absent {
  background: var(--color-absent);
  color: #fff;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

.modal-content {
  position: relative;
  background: #fff;
  border-radius: 0.75rem;
  padding: 1.5rem;
  max-width: 20rem;
  width: 100%;
  text-align: center;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
}

.modal-title {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
}

.modal-body {
  margin: 0 0 1.25rem;
  color: #4a4a4a;
}

.btn-play-again {
  width: 100%;
  padding: 0.875rem 1.25rem;
  font-size: 1rem;
  font-weight: 700;
  border: 2px solid var(--color-text);
  border-radius: 2rem;
  background: #fff;
  color: var(--color-text);
  cursor: pointer;
  font-family: inherit;
  touch-action: manipulation;
}

.btn-play-again:active {
  background: #f4f4f4;
}

@keyframes pop {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

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

@keyframes shake {
  10%,
  90% {
    transform: translateX(-2px);
  }
  20%,
  80% {
    transform: translateX(4px);
  }
  30%,
  50%,
  70% {
    transform: translateX(-6px);
  }
  40%,
  60% {
    transform: translateX(6px);
  }
}

@media (max-width: 360px) {
  :root {
    --tile-size: clamp(3rem, 13vw, 3.5rem);
    --font-tile: 1.5rem;
    --key-height: 2.75rem;
  }
}
