:root {
  --bg: #121213;
  --fg: #ffffff;
  --border: #3a3a3c;
  --correct: #538d4e;
  --present: #b59f3b;
  --absent: #3a3a3c;
  --key-bg: #818384;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 12px;
}

header { text-align: center; margin-bottom: 8px; }
header h1 { margin: 0; font-size: 28px; letter-spacing: 2px; }
#subtitle { margin: 4px 0 0; color: #aaa; font-size: 14px; }

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

/* Author `display` rules above win over the UA [hidden] stylesheet rule by
   cascade origin regardless of specificity — restate it explicitly here. */
#gameTab[hidden],
#leaderboardTab[hidden] {
  display: none;
}

#grid {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 320px;
}

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

.cell {
  aspect-ratio: 1;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: bold;
  text-transform: uppercase;
  border-radius: 4px;
  transition: transform 0.1s ease;
  transform-style: preserve-3d;
}

.cell.correct { background: var(--correct); border-color: var(--correct); }
.cell.present { background: var(--present); border-color: var(--present); }
.cell.absent  { background: var(--absent);  border-color: var(--absent); }
.cell.filled  { border-color: #565758; transform: scale(1.05); }

.cell.flip { animation: cellFlip 0.35s ease; }
@keyframes cellFlip {
  0%   { transform: rotateY(0deg); }
  45%  { transform: rotateY(90deg); }
  55%  { transform: rotateY(90deg); }
  100% { transform: rotateY(0deg); }
}

.row.win .cell { animation: cellBounce 0.55s ease; }
@keyframes cellBounce {
  0%, 100% { transform: translateY(0); }
  30%      { transform: translateY(-14px); }
  50%      { transform: translateY(0); }
  70%      { transform: translateY(-6px); }
}

#message {
  min-height: 20px;
  font-size: 14px;
  color: #f5c518;
  text-align: center;
}

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

#keyboard[hidden] { display: none; }

.kb-row { display: flex; justify-content: center; gap: 4px; }

.key {
  background: var(--key-bg);
  color: var(--fg);
  border: none;
  border-radius: 4px;
  padding: 12px 0;
  flex: 1;
  max-width: 34px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-transform: uppercase;
}

.key.wide { max-width: 58px; font-size: 11px; }
.key.correct { background: var(--correct); }
.key.present { background: var(--present); }
.key.absent  { background: #2b2b2c; color: #777; }
.key { transition: transform 0.08s ease, background-color 0.2s ease; }
.key.pressed { transform: scale(0.88); }

#shareBtn {
  background: var(--correct);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  max-width: 320px;
}

#shareBtn:active { opacity: 0.85; }

#tabs {
  display: flex;
  gap: 4px;
  background: #1e1e1f;
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 16px;
}

.tab {
  background: transparent;
  border: none;
  color: #888;
  padding: 8px 22px;
  border-radius: 7px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.tab.active { background: var(--key-bg); color: #fff; }

#leaderboardTab {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

#leaderboardHint {
  color: #888;
  font-size: 13px;
  text-align: center;
  margin: 0 0 14px;
}

#leaderboardList {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #1e1e1f;
  border-radius: 8px;
  padding: 10px 14px;
  animation: lbIn 0.25s ease;
}

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

.lb-rank {
  font-weight: 700;
  color: #888;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}

.lb-row:nth-child(1) .lb-rank { color: #ffd54a; }
.lb-row:nth-child(2) .lb-rank { color: #c7cad1; }
.lb-row:nth-child(3) .lb-rank { color: #cd8a4f; }

.lb-name {
  flex: 1;
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-streak {
  color: var(--present);
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.lb-wins {
  color: #888;
  font-size: 12px;
  flex-shrink: 0;
  min-width: 52px;
  text-align: right;
}

.lb-empty {
  text-align: center;
  color: #777;
  padding: 32px 12px;
  font-size: 14px;
}
