/* ===== RESET & BASE ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #121213;
  --bg-secondary: #1a1a1b;
  --text: #ffffff;
  --text-secondary: #818384;
  --border: #3a3a3c;
  --border-present: #3a3a3c;
  --correct: #538d4e;
  --present: #b59f3b;
  --absent: #3a3a3c;
  --key-bg: #818384;
  --key-text: #ffffff;
  --modal-bg: #121213;
  --modal-overlay: rgba(0,0,0,0.6);
  --cell-size: 58px;
  --gap: 5px;
  --keyboard-gap: 6px;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Clear Sans', 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ===== HEADER ===== */
header {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  height: 50px;
  flex-shrink: 0;
}

h1 {
  font-weight: 700;
  font-size: 2rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

/* ===== MAIN ===== */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  max-width: 500px;
  padding: 0 10px;
  gap: 8px;
  overflow: hidden;
}

/* ===== MESSAGE ===== */
.message {
  height: 24px;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s;
  flex-shrink: 0;
}

/* ===== BOARD ===== */
.board {
  display: grid;
  grid-template-rows: repeat(6, var(--cell-size));
  gap: var(--gap);
  margin-bottom: 8px;
  flex-shrink: 0;
}

.row {
  display: grid;
  grid-template-columns: repeat(5, var(--cell-size));
  gap: var(--gap);
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 700;
  text-transform: uppercase;
  transition: border-color 0.1s;
}

.cell.filled {
  border-color: var(--text-secondary);
  animation: pop 0.1s ease;
}

.cell.reveal {
  animation: flip 0.5s ease forwards;
}

.cell.correct { background: var(--correct); border: none; }
.cell.present { background: var(--present); border: none; }
.cell.absent  { background: var(--absent); border: none; }

.cell.bounce { animation: bounce 0.6s ease; }
.cell.shake  { animation: shake 0.5s ease; }

/* ===== KEYBOARD ===== */
.keyboard {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: var(--keyboard-gap);
  padding-bottom: env(safe-area-inset-bottom, 10px);
  flex-shrink: 0;
}

.kb-row {
  display: flex;
  justify-content: center;
  gap: var(--keyboard-gap);
}

.key {
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  height: 50px;
  min-width: 34px;
  border: none;
  border-radius: 6px;
  background: var(--key-bg);
  color: var(--key-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  flex: 1;
  max-width: 44px;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.key:active { opacity: 0.7; }

.key.wide {
  max-width: 65px;
  font-size: 12px;
}

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

/* ===== MODAL ===== */
.modal {
  position: fixed;
  inset: 0;
  background: var(--modal-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal.hidden { display: none; }

.modal-content {
  background: var(--modal-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 30px 24px;
  text-align: center;
  max-width: 320px;
  width: 100%;
  animation: slideUp 0.3s ease;
}

.modal-content h2 {
  font-size: 1.4rem;
  margin-bottom: 10px;
}

.modal-content p {
  color: var(--text-secondary);
  margin-bottom: 20px;
  font-size: 0.95rem;
}

.modal-btn {
  background: var(--correct);
  color: var(--text);
  border: none;
  border-radius: 8px;
  padding: 12px 32px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  margin-bottom: 16px;
}

.stats {
  display: flex;
  justify-content: center;
  gap: 16px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.stats div {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stats span {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

/* ===== ANIMATIONS ===== */
@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  40%      { transform: translateY(-16px); }
  60%      { transform: translateY(-8px); }
}

@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* ===== RESPONSIVE ===== */
@media (max-height: 650px) {
  :root { --cell-size: 48px; --gap: 4px; }
  header { padding: 6px 0; height: 40px; }
  h1 { font-size: 1.5rem; }
  .key { height: 44px; font-size: 12px; }
}

@media (max-width: 360px) {
  :root { --cell-size: 52px; }
  .key { min-width: 28px; max-width: 38px; font-size: 11px; }
  .key.wide { max-width: 56px; }
}

@media (min-width: 768px) {
  :root { --cell-size: 62px; --gap: 6px; }
  .key { max-width: 48px; height: 56px; font-size: 14px; }
  .key.wide { max-width: 72px; }
}
