:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1e2430;
  --muted: #667085;
  --line: #d9dfeb;

  --correct: #22a06b;
  --present: #d4a72c;
  --absent: #98a2b3;

  --radius: 16px;
  --shadow: 0 10px 30px rgba(16, 24, 40, 0.08);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

.wrap {
  width: min(100%, 680px);
  margin: 0 auto;
  padding: 32px 16px 48px;
}

.header {
  text-align: center;
  margin-bottom: 20px;
}

.header h1 {
  margin: 0 0 8px;
  font-size: clamp(28px, 4vw, 42px);
}

.meta {
  margin: 0;
  color: var(--muted);
}

.header-actions {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.text-btn {
  border: 0;
  background: transparent;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  padding: 0;
}

.countdown {
  margin: 12px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  overflow-x: hidden;
}

.message {
  min-height: 24px;
  margin-bottom: 18px;
  font-weight: 700;
  text-align: center;
}

.message.error {
  color: #b42318;
}

.message.success {
  color: #067647;
}

.board {
  --tile-gap: 6px;
  --tile-size: 56px;

  display: grid;
  gap: var(--tile-gap);
  margin-bottom: 20px;
  width: 100%;
}

.row {
  display: grid;
  gap: var(--tile-gap);
  width: max-content;
  max-width: 100%;
  margin-inline: auto;
}

.tile {
  width: var(--tile-size);
  aspect-ratio: 1 / 1;
  min-width: 0;
  border: 2px solid var(--line);
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: clamp(18px, 3vw, 28px);
  font-weight: 700;
  text-transform: uppercase;
  background: #fff;
  transform-style: preserve-3d;
}

.tile.filled {
  border-color: #b8c1d4;
}

.tile.correct {
  background: var(--correct);
  border-color: var(--correct);
  color: #fff;
}

.tile.present {
  background: var(--present);
  border-color: var(--present);
  color: #fff;
}

.tile.absent {
  background: var(--absent);
  border-color: var(--absent);
  color: #fff;
}

.tile.reveal {
  animation: tile-flip 0.6s ease;
}

@keyframes tile-flip {
  0% {
    transform: rotateX(0deg);
  }
  45% {
    transform: rotateX(90deg);
  }
  55% {
    transform: rotateX(90deg);
  }
  100% {
    transform: rotateX(0deg);
  }
}

.keyboard {
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
  width: 100%;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  align-items: stretch;
  gap: 6px;
  width: 100%;
}

.key {
  flex: 1 1 0;
  min-width: 0;
  height: 54px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #eef2f7;
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  text-transform: uppercase;
  touch-action: manipulation;
}

.key:hover {
  border-color: #b8c1d4;
}

.key.wide {
  flex: 1.45 1 0;
}

.key.correct {
  background: var(--correct);
  border-color: var(--correct);
  color: #fff;
}

.key.present {
  background: var(--present);
  border-color: var(--present);
  color: #fff;
}

.key.absent {
  background: var(--absent);
  border-color: var(--absent);
  color: #fff;
}

.actions {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.action-btn {
  height: 46px;
  border: 0;
  border-radius: 12px;
  padding: 0 18px;
  font-weight: 700;
  cursor: pointer;
  background: #111827;
  color: #fff;
}

.stats {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

.stats strong {
  color: var(--text);
}

.stats-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 12px;
  text-align: center;
  background: #f8fafc;
}

.stat-card strong {
  display: block;
  font-size: 24px;
  line-height: 1.1;
  margin-bottom: 6px;
}

.stats-section-title {
  margin: 20px 0 10px;
  font-size: 16px;
  font-weight: 700;
}

.dist-list {
  display: grid;
  gap: 8px;
}

.dist-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) 44px;
  gap: 10px;
  align-items: center;
}

.dist-bar-wrap {
  height: 28px;
  border-radius: 999px;
  background: #eef2f7;
  overflow: hidden;
}

.dist-bar {
  height: 100%;
  min-width: 28px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 10px;
  color: #fff;
  font-weight: 700;
  background: var(--correct);
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.history-item strong {
  font-size: 14px;
}

.history-item span {
  color: var(--muted);
  font-size: 14px;
}

.modal {
  border: 0;
  padding: 0;
  border-radius: 20px;
  width: min(92vw, 560px);
}

.modal::backdrop {
  background: rgba(15, 23, 42, 0.55);
}

.modal-card {
  padding: 24px;
  background: #fff;
}

.modal-card h2 {
  margin: 0 0 14px;
}

.modal-card p {
  margin: 0 0 12px;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  justify-content: center;
  margin-top: 18px;
}

.example-grid {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.example-row {
  display: grid;
  grid-template-columns: repeat(6, 44px);
  gap: 8px;
}

#stats-modal-content {
  color: var(--text);
  line-height: 1.8;
}

.guess-form {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.guess-form input {
  flex: 1;
  min-width: 0;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 14px;
  font-size: 18px;
  text-transform: lowercase;
}

.guess-form button {
  height: 48px;
  border: 0;
  border-radius: 12px;
  padding: 0 18px;
  font-weight: 700;
  cursor: pointer;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  border: 0;
  clip: rect(0, 0, 0, 0);
}

@media (max-width: 640px) {
  .wrap {
    padding: 24px 12px 36px;
  }

  .panel {
    padding: 14px;
  }

  .board {
    --tile-gap: 4px;
  }

  .tile {
    border-radius: 10px;
    font-size: clamp(16px, 5vw, 22px);
  }

  .keyboard {
    gap: 6px;
  }

  .keyboard-row {
    gap: 4px;
  }

  .key {
    height: 46px;
    padding: 0 4px;
    font-size: 12px;
    border-radius: 8px;
  }

  .key.wide {
    flex: 1.7 1 0;
  }

  .stats-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dist-row {
    grid-template-columns: 20px minmax(0, 1fr) 36px;
    gap: 8px;
  }

  .history-item {
    flex-direction: column;
    align-items: flex-start;
  }

  .example-row {
    grid-template-columns: repeat(6, 38px);
  }

  .modal-card {
    padding: 18px;
  }

  .guess-form {
    flex-direction: column;
  }

  .guess-form button {
    width: 100%;
  }
}