:root {
  --bg: #121213;
  --tile-border: #3a3a3c;
  --tile-border-active: #565758;
  --text: #ffffff;
  --key-bg: #818384;
  --key-text: #ffffff;
  --correct: #538d4e;
  --present: #b59f3b;
  --absent: #3a3a3c;
  --tile-size: 62px;
  --gap: 5px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 500px;
  margin: 0 auto;
}

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--tile-border);
}
/* Equal-width side groups so the title stays truly centered regardless of
   how many buttons each side has. */
.topbar-left { flex: 1; display: flex; justify-content: flex-start; }
.topbar .actions { flex: 1; justify-content: flex-end; }
.title {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 4px;
  margin: 0;
}
.lang-switch { display: flex; gap: 4px; }
.lang-btn {
  background: transparent;
  color: var(--key-bg);
  border: 1px solid var(--tile-border);
  border-radius: 6px;
  padding: 6px 10px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}
.lang-btn.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.actions { display: flex; gap: 4px; }
.icon-btn {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.icon-btn:hover { background: var(--tile-border); }

/* ---- Board ---- */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px;
}
.board {
  display: grid;
  grid-template-rows: repeat(6, var(--tile-size));
  gap: var(--gap);
}
.row {
  display: grid;
  grid-template-columns: repeat(5, var(--tile-size));
  gap: var(--gap);
}
.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  border: 2px solid var(--tile-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text);
  transition: transform 0.1s ease;
}
.tile.filled {
  border-color: var(--tile-border-active);
  animation: pop 0.1s ease;
}
.tile.correct { background: var(--correct); border-color: var(--correct); }
.tile.present { background: var(--present); border-color: var(--present); }
.tile.absent  { background: var(--absent);  border-color: var(--absent);  }

.tile.reveal { animation: flip 0.5s ease forwards; }
.row.shake { animation: shake 0.4s ease; }
.row.win .tile { animation: bounce 0.6s ease; }

@keyframes pop { from { transform: scale(0.9); } to { 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%,60% { transform: translateX(-6px); }
  40%,80% { transform: translateX(6px); }
}
@keyframes bounce {
  0%,100% { transform: translateY(0); }
  40%     { transform: translateY(-24px); }
  60%     { transform: translateY(-10px); }
}

/* ---- Hint ---- */
.hint-area {
  min-height: 24px;
  font-size: 15px;
  color: #d7dadc;
  text-align: center;
  max-width: 90%;
}
.hint-area .clue { font-style: italic; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 12px 18px;
  border-radius: 6px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 10;
}
.toast.show { opacity: 1; }

/* ---- Keyboard ---- */
.keyboard {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
}
.kb-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}
.key {
  min-width: 32px;
  height: 54px;
  flex: 1;
  max-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: 5px;
  background: var(--key-bg);
  color: var(--key-text);
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
}
.key.wide { flex: 1.5; max-width: 66px; font-size: 12px; }
.key.correct { background: var(--correct); }
.key.present { background: var(--present); }
.key.absent  { background: var(--absent); }
.key:active { filter: brightness(1.2); }

/* ============ Icons ============ */
.icon { display: block; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; }
.icon-btn .icon { width: 20px; height: 20px; }
button [data-icon], .status-line [data-icon], .stat [data-icon] {
  display: inline-flex; vertical-align: middle;
}

/* ============ Mode switch ============ */
.mode-switch {
  display: flex;
  gap: 6px;
  justify-content: center;
  padding: 10px 12px 2px;
}
.mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  color: var(--key-bg);
  border: 1px solid var(--tile-border);
  border-radius: 999px;
  padding: 7px 16px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.mode-btn .icon { width: 16px; height: 16px; }
.mode-btn.active {
  background: var(--correct);
  color: #fff;
  border-color: var(--correct);
}

/* ============ Status line ============ */
.status-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 20px;
  font-size: 13px;
  color: var(--key-bg);
  letter-spacing: 0.5px;
}
.status-line .icon { width: 15px; height: 15px; }

/* ============ Modals ============ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-card {
  position: relative;
  background: #1a1a1b;
  border: 1px solid var(--tile-border);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 380px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-card h2 {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 12px; font-size: 20px;
}
.modal-close {
  position: absolute; top: 12px; right: 12px;
  color: var(--key-bg);
}
.muted { color: var(--key-bg); font-size: 13px; margin: 6px 0 16px; }
.modal-card label {
  display: block;
  font-size: 13px;
  color: var(--key-bg);
  margin-bottom: 12px;
}
.modal-card input {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 10px 12px;
  background: #121213;
  border: 1px solid var(--tile-border-active);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
}
.modal-card input:focus { outline: none; border-color: var(--correct); }
.form-error { color: #e06b6b; font-size: 13px; min-height: 18px; margin-bottom: 8px; }
.modal-actions { display: flex; gap: 8px; margin-top: 8px; }
.btn {
  flex: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 14px;
  border: 1px solid var(--tile-border-active);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-weight: 700; font-size: 14px;
  cursor: pointer;
}
.btn .icon { width: 16px; height: 16px; }
.btn-primary { background: var(--correct); border-color: var(--correct); color: #fff; }
.btn:active { filter: brightness(1.15); }

/* ============ Stats grid ============ */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 6px 0 18px;
}
.stat {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: #121213;
  border: 1px solid var(--tile-border);
  border-radius: 10px;
  padding: 12px 8px;
}
.stat .icon { width: 18px; height: 18px; color: var(--present); margin-bottom: 2px; }
.stat b { font-size: 22px; }
.stat small { color: var(--key-bg); font-size: 11px; text-align: center; }

/* ============ Leaderboard ============ */
.lb-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.lb-tab {
  flex: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px;
  border: 1px solid var(--tile-border);
  border-radius: 8px;
  background: transparent; color: var(--key-bg);
  font-weight: 700; font-size: 13px; cursor: pointer;
}
.lb-tab .icon { width: 15px; height: 15px; }
.lb-tab.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.lb-body { min-height: 120px; }
.lb-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.lb-table th {
  text-align: left; color: var(--key-bg); font-size: 12px;
  font-weight: 700; padding: 6px 8px; border-bottom: 1px solid var(--tile-border);
}
.lb-table td { padding: 8px; border-bottom: 1px solid #262626; }
.lb-table tbody tr:nth-child(1) td { color: #f5c518; font-weight: 700; }
.lb-table td:first-child, .lb-table th:first-child { width: 32px; text-align: center; }
