:root {
  --bg: #ffffff;
  --text: #1a1a1b;
  --border: #d3d6da;
  --empty-border: #878a8c;
  --key: #d3d6da;
  --key-text: #1a1a1b;
  --correct: #6aaa64;
  --present: #c9b458;
  --absent: #787c7e;
  --muted: #565758;
  --message-bg: #1a1a1b;
  --message-text: #ffffff;
  --previous-link: #1a1a1b;
  --select-bg: #ffffff;
  --select-border: #d3d6da;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
}

header {
  width: 100%;
  min-height: 62px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.title-wrap {
  display: grid;
  justify-items: center;
  gap: 2px;
}

h1 {
  margin: 0;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 34px;
  line-height: 1;
  letter-spacing: 0;
  font-weight: 700;
}

#word-date {
  min-height: 14px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

#theme-select {
  position: absolute;
  right: 14px;
  min-width: 92px;
  height: 34px;
  border: 1px solid var(--select-border);
  border-radius: 4px;
  background: var(--select-bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
}

main {
  width: 100%;
  max-width: 520px;
  min-height: calc(100vh - 62px);
  padding: 18px 12px 12px;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 22px;
}

#message {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
}

#message span {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 8px 12px;
  color: var(--message-text);
  background: var(--message-bg);
  border-radius: 4px;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 120ms ease, transform 120ms ease;
}

#message span.show {
  opacity: 1;
  transform: translateY(0);
}

.board-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

#board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 5px;
  width: min(350px, calc(100vw - 36px));
  aspect-ratio: 5 / 6;
}

.previous-link {
  color: var(--previous-link);
  font-size: 13px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

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

.tile {
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.7rem, 8vw, 2rem);
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
  user-select: none;
}

.tile.filled {
  border-color: var(--empty-border);
  transform: scale(1.04);
}

.tile.correct,
.tile.present,
.tile.absent {
  color: #fff;
  border-color: transparent;
  transform: scale(1);
}

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

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

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

#keyboard {
  display: grid;
  gap: 8px;
  width: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

.key-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}

button.key {
  min-width: 0;
  height: 58px;
  flex: 1;
  border: 0;
  border-radius: 4px;
  background: var(--key);
  color: var(--key-text);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;
}

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

button.key.correct,
button.key.present,
button.key.absent {
  color: #fff;
}

button.key.correct {
  background: var(--correct);
}

button.key.present {
  background: var(--present);
}

button.key.absent {
  background: var(--absent);
}

button.key:active {
  filter: brightness(0.94);
}

@media (max-width: 380px) {
  main {
    padding-inline: 6px;
  }

  .key-row {
    gap: 4px;
  }

  button.key {
    height: 54px;
    font-size: 12px;
  }

  #theme-select {
    right: 6px;
    min-width: 78px;
    font-size: 12px;
  }
}
