:root {
  --bg:          #121213;
  --surface:     #1a1a1b;
  --surface-2:   #272729;
  --border:      #3a3a3c;
  --text:        #ffffff;
  --text-muted:  #818384;
  --green:       #538d4e;
  --green-light: #6aaa64;
  --red:         #b53333;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --radius: 6px;
}

[hidden] { display: none !important; }

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
}

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

.header-title {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.header-btns { display: flex; gap: 8px; }

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius);
}
.icon-btn:hover { background: var(--surface-2); }

/* ---- Hint banner ---- */
.hint-banner {
  text-align: center;
  padding: 14px 16px 6px;
  width: 100%;
  max-width: 700px;
}

.hint-category-tag {
  display: inline-block;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 5px 18px;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text);
}

.hint-date {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 5px;
}

.hint-timer {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}

.header-greeting {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 4px;
}

.hint-difficulty {
  display: inline-block;
  border-radius: 99px;
  padding: 5px 14px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  margin-left: 8px;
}
.hint-difficulty--easy   { background: #1a3a1a; color: #6aaa64; border: 1px solid #538d4e; }
.hint-difficulty--medium { background: #3a2e00; color: #f0c040; border: 1px solid #a07800; }
.hint-difficulty--hard   { background: #3a1a1a; color: #e07070; border: 1px solid #b53333; }

/* ---- Phrase display ---- */
.phrase-container {
  width: 100%;
  max-width: 700px;
  padding: 24px 12px 12px;
  overflow-x: auto;
}

.phrase-words {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 16px;
  justify-content: center;
}

.phrase-word {
  display: flex;
  gap: 4px;
  padding: 6px 6px 10px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  position: relative;
}

.phrase-word::after {
  content: '';
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 3px;
  height: 2px;
  border-radius: 1px;
  background: var(--text-muted);
  opacity: 0.5;
}

.phrase-tile {
  width: 36px;
  height: 42px;
  border: 2px solid #9a9a9e;
  border-radius: var(--radius);
  background: #55555a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--text);
  transition: background 0.25s, border-color 0.25s;
  user-select: none;
}

.phrase-tile--revealed {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.phrase-tile--loss {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.phrase-tile--pop {
  transform: scale(1.15);
  transition: transform 0.1s;
}

/* ---- Lives ---- */
.lives-row {
  display: flex;
  gap: 8px;
  padding: 8px 0 4px;
  justify-content: center;
}

.life-pip {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #e74c3c;
  display: inline-block;
  transition: background 0.2s;
}

.life-pip--lost {
  background: var(--surface-2);
  border: 2px solid var(--border);
}

/* ---- Keyboard ---- */
.keyboard-container {
  width: 100%;
  max-width: 500px;
  padding: 12px 8px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.key {
  flex: 1;
  max-width: 42px;
  height: 56px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.key:hover:not(:disabled) { background: var(--border); }
.key:active:not(:disabled) { transform: scale(0.95); }
.key:disabled { cursor: default; }

.key--correct {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
  opacity: 0.85;
}

.key--wrong {
  background: var(--surface);
  border-color: var(--surface);
  color: var(--text-muted);
  opacity: 0.5;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%       { transform: translateX(-4px); }
  75%       { transform: translateX(4px); }
}
.key--shake { animation: shake 0.35s ease; }

/* ---- End panel ---- */
.end-panel {
  width: 100%;
  max-width: 700px;
  padding: 16px 12px;
  text-align: center;
}

.end-title {
  font-size: 1.25rem;
  font-weight: 800;
  margin-bottom: 6px;
}

.end-sub {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 16px;
}
.end-sub strong { color: var(--text); }

.end-btns { display: flex; gap: 8px; justify-content: center; }

.btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s;
}
.btn:hover { background: var(--border); }
.btn--primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn--primary:hover { background: var(--green-light); }
.btn--full { width: 100%; margin-top: 20px; padding: 14px; font-size: 1rem; }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  max-width: 420px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

/* On a narrow phone the weekly leaderboard's 5 columns leave very little
   room for the name — claw back space from padding/gaps here rather than
   letting the name column alone absorb the whole shortfall. */
@media (max-width: 480px) {
  .modal { padding: 16px; }
  .leaderboard-row { gap: 6px; }
}

.leaderboard-scroll {
  max-height: 50vh;
  overflow-y: auto;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 800;
  text-align: center;
  margin-bottom: 20px;
  letter-spacing: 0.05em;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
}

.how-step {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 12px;
  font-size: 0.9rem;
}
.how-emoji { font-size: 1.2rem; min-width: 26px; }
.how-text  { color: var(--text-muted); line-height: 1.5; }
.how-text strong { color: var(--text); }

.build-info {
  margin-top: 16px;
  text-align: center;
  font-size: 0.7rem;
  color: var(--border);
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.stat { text-align: center; }
.stat-num { font-size: 1.6rem; font-weight: 800; }
.stat-lbl { font-size: 0.68rem; color: var(--text-muted); text-transform: uppercase; }
.stat-avg { text-align: center; font-size: 0.85rem; color: var(--text-muted); }
.stat-avg strong { color: var(--text); }

/* Opt-in modal */
.optin-text {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
  text-align: center;
  margin-bottom: 16px;
}

.optin-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 12px;
  font-size: 0.95rem;
  font-family: var(--font);
}
.optin-input:focus { outline: 2px solid var(--green-light); outline-offset: -1px; }

/* Leaderboard */
.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.leaderboard-row:last-child { border-bottom: none; }
.leaderboard-row--header {
  padding-top: 0;
  padding-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.leaderboard-rank { width: 24px; font-weight: 800; color: var(--text-muted); }
/* Name/wrong/time set their own font-size (rather than inheriting the row's)
   so a "ch" width means the same number of pixels in the header row as in a
   data row — otherwise the header's smaller/uppercase text throws every
   column after it out of alignment with the data beneath it. */
/* The name column is the only one allowed to shrink below its ideal
   (max-)width — flex-shrink lets it give up space on a narrow screen
   instead of pushing the fixed-width stat columns off the edge of the
   modal, where they'd silently require a sideways scroll to reach. A
   6ch min-width stops it giving up so much that every name gets reduced
   to two or three letters — past that floor the row scrolls horizontally
   instead, which only bites on the widest name on the smallest screens. */
.leaderboard-name { flex: 1 1 0; min-width: 6ch; font-weight: 600; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard-wrong { flex: 0 0 auto; text-align: right; color: var(--text-muted); font-size: 0.8rem; }
.leaderboard-time { flex: 0 0 auto; text-align: right; font-variant-numeric: tabular-nums; color: var(--text-muted); font-size: 0.9rem; }
.leaderboard-empty { text-align: center; color: var(--text-muted); font-size: 0.9rem; padding: 12px 0; }
.leaderboard-games { flex: 0 0 auto; text-align: right; color: var(--text-muted); font-size: 0.8rem; }

/* Weekly leaderboard */
.weekly-winner-banner {
  text-align: center;
  background: var(--surface-2);
  border: 1px solid var(--green);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
  font-size: 0.9rem;
}
.weekly-winner-banner strong { color: var(--green-light); }

.weekly-winner-banner--winner {
  border: 1px solid transparent;
  background:
    linear-gradient(var(--surface-2), var(--surface-2)) padding-box,
    linear-gradient(120deg, #ffd23f, #ee6c9d, #6c8cff, #ffd23f) border-box;
  background-size: 100% 100%, 300% 300%;
  animation: weekly-winner-shimmer 6s ease infinite, weekly-winner-glow 2.4s ease-in-out infinite;
}
.weekly-winner-banner--winner strong {
  background: linear-gradient(120deg, #ffd23f, #ee6c9d, #6c8cff);
  background-size: 300% 300%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: weekly-winner-shimmer 6s ease infinite;
}
.weekly-winner-trophy {
  display: inline-block;
  animation: weekly-winner-bounce 1.6s ease-in-out infinite;
}
@keyframes weekly-winner-shimmer {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}
@keyframes weekly-winner-glow {
  0%, 100% { box-shadow: 0 0 6px 0 rgba(238, 108, 157, 0.25); }
  50% { box-shadow: 0 0 16px 2px rgba(108, 140, 255, 0.35); }
}
@keyframes weekly-winner-bounce {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-3px) rotate(-8deg); }
  50% { transform: translateY(0) rotate(0deg); }
  75% { transform: translateY(-2px) rotate(8deg); }
}
@media (prefers-reduced-motion: reduce) {
  .weekly-winner-banner--winner,
  .weekly-winner-banner--winner strong,
  .weekly-winner-trophy {
    animation: none;
  }
}
.weekly-subheading {
  color: var(--text-muted);
  font-size: 0.78rem;
  text-align: center;
  margin-bottom: 12px;
  line-height: 1.4;
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: 99px;
  font-size: 0.9rem;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 999;
  white-space: nowrap;
  max-width: 90vw;
  text-align: center;
}
.toast--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---- Responsive ---- */
@media (max-width: 480px) {
  .header-title { font-size: 1.2rem; }
  .phrase-tile { width: 30px; height: 36px; font-size: 0.95rem; }
  .key { height: 48px; font-size: 0.8rem; }
}
