:root {
  --green: #6aaa64;
  --yellow: #c9b458;
  --absent: #787c7e;
  --text: #000;
  --border: #d3d6da;
  --key: #d3d6da;
  --background: #fff;
  font-family: "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--background);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
}

button {
  color: inherit;
  font: inherit;
}

.game {
  display: flex;
  height: 100%;
  flex-direction: column;
  margin: 0 auto;
  max-width: 500px;
}

.header {
  position: relative;
  display: grid;
  flex: 0 0 50px;
  grid-template-columns: 80px 1fr 80px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding: 0 8px;
}

.header h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(23px, 6vw, 30px);
  font-weight: 700;
  letter-spacing: -1px;
  line-height: 1;
  text-align: center;
}

.icon-button {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 2px solid currentColor;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  font-size: 21px;
  font-weight: 700;
}

.header-status {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 5px;
  color: #787c7e;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c9b458;
}

.header-status.ready .status-dot {
  background: var(--green);
}

.header-status.error .status-dot {
  background: #d33;
}

.main {
  position: relative;
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
}

.board-wrap {
  display: flex;
  min-height: 0;
  flex: 1;
  align-items: flex-end;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px 0;
  scrollbar-width: thin;
}

.board {
  display: grid;
  width: min(350px, calc(100vw - 70px));
  margin: auto auto 0;
  gap: 5px;
}

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

.tile {
  display: grid;
  aspect-ratio: 1;
  place-items: center;
  border: 2px solid var(--border);
  background: #fff;
  font-size: clamp(24px, 8vw, 32px);
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
}

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

.tile.reveal {
  animation: flip .5s ease forwards;
}

.tile.reveal:nth-child(2) {
  animation-delay: .18s;
}

.tile.reveal:nth-child(3) {
  animation-delay: .36s;
}

.tile.reveal:nth-child(4) {
  animation-delay: .54s;
}

.tile.reveal:nth-child(5) {
  animation-delay: .72s;
}

.tile.correct,
.mini-tile.correct,
.key.correct {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.tile.present,
.mini-tile.present,
.key.present {
  border-color: var(--yellow);
  background: var(--yellow);
  color: #fff;
}

.tile.absent,
.mini-tile.absent,
.key.absent {
  border-color: var(--absent);
  background: var(--absent);
  color: #fff;
}

.guess-row.shake {
  animation: shake .6s;
}

.toast {
  position: absolute;
  z-index: 3;
  top: 12px;
  left: 50%;
  max-width: calc(100% - 32px);
  padding: 11px 14px;
  transform: translate(-50%, -12px);
  border-radius: 4px;
  background: #000;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transition: opacity .15s, transform .15s;
}

.toast.visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

.keyboard {
  flex: 0 0 auto;
  padding: 0 8px max(8px, env(safe-area-inset-bottom));
  user-select: none;
}

.keyboard-row {
  display: flex;
  height: 58px;
  margin: 0 auto 8px;
  gap: 6px;
}

.keyboard-row--middle {
  padding: 0 5%;
}

.letter-keys {
  display: contents;
}

.key {
  display: flex;
  min-width: 0;
  flex: 1;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 4px;
  background: var(--key);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  -webkit-tap-highlight-color: transparent;
}

.key:active {
  filter: brightness(.88);
}

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

.key--delete svg {
  width: 24px;
  height: 24px;
}

dialog {
  width: min(480px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  border: 0;
  border-radius: 8px;
  box-shadow: 0 4px 24px #0003;
}

dialog::backdrop {
  background: #fff9;
}

dialog h2 {
  margin: 8px 0 24px;
  text-align: center;
  text-transform: uppercase;
}

.dialog-close {
  position: absolute;
  top: 12px;
  right: 12px;
  border: 0;
  font-size: 28px;
  font-weight: 400;
}

.example {
  border-top: 1px solid var(--border);
  margin-top: 24px;
  padding-top: 20px;
}

.example-row {
  display: flex;
  gap: 4px;
}

.mini-tile {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 2px solid var(--border);
  font-weight: 700;
}

@keyframes pop {
  50% { transform: scale(1.1); }
}

@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(90deg); }
  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); }
}

@media (max-height: 600px) {
  .keyboard-row {
    height: 48px;
    margin-bottom: 5px;
  }

  .board {
    width: min(270px, calc(100vw - 90px));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-delay: 0ms !important;
    transition-duration: .01ms !important;
  }
}
