/* Guess Five demo. Tiles, marks and keys follow src/games/guessFive and src/theme/marks.ts. */
.play {
  --stagger: 120ms;
  --stamp: 300ms;
  /* The ink lands just over half way through the stamp. */
  --impact: 135ms;

  display: flex;
  flex-direction: column;
  gap: var(--md);
  padding: var(--md);
  border: 1px solid var(--separator);
  border-radius: var(--radius-lg);
}

.play-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sm);
}

.board {
  display: grid;
  gap: var(--sm);
  width: 100%;
  max-width: 330px;
  margin: 0 auto;
}

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

.tile {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 1.5px solid var(--tile-border);
  border-radius: var(--radius-sm);
  background: var(--background-secondary);
  box-shadow: var(--tile-shadow);
  color: var(--label);
  font: 600 1.75rem/1 var(--serif);
  transition-property: background-color, border-color, border-width, color, box-shadow;
  transition-duration: 20ms;
}

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

.tile.active {
  border: 2.5px solid var(--label);
}

.tile.filled .letter {
  animation: drop 180ms cubic-bezier(0.2, 0.8, 0.3, 1);
}

.tile .glyph {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 8px;
  height: 8px;
  opacity: 0;
  transition: opacity 20ms;
}

.tile.correct,
.tile.present,
.tile.absent {
  box-shadow: none;
  transition-delay: calc(var(--i) * var(--stagger) + var(--impact));
}

.tile.correct .glyph,
.tile.present .glyph,
.tile.absent .glyph {
  opacity: 1;
  transition-delay: calc(var(--i) * var(--stagger) + var(--impact));
}

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

.tile.present {
  border: 3px solid var(--mark-present);
  color: var(--on-mark-present);
}

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

/* Filled dot for right place, ring for wrong place, dash for not in the word. */
.correct .glyph,
.mark-correct .glyph {
  border-radius: 50%;
  background: currentColor;
}

.present .glyph,
.mark-present .glyph {
  border-radius: 50%;
  border: 1.6px solid currentColor;
}

.absent .glyph,
.mark-absent .glyph {
  height: 2px;
  margin-top: 3px;
  border-radius: 2px;
  background: currentColor;
}

.tile.stamp {
  animation: stamp var(--stamp) cubic-bezier(0.3, 0.6, 0.3, 1) both;
  animation-delay: calc(var(--i) * var(--stagger));
}

.row.shake {
  animation: shake 360ms ease-in-out;
}

.row.warn .tile {
  border-color: var(--error);
}

@keyframes stamp {
  0% {
    transform: none;
  }
  38% {
    transform: translateY(-7px) scale(1.07);
  }
  52% {
    transform: translateY(1px) scale(0.96);
  }
  100% {
    transform: none;
  }
}

@keyframes drop {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
}

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

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--sm) var(--md);
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--label-secondary);
}

.legend li {
  display: flex;
  align-items: center;
  gap: var(--sm);
}

.swatch {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-sm);
}

.swatch .glyph {
  width: 8px;
  height: 8px;
}

.swatch.mark-correct {
  background: var(--mark-correct);
  color: var(--on-mark-correct);
}

.swatch.mark-present {
  border: 2px solid var(--mark-present);
  background: var(--background-secondary);
  color: var(--on-mark-present);
}

.swatch.mark-absent {
  background: var(--mark-absent);
  color: var(--on-mark-absent);
}

.notice {
  min-height: 1.25rem;
  font-size: 0.9375rem;
  line-height: 1.25rem;
  text-align: center;
  color: var(--label-secondary);
}

.notice.error {
  color: var(--error);
}

/* Keyboard: the top row fills the width, the rows below are centred, as on iOS. */
.keys {
  --gap: var(--xs);

  display: grid;
  gap: var(--sm);
  user-select: none;
  -webkit-user-select: none;
}

.keys .key-row {
  display: flex;
  justify-content: center;
  gap: var(--gap);
}

.key {
  flex: 0 0 calc((100% - (var(--n) - 1) * var(--gap)) / var(--n));
  display: grid;
  place-items: center;
  min-height: 52px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--key);
  box-shadow: var(--key-shadow);
  color: var(--on-key);
  font: 600 1.125rem/1 var(--serif);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.key:active {
  opacity: 0.7;
}

.key.wide {
  flex: 1 1 0;
  font: 400 0.8125rem/1 var(--sans);
}

.key.wide svg {
  width: 22px;
  height: 22px;
}

.key.correct {
  background: var(--mark-correct);
  color: var(--on-mark-correct);
  box-shadow: none;
}

.key.present {
  background: var(--background-secondary);
  color: var(--on-mark-present);
  box-shadow: inset 0 0 0 2px var(--mark-present);
}

.key.absent,
.key:disabled {
  background: transparent;
  color: var(--on-key-used);
  box-shadow: none;
}

.key:disabled {
  cursor: default;
}

.result {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sm);
  padding: var(--lg) 0;
  text-align: center;
}

.result h3 {
  font-size: 1.75rem;
  line-height: 2.125rem;
}

.result .button {
  margin-top: var(--sm);
}

[hidden] {
  display: none !important;
}

@media (max-width: 400px) {
  .key {
    min-height: 46px;
    font-size: 1rem;
  }
}

/* Reduce Motion: tiles only fade to their mark, and a rejected row flashes instead of shaking. */
@media (prefers-reduced-motion: reduce) {
  .play {
    --stagger: 40ms;
    --impact: 0ms;
  }

  .tile.correct,
  .tile.present,
  .tile.absent,
  .tile.correct .glyph,
  .tile.present .glyph,
  .tile.absent .glyph {
    transition-duration: 160ms;
  }

  .tile.stamp,
  .tile.filled .letter,
  .row.shake {
    animation: none;
  }
}
