:root {
  --bg: #ffffff;
  --fg: #1a1a1b;
  --border: #d3d6da;
  --border-strong: #878a8c;
  --correct: #6aaa64;
  --present: #c9b458;
  --absent: #787c7e;
  --key-bg: #d3d6da;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121213;
    --fg: #ffffff;
    --border: #3a3a3c;
    --border-strong: #565758;
    --correct: #538d4e;
    --present: #b59f3b;
    --absent: #3a3a3c;
    --key-bg: #818384;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: 40px;
  touch-action: manipulation;
}

header {
  width: 100%;
  max-width: 500px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: clamp(1.2rem, 5vw, 1.8rem);
  letter-spacing: 0.05em;
  margin: 0;
  flex: 1;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

@media (max-width: 400px) {
  .header-btn {
    padding: 0 8px;
    font-size: 0.7rem;
  }
  .icon-btn {
    width: 32px;
    height: 32px;
  }
}

.icon-btn,
.header-btn {
  background: none;
  border: 1px solid var(--border-strong);
  color: var(--fg);
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover,
.header-btn:hover {
  background: var(--key-bg);
}

.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  line-height: 1;
}

.header-btn {
  height: 36px;
  padding: 0 14px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 16px;
  width: 100%;
  max-width: 500px;
}

#board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 5px;
  width: min(90vw, 350px);
}

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

.tile {
  aspect-ratio: 1;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: bold;
  text-transform: uppercase;
  user-select: none;
  cursor: pointer;
  transition: transform 0.15s ease;
}

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

.tile.active {
  border-color: var(--correct);
  box-shadow: 0 0 0 1px var(--correct);
}

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

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

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

.tile.pop {
  animation: pop 0.1s ease;
}

@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.tile.flip {
  animation: flip 0.5s ease;
}

@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}

.tile.shake {
  animation: shake 0.5s ease;
}

@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

.tile.bounce {
  animation: bounce 0.6s ease;
}

@keyframes bounce {
  0%, 20% { transform: translateY(0); }
  40% { transform: translateY(-22px); }
  50% { transform: translateY(0); }
  60% { transform: translateY(-10px); }
  80% { transform: translateY(0); }
}

#message.win-message {
  animation: pulse 0.6s ease 2;
  color: var(--correct);
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

#message {
  min-height: 1.5em;
  font-weight: bold;
  text-align: center;
}

#word-count {
  margin: 0;
  font-size: 0.8rem;
  color: var(--border-strong);
  text-align: center;
}

#keyboard {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 500px;
}

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

.key {
  background: var(--key-bg);
  border: none;
  border-radius: 4px;
  color: var(--fg);
  font-weight: bold;
  text-transform: uppercase;
  cursor: pointer;
  padding: 0;
  height: 48px;
  flex: 1;
  max-width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
}

.key.wide {
  max-width: 60px;
  font-size: 0.7rem;
}

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

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

.key.absent {
  background: var(--absent);
  color: white;
  opacity: 0.6;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--bg);
  color: var(--fg);
  padding: 24px;
  border-radius: 8px;
  border: 2px solid var(--border-strong);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  max-width: 400px;
  width: 90%;
  animation: modal-in 0.15s ease;
}

@keyframes modal-in {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-content h2 {
  margin-top: 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.modal-content h3 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--border-strong);
  margin-bottom: 6px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.btn-primary,
.btn-secondary {
  padding: 10px 18px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 0.85rem;
}

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

.btn-secondary {
  background: var(--key-bg);
  color: var(--fg);
}

.modal-content ul {
  list-style: none;
  padding: 0;
}

.modal-content li {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
}

.example-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  font-weight: bold;
  color: white;
  border-radius: 3px;
}

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

#close-help-btn,
#close-stats-btn {
  margin-top: 12px;
}

.stats-summary {
  display: flex;
  justify-content: space-around;
  text-align: center;
  margin: 12px 0;
}

.stats-summary .stat {
  display: flex;
  flex-direction: column;
}

.stats-summary .stat-value {
  font-size: 1.6rem;
  font-weight: bold;
}

.stats-summary .stat-label {
  font-size: 0.7rem;
  color: var(--border-strong);
}

.stats-distribution {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 12px 0;
}

.dist-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
}

.dist-label {
  width: 12px;
  font-weight: bold;
}

.dist-bar-wrap {
  flex: 1;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.dist-bar {
  background: var(--absent);
  color: white;
  text-align: right;
  padding: 2px 6px;
  min-width: 20px;
  font-size: 0.75rem;
  white-space: nowrap;
}

.dist-bar.highlight {
  background: var(--correct);
}

.stats-solved {
  max-height: 150px;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.solved-word {
  background: var(--key-bg);
  color: var(--fg);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 0.8rem;
  text-transform: uppercase;
  font-weight: bold;
}

.stats-empty {
  font-size: 0.85rem;
  color: var(--border-strong);
}

#site-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px 16px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--border-strong);
  background: var(--bg);
  border-top: 1px solid var(--border);
  z-index: 5;
}

#site-footer a {
  color: var(--border-strong);
  font-weight: bold;
  text-decoration: none;
}

#site-footer a:hover {
  text-decoration: underline;
}
