:root {
  color-scheme: light;
  --background: #f8f8f8;
  --surface: #ffffff;
  --text: #202124;
  --muted: #5f6368;
  --border: #d3d6da;
  --filled-border: #878a8c;
  --primary: #315c8c;
  --correct: #538d4e;
  --present: #b59f3b;
  --absent: #787c7e;
  --key: #d9dde3;
  --danger: #a63737;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--background);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: default;
}

.app {
  width: min(100%, 560px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 12px 16px 18px;
}

.screen {
  min-height: calc(100vh - 30px);
}

.name-screen {
  display: grid;
  place-content: center;
  gap: 18px;
  text-align: center;
}

.title {
  margin: 0;
  font-size: clamp(32px, 8vw, 44px);
  line-height: 1;
  font-weight: 900;
}

.subtitle {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
}

.name-form {
  display: grid;
  gap: 14px;
  width: min(360px, calc(100vw - 48px));
}

.name-input {
  width: 100%;
  height: 54px;
  padding: 0 14px;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  outline: none;
}

.name-input:focus {
  border-color: var(--primary);
}

.auth-message {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.primary-button,
.secondary-button {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 6px;
  font-weight: 800;
}

.primary-button {
  background: var(--primary);
  color: white;
}

.primary-button:disabled {
  opacity: 0.45;
}

.secondary-button {
  background: var(--key);
  color: var(--text);
}

.game-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.topbar {
  width: 100%;
}

.title-row {
  display: grid;
  grid-template-columns: 112px 1fr 112px;
  align-items: center;
  min-height: 48px;
}

.actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.actions.right {
  justify-content: flex-end;
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  display: grid;
  place-items: center;
}

.icon-button:hover,
.icon-button:focus-visible {
  background: #ebedf0;
}

.wordmark {
  margin: 0;
  text-align: center;
  font-size: 28px;
  line-height: 1;
  font-weight: 900;
}

.reset-button {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  background: var(--primary);
  color: white;
  font-weight: 800;
}

.puzzle-label,
.message {
  width: 100%;
  margin: 0;
  text-align: center;
  font-weight: 800;
}

.puzzle-label {
  height: 24px;
  color: var(--primary);
  font-size: 17px;
}

.message {
  height: 32px;
  color: var(--muted);
  font-size: 15px;
}

.message.error {
  color: var(--danger);
}

.board {
  width: min(100%, 360px);
  margin: 18px 0;
  display: grid;
  gap: 6px;
}

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

.tile {
  aspect-ratio: 1;
  border: 2px solid var(--border);
  background: transparent;
  display: grid;
  place-items: center;
  color: var(--text);
  font-size: clamp(26px, 8vw, 34px);
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
}

.tile.selected {
  border-width: 3px;
  border-color: var(--primary);
}

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

.tile.correct,
.tile.present,
.tile.absent {
  color: white;
  border-color: transparent;
}

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

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

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

.keyboard {
  width: 100%;
  display: grid;
  gap: 8px;
  margin-top: auto;
}

.keyboard-row {
  display: grid;
  gap: 4px;
}

.keyboard-row.row-1 {
  grid-template-columns: repeat(10, 1fr);
}

.keyboard-row.row-2 {
  grid-template-columns: repeat(11, 1fr);
}

.keyboard-row.row-3 {
  grid-template-columns: 1.55fr repeat(8, 1fr) 1.55fr;
}

.key {
  min-width: 0;
  height: 52px;
  padding: 0 2px;
  border-radius: 6px;
  background: var(--key);
  color: var(--text);
  font-size: 13px;
  font-weight: 900;
}

.key.correct,
.key.present,
.key.absent {
  color: white;
}

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

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

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

.key:disabled {
  opacity: 0.58;
}

.leaderboard-screen {
  display: flex;
  flex-direction: column;
}

.leaderboard-top {
  display: grid;
  grid-template-columns: 64px 1fr 92px;
  align-items: center;
  gap: 8px;
}

.leaderboard-title {
  margin: 0;
  text-align: center;
  font-size: 24px;
  line-height: 1.1;
  font-weight: 900;
}

.leaderboard-message {
  margin: 14px 0;
  min-height: 22px;
  color: var(--muted);
  text-align: center;
  font-weight: 800;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  background: var(--surface);
}

.leaderboard-table th,
.leaderboard-table td {
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.leaderboard-table th {
  font-size: 13px;
  font-weight: 900;
}

.leaderboard-table td {
  font-size: 15px;
  font-weight: 700;
}

.leaderboard-table .rank {
  width: 34px;
}

.leaderboard-table .user {
  width: auto;
  text-align: left;
  overflow-wrap: anywhere;
}

.leaderboard-table .level {
  width: 34px;
}

.leaderboard-table .score {
  width: 56px;
  text-align: right;
}

.empty-state {
  margin: 30px 0 0;
  text-align: center;
  font-size: 18px;
  font-weight: 800;
}

@media (max-width: 420px) {
  .app {
    padding-inline: 10px;
  }

  .title-row {
    grid-template-columns: 96px 1fr 96px;
  }

  .leaderboard-table th,
  .leaderboard-table td {
    padding-inline: 2px;
  }
}
