/* ─── Reset & base ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #121213;
  --surface: #1a1a1b;
  --border: #3a3a3c;
  --text: #ffffff;
  --text-muted: #818384;
  --correct: #538d4e;
  --present: #b59f3b;
  --absent: #3a3a3c;
  --key-bg: #818384;
  --key-text: #ffffff;
  --accent: #538d4e;
  --tile-size: 62px;
  --tile-gap: 5px;
  --radius: 4px;
}

html { overflow-x: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Clear Sans', 'Helvetica Neue', Arial, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
}

/* ─── Screens ────────────────────────────────────────────────────────── */
.screen { display: none; flex-direction: column; align-items: center; width: 100%; max-width: 480px; padding: 20px 16px; }
.screen.active { display: flex; }

/* ─── Header ─────────────────────────────────────────────────────────── */
header { text-align: center; border-bottom: 1px solid var(--border); width: 100%; padding-bottom: 16px; margin-bottom: 24px; }
h1 { font-size: 2rem; font-weight: 700; letter-spacing: 4px; text-transform: uppercase; }
.subtitle { color: var(--text-muted); font-size: 0.85rem; margin-top: 4px; }

/* ─── Help button ────────────────────────────────────────────────────── */
.header-title-row { position: relative; }
.btn-help {
  position: fixed; top: 20px; right: max(16px, calc(50% - 224px)); z-index: 900;
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--text-muted); background: var(--bg);
  color: var(--text-muted); font-size: 0.9rem; font-weight: 700;
  cursor: pointer; line-height: 1; transition: border-color 0.15s, color 0.15s;
}
.btn-help:hover { border-color: var(--text); color: var(--text); }

/* ─── Help screen ────────────────────────────────────────────────────── */
.help-content { width: 100%; }
.help-intro { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 20px; line-height: 1.5; }
.help-example { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.help-tiles { display: flex; gap: 4px; flex-shrink: 0; }
.help-tile {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; font-weight: 700; text-transform: uppercase;
  border-radius: var(--radius);
}
.help-tile.correct { background: var(--correct); color: #fff; }
.help-tile.present { background: var(--present); color: #fff; }
.help-tile.absent  { background: var(--absent);  color: #fff; }
.help-example p { font-size: 0.88rem; color: var(--text-muted); line-height: 1.4; }
.clue-correct { color: var(--correct); }
.clue-present { color: var(--present); }
.clue-absent  { color: var(--text-muted); }
.help-rule { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.help-modes { display: flex; flex-direction: column; gap: 14px; }
.help-mode-name { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 1.5px; color: var(--correct); margin-bottom: 4px; }
.help-mode-desc { font-size: 0.88rem; color: var(--text-muted); line-height: 1.5; }

/* ─── Auth section ───────────────────────────────────────────────────── */
.auth-section { margin-top: 14px; display: flex; justify-content: center; min-height: 38px; }
.auth-guest { display: flex; align-items: center; gap: 10px; }
.auth-hint { font-size: 0.75rem; color: var(--text-muted); }
.btn-google-signin {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 14px;
  background: #fff; color: #3c4043;
  border: 1px solid #dadce0; border-radius: 4px;
  font-size: 0.85rem; font-weight: 500;
  text-decoration: none; transition: background 0.15s;
}
.btn-google-signin::before {
  content: 'G';
  font-weight: 700; font-size: 1rem;
  background: linear-gradient(135deg, #4285F4 25%, #EA4335 50%, #FBBC05 75%, #34A853 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.btn-google-signin:hover { background: #f1f3f4; }
.auth-user { display: flex; align-items: center; gap: 10px; }
.auth-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border); }
.auth-avatar-placeholder {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--correct); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 700; flex-shrink: 0;
}
.auth-info { display: flex; flex-direction: column; line-height: 1.3; }
.auth-name { font-size: 0.9rem; font-weight: 600; }
.auth-stats { font-size: 0.7rem; color: var(--text-muted); margin-top: 2px; }

/* ─── Word length picker ─────────────────────────────────────────────── */
.word-length-picker { margin-bottom: 28px; text-align: center; }
.word-length-picker label { display: block; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 2px; color: var(--text-muted); margin-bottom: 10px; }
.length-buttons { display: flex; gap: 8px; }
.len-btn {
  width: 46px; height: 46px;
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1.1rem; font-weight: 700;
  cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.len-btn.active { border-color: var(--correct); background: var(--correct); }
.len-btn:hover:not(.active) { border-color: var(--text-muted); }

/* ─── Mode buttons ───────────────────────────────────────────────────── */
.mode-buttons { display: flex; flex-direction: column; gap: 12px; width: 100%; margin-bottom: 24px; }
.daily-area {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.daily-header-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.daily-number { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 2px; color: var(--text-muted); }
.daily-badge { font-size: 0.8rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; }
.badge-win  { background: rgba(83,141,78,0.2);  color: var(--correct); }
.badge-loss { background: rgba(229,83,75,0.15); color: #e5534b; }
.btn-played { opacity: 0.45; cursor: default; }
.btn-played:hover { opacity: 0.45; }

.btn-primary {
  padding: 14px 28px;
  background: var(--correct);
  color: #fff; border: none; border-radius: var(--radius);
  font-size: 1rem; font-weight: 700; cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.85; }

.btn-secondary {
  padding: 12px 24px;
  background: transparent;
  color: var(--text); border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem; font-weight: 600; cursor: pointer;
  transition: border-color 0.15s;
}
.btn-secondary:hover { border-color: var(--text-muted); }

.btn-ghost {
  background: transparent; color: var(--text-muted);
  border: none; cursor: pointer; font-size: 0.9rem;
  padding: 8px 12px; border-radius: var(--radius);
  transition: color 0.15s;
}
.btn-ghost:hover { color: var(--text); }
.btn-ghost.small { font-size: 0.8rem; padding: 6px 10px; }

/* ─── Friends section (home screen) ─────────────────────────────────── */
.friends-section { width: 100%; }

/* ─── Ad section ─────────────────────────────────────────────────────── */
.ad-section { width: 100%; }
.ad-container {
  width: 100%; min-height: 100px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 0.8rem;
}
.divider { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; color: var(--text-muted); font-size: 0.8rem; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ─── Challenge setup ────────────────────────────────────────────────── */
.challenge-word-entry { margin: 20px 0 8px; text-align: left; width: 100%; }
.challenge-word-entry .muted { margin-bottom: 12px; }
.challenge-input-row { display: flex; gap: 8px; }
#challenge-word-input {
  flex: 1; padding: 12px 16px;
  background: var(--surface); color: var(--text);
  border: 2px solid var(--border); border-radius: var(--radius);
  font-size: 1.1rem; font-weight: 700; letter-spacing: 4px;
  text-transform: uppercase; outline: none;
}
#challenge-word-input:focus { border-color: var(--correct); }
.challenge-word-msg { min-height: 20px; font-size: 0.85rem; color: #e5534b; margin-top: 8px; }
#room-code-input {
  flex: 1; padding: 12px 16px;
  background: var(--surface); color: var(--text);
  border: 2px solid var(--border); border-radius: var(--radius);
  font-size: 1.1rem; font-weight: 700; letter-spacing: 4px;
  text-transform: uppercase; text-align: center; outline: none;
}
#room-code-input:focus { border-color: var(--correct); }

/* ─── Waiting screen ─────────────────────────────────────────────────── */
.waiting-box { text-align: center; padding: 40px 20px; }
.waiting-box p { color: var(--text-muted); margin-bottom: 16px; }
.room-code-display {
  font-size: 3rem; font-weight: 900; letter-spacing: 12px;
  color: var(--text); margin: 16px 0 24px;
  padding: 20px; background: var(--surface);
  border: 2px solid var(--border); border-radius: 8px;
}
.muted { font-size: 0.85rem; }

/* ─── Game header ────────────────────────────────────────────────────── */
.game-header {
  display: grid; grid-template-columns: auto 1fr auto;
  align-items: center; gap: 8px;
  width: 100%; border-bottom: 1px solid var(--border);
  padding-bottom: 12px; margin-bottom: 12px;
}
.game-header-center { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.game-header h1 { text-align: center; font-size: 1.5rem; letter-spacing: 3px; }
.mode-label { font-size: 0.7rem; color: var(--text-muted); text-align: center; }

/* ─── Status message ─────────────────────────────────────────────────── */
.status-msg {
  min-height: 28px; text-align: center;
  font-size: 0.85rem; font-weight: 600; color: var(--text);
  margin-bottom: 8px; transition: opacity 0.3s;
}

/* ─── Boards ─────────────────────────────────────────────────────────── */
.boards-area { display: flex; gap: 24px; justify-content: center; flex-wrap: wrap; margin-bottom: 16px; }
.board-wrapper { display: flex; flex-direction: column; align-items: center; }
.board-label { font-size: 0.75rem; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; color: var(--text-muted); margin-bottom: 8px; }

.board {
  display: grid;
  gap: var(--tile-gap);
  /* columns set dynamically via JS */
}

/* ─── Tiles ──────────────────────────────────────────────────────────── */
.tile {
  width: var(--tile-size); height: var(--tile-size);
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; font-weight: 700; text-transform: uppercase;
  user-select: none; transition: border-color 0.05s;
  position: relative;
}
.tile.filled { border-color: #565758; }
.tile.revealed { border-color: transparent; animation: flip 0.5s ease forwards; }
.tile.correct { --tile-bg: var(--correct); color: #fff; }
.tile.present { --tile-bg: var(--present); color: #fff; }
.tile.absent  { --tile-bg: var(--absent);  color: #fff; }

@keyframes flip {
  0%   { transform: scaleY(1); background: var(--bg); }
  49%  { transform: scaleY(0); background: var(--bg); }
  50%  { transform: scaleY(0); background: var(--tile-bg); }
  100% { transform: scaleY(1); background: var(--tile-bg); }
}

/* Opponent board — hidden during race, revealed full-size at game end */
.opponent-board .tile.revealed { animation: flip 0.4s ease forwards; }

/* ─── Keyboard ───────────────────────────────────────────────────────── */
.keyboard { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 500px; padding: 0 8px; }
.key-row { display: flex; justify-content: center; gap: 6px; }
.key {
  height: 58px; min-width: 0; padding: 0 4px;
  background: var(--key-bg); color: var(--key-text);
  border: none; border-radius: 4px;
  font-size: 0.85rem; font-weight: 700;
  cursor: pointer; text-transform: uppercase;
  flex: 1; max-width: 43px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.key.wide { flex: 1.5; max-width: 65px; font-size: 0.75rem; }
.key.correct { background: var(--correct); }
.key.present { background: var(--present); }
.key.absent  { background: #1c1c1e; color: var(--text-muted); }

/* ─── End banner ─────────────────────────────────────────────────────── */
.end-banner {
  margin-top: 16px; padding: 24px; text-align: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; width: 100%; max-width: 480px;
}
.end-banner p { margin-bottom: 8px; }
#end-msg { font-size: 1.2rem; font-weight: 700; }
.end-detail { font-size: 0.82rem; color: var(--text-muted); margin-top: 4px; margin-bottom: 4px; }
#end-word { font-size: 1rem; color: var(--text-muted); margin-bottom: 16px; text-transform: uppercase; letter-spacing: 3px; }

/* ─── Friends nav (home screen) ─────────────────────────────────────── */

/* ─── Friends screen ─────────────────────────────────────────────────── */
.friends-add-area {
  display: flex; gap: 16px; width: 100%; margin-bottom: 24px;
  flex-wrap: wrap;
}
.friends-add-col { flex: 1; min-width: 140px; display: flex; flex-direction: column; gap: 10px; }
.friends-section-label { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 2px; color: var(--text-muted); }
.friends-hint { font-size: 0.8rem; color: var(--text-muted); line-height: 1.4; }
.friend-code-display {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 2px solid var(--correct);
  border-radius: var(--radius); padding: 10px 14px;
  overflow: hidden;
}
.friend-code-value { font-size: 1.4rem; font-weight: 900; letter-spacing: 6px; color: var(--text); flex: 1; min-width: 0; }
.friend-code-display .btn-ghost { flex-shrink: 0; }
.friends-add-divider { width: 1px; background: var(--border); align-self: stretch; }
.friends-redeem-row { display: flex; flex-direction: column; gap: 8px; }
.friends-redeem-row input { width: 100%; box-sizing: border-box; }
.friends-redeem-row button { align-self: flex-start; }
#friend-code-input {
  flex: 1; padding: 10px 14px;
  background: var(--surface); color: var(--text);
  border: 2px solid var(--border); border-radius: var(--radius);
  font-size: 1rem; font-weight: 700; letter-spacing: 4px;
  text-transform: uppercase; outline: none;
}
#friend-code-input:focus { border-color: var(--correct); }
.redeem-msg { min-height: 18px; font-size: 0.82rem; }
.redeem-msg.error { color: #e5534b; }
.redeem-msg.success { color: var(--correct); }
.friends-list-section { width: 100%; }
.no-friends-msg {
  padding: 12px 0; display: flex; flex-direction: column; gap: 10px;
  font-size: 0.88rem; color: var(--text-muted); line-height: 1.5;
}
.no-friends-msg strong { color: var(--text); }
.no-friends-msg em { font-style: normal; color: var(--text); font-weight: 600; }

/* Friend card */
.friend-card {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border-bottom: 1px solid var(--border);
  gap: 12px;
}
.friend-card:last-child { border-bottom: none; }
.friend-left { display: flex; align-items: center; gap: 10px; }
.friend-avatar-sm {
  width: 36px; height: 36px; border-radius: 50%;
  object-fit: cover; border: 1px solid var(--border); flex-shrink: 0;
}
.friend-avatar-placeholder-sm {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--key-bg); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 700; flex-shrink: 0;
}
.friend-name-row { display: flex; align-items: center; gap: 6px; }
.friend-name { font-size: 0.95rem; font-weight: 600; }
.online-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  background: var(--correct);
}
.offline-dot { background: var(--border); }
.friend-h2h { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }
.friend-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ─── Game invite overlay ────────────────────────────────────────────── */
.invite-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 24px; pointer-events: none;
}
.invite-overlay:not(.hidden) { pointer-events: auto; }
.invite-popup {
  background: var(--surface); border: 1px solid var(--correct);
  border-radius: 10px; padding: 20px 24px;
  width: 100%; max-width: 400px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  animation: slideUp 0.25s ease;
}
.invite-popup-msg { font-size: 1rem; font-weight: 600; margin-bottom: 16px; line-height: 1.4; }
.invite-popup-actions { display: flex; gap: 10px; }
.invite-popup-actions .btn-primary { flex: 1; }
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ─── Stats screen ───────────────────────────────────────────────────── */
.stats-container { width: 100%; }
.stats-table {
  width: 100%; border-collapse: collapse;
  font-size: 0.9rem;
}
.stats-table th {
  text-align: left; padding: 8px 12px;
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 2px;
  color: var(--text-muted); border-bottom: 1px solid var(--border);
}
.stats-table th:not(:first-child) { text-align: center; }
.stats-table td {
  padding: 14px 12px; border-bottom: 1px solid var(--border);
  color: var(--text);
}
.stats-table td:not(:first-child) { text-align: center; }
.stats-table tr:last-child td { border-bottom: none; }
.stats-table .stat-win   { color: var(--correct); font-weight: 700; }
.stats-table .stat-loss  { color: #e5534b; }
.stats-table .stat-draw  { color: var(--text-muted); }
.stats-table .stat-pct   { font-weight: 700; }
.stats-empty { text-align: center !important; color: var(--text-muted); padding: 32px 0 !important; }
.stat-time   { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.stats-section { margin-top: 28px; }
.stats-section-title {
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 2px; color: var(--text-muted); margin-bottom: 12px;
}

/* Today's challenge comparison */
.dc-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.dc-row:last-child { border-bottom: none; }
.dc-row-me .dc-name { font-weight: 700; color: var(--text); }
.dc-name { color: var(--text); }
.dc-result { display: flex; align-items: center; gap: 6px; }
.stat-muted { color: var(--text-muted); }
.stat-win  { color: var(--correct); font-weight: 700; }
.stat-loss { color: #e5534b; }

/* PvP per-opponent */
.pvp-opp-block {
  padding: 12px 0; border-bottom: 1px solid var(--border); font-size: 0.9rem;
}
.pvp-opp-block:last-child { border-bottom: none; }
.pvp-opp-name { font-weight: 700; color: var(--text); margin-bottom: 8px; }
.pvp-mode-table { display: flex; flex-direction: column; gap: 4px; }
.pvp-mode-row { display: flex; justify-content: space-between; align-items: center; }
.pvp-mode-label { color: var(--text-muted); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.06em; }
.pvp-mode-record { display: flex; gap: 8px; }

/* ─── Utilities ──────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.shake { animation: shake 0.4s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%  { transform: translateX(-6px); }
  40%  { transform: translateX(6px); }
  60%  { transform: translateX(-4px); }
  80%  { transform: translateX(4px); }
}

/* ─── Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 400px) {
  :root { --tile-size: 52px; }
  .tile { font-size: 1.6rem; }
  .key { height: 50px; }
  .key.wide { font-size: 0.65rem; }
  .key-row { gap: 4px; }
  .keyboard { padding: 0 4px; }
}
