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

:root {
  --purple: #7c3aed;
  --purple-dark: #5b21b6;
  --blue: #3b82f6;
  --blue-dark: #2563eb;
  --green: #22c55e;
  --green-dark: #16a34a;
  --orange: #f97316;
  --orange-dark: #ea580c;
  --red: #ef4444;
  --red-dark: #dc2626;
  --yellow: #eab308;
  --yellow-dark: #ca8a04;
  --grey: #6b7280;
  --grey-dark: #4b5563;
  --bg: #f0f4ff;
  --card-bg: #ffffff;
  --header-bg: #ffffff;
  --nav-bg: #ffffff;
  --input-bg: #ffffff;
  --surface-muted: #e2e8f0;
  --surface-soft: #f8fafc;
  --surface-soft-alt: #f5f5f5;
  --border-color: #e2e8f0;
  --text: #1e293b;
  --text-light: #64748b;
  --shadow: 0 4px 20px rgba(0,0,0,0.1);
  --shadow-btn: 0 6px 0 rgba(0,0,0,0.15);
  --radius: 16px;
  --radius-sm: 10px;
  --nav-height: 72px;
}

html[data-theme="dark"] {
  --bg: #202631;
  --card-bg: #2b3340;
  --header-bg: #252d39;
  --nav-bg: #252d39;
  --input-bg: #1f2631;
  --surface-muted: #3b4658;
  --surface-soft: #313948;
  --surface-soft-alt: #2a313d;
  --border-color: #4b576d;
  --text: #e7edf7;
  --text-light: #aeb9cc;
  --shadow: 0 10px 28px rgba(0,0,0,0.28);
  --shadow-btn: 0 6px 0 rgba(0,0,0,0.28);
}

html, body {
  height: 100%;
  font-family: 'Nunito', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ===== SCREENS ===== */
.screen {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: none;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}
.screen.active {
  display: flex;
}

/* ===== SCREEN HEADER ===== */
.screen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--header-bg);
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  z-index: 10;
  min-height: 60px;
}
.screen-title {
  font-family: 'Fredoka One', cursive;
  font-size: 1.4rem;
  color: var(--purple);
}
.header-spacer {
  width: 40px;
}
.header-actions {
  width: 40px;
  display: flex;
  justify-content: flex-end;
}

.theme-toggle {
  width: 40px;
  height: 40px;
  border: 2px solid var(--border-color);
  border-radius: 999px;
  background: var(--card-bg);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
  transition: transform 0.16s ease, background-color 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}
.theme-toggle:active {
  transform: translateY(2px);
}
.theme-toggle.dark-active {
  background: rgba(59, 130, 246, 0.16);
  border-color: rgba(96, 165, 250, 0.45);
}

/* ===== SCREEN BODY ===== */
.screen-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  padding-bottom: calc(var(--nav-height) + 20px);
  -webkit-overflow-scrolling: touch;
}

/* ===== BUTTONS ===== */
.btn {
  font-family: 'Fredoka One', cursive;
  font-size: 1rem;
  border: none;
  border-radius: var(--radius);
  padding: 14px 28px;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  box-shadow: var(--shadow-btn);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-decoration: none;
  position: relative;
  overflow: hidden;
}
.btn::after,
.btn-back::after,
.nav-btn::after,
.letter-btn::after,
.btn-item::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.28), rgba(255,255,255,0));
  opacity: 0;
  transition: opacity 0.18s ease;
  pointer-events: none;
}
.btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 rgba(0,0,0,0.15);
}
.btn-sm {
  padding: 8px 16px;
  font-size: 0.85rem;
}
.btn-big {
  width: 100%;
  padding: 20px 28px;
  font-size: 1.2rem;
  margin-bottom: 16px;
}
.btn-purple { background: var(--purple); }
.btn-purple:active { background: var(--purple-dark); }
.btn-blue { background: var(--blue); }
.btn-blue:active { background: var(--blue-dark); }
.btn-green { background: var(--green); }
.btn-green:active { background: var(--green-dark); }
.btn-orange { background: var(--orange); }
.btn-orange:active { background: var(--orange-dark); }
.btn-red { background: var(--red); }
.btn-red:active { background: var(--red-dark); }
.btn-yellow { background: var(--yellow); color: #1e293b; }
.btn-yellow:active { background: var(--yellow-dark); }
.btn-grey { background: var(--grey); }
.btn-grey:active { background: var(--grey-dark); }

.btn-emoji {
  font-size: 1.6rem;
}

.btn-google {
  background: var(--card-bg);
  color: var(--text);
  border: 2px solid var(--border-color);
  box-shadow: 0 4px 0 #ccc;
}
.btn-google:active {
  background: var(--surface-soft-alt);
  box-shadow: 0 2px 0 #ccc;
}
.google-icon {
  width: 20px;
  height: 20px;
}

.btn-guest {
  background: var(--grey);
  box-shadow: 0 4px 0 var(--grey-dark);
}

.btn-back {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  color: var(--text);
  position: relative;
  transition: transform 0.16s ease, background-color 0.16s ease;
}
.btn-back:active {
  background: rgba(0,0,0,0.05);
}

/* ===== TOGGLE BUTTONS ===== */
.btn-toggle {
  background: var(--surface-muted);
  color: var(--text);
  box-shadow: none;
  padding: 10px 20px;
  font-size: 0.9rem;
  border-radius: 25px;
}
.btn-toggle.active {
  background: var(--purple);
  color: white;
}

/* ===== LOGIN ===== */
.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 40px 20px;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at top left, rgba(59, 130, 246, 0.14), transparent 34%),
    radial-gradient(circle at bottom right, rgba(251, 191, 36, 0.12), transparent 30%),
    linear-gradient(180deg, #f8fbff 0%, #eef4ff 100%);
}
.login-container::before,
.login-container::after {
  content: '';
  position: absolute;
  border-radius: 999px;
  pointer-events: none;
}
.login-container::before {
  width: 240px;
  height: 240px;
  top: -110px;
  left: -80px;
  background: rgba(59, 130, 246, 0.08);
  filter: blur(10px);
}
.login-container::after {
  width: 200px;
  height: 200px;
  right: -60px;
  bottom: -70px;
  background: rgba(251, 191, 36, 0.12);
  filter: blur(10px);
}
.logo-area {
  position: relative;
  z-index: 1;
  text-align: center;
  margin-bottom: 60px;
}
.game-title {
  font-family: 'Fredoka One', cursive;
  font-size: 3.5rem;
  color: var(--text);
  text-shadow: 0 4px 18px rgba(59, 130, 246, 0.12);
  letter-spacing: 2px;
}
.game-title .highlight {
  color: var(--blue);
}
.tagline {
  color: var(--text-light);
  font-size: 1.1rem;
  margin-top: 8px;
  font-weight: 600;
}
.login-buttons {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 320px;
}

/* ===== HOME ===== */
.home-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-top: 40px;
}

/* ===== COINS ===== */
.coins-display {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  font-family: 'Fredoka One', cursive;
  font-size: 1rem;
  color: var(--text);
}
.coin-icon {
  font-size: 1.2rem;
}

/* ===== SOLO MENU ===== */
.solo-section {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.solo-section h3 {
  font-family: 'Fredoka One', cursive;
  font-size: 1.2rem;
  margin-bottom: 6px;
}
.section-desc {
  color: var(--text-light);
  font-size: 0.9rem;
  margin-bottom: 16px;
}
.difficulty-selector {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.btn-diff {
  flex: 1;
  background: var(--surface-muted);
  color: var(--text);
  box-shadow: none;
  padding: 10px;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
}
.btn-diff.active {
  background: var(--blue);
  color: white;
  box-shadow: 0 3px 0 var(--blue-dark);
}

.letter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
  gap: 8px;
}
.letter-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  font-family: 'Fredoka One', cursive;
  font-size: 1.2rem;
  background: var(--purple);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  min-height: 82px;
  padding: 10px 6px 8px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--purple-dark);
  transition: transform 0.1s;
  position: relative;
}
.letter-btn .letter-main {
  display: block;
  line-height: 1;
  margin-bottom: 8px;
}
.letter-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--purple-dark);
}
.letter-btn .letter-best {
  display: block;
  font-size: 0.55rem;
  line-height: 1.15;
  color: rgba(255,255,255,0.75);
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.letter-btn .letter-best-global {
  color: rgba(255,255,255,0.92);
}
.letter-btn .letter-best-personal {
  color: rgba(255,255,255,0.72);
}

/* ===== GAME SCREEN ===== */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--header-bg);
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  z-index: 10;
}
.game-info {
  display: flex;
  gap: 24px;
  align-items: center;
}
.game-letter-display, .game-score-display, .game-turn-display {
  text-align: center;
}
.game-letter-display .label, .game-score-display .label, .game-turn-display .label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-light);
  text-transform: uppercase;
  font-weight: 700;
}
.big-letter {
  font-family: 'Fredoka One', cursive;
  font-size: 2rem;
  color: var(--purple);
}
.game-score-display span:last-child,
.game-turn-display span:last-child {
  font-family: 'Fredoka One', cursive;
  font-size: 1.4rem;
}

.game-items {
  display: flex;
  gap: 8px;
}
.btn-item {
  background: none;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 1.2rem;
  cursor: pointer;
  position: relative;
  transition: transform 0.16s ease, border-color 0.16s ease, background-color 0.16s ease;
}
.btn-item span {
  font-size: 0.7rem;
  font-family: 'Fredoka One', cursive;
  position: absolute;
  bottom: -2px;
  right: -2px;
  background: var(--purple);
  color: white;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.game-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.timer-bar-container {
  height: 6px;
  background: var(--surface-muted);
  width: 100%;
}
.timer-bar {
  height: 100%;
  background: var(--green);
  transition: width 0.1s linear, background-color 0.3s;
  width: 100%;
}
.timer-bar.warning {
  background: var(--orange);
}
.timer-bar.danger {
  background: var(--red);
}

.words-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.word-item {
  background: var(--card-bg);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
  font-weight: 700;
  animation: slideIn 0.3s ease;
}
.word-item.invalid {
  background: #fef2f2;
  color: var(--red);
  text-decoration: line-through;
}
.word-item.hint {
  background: #fffbeb;
  color: var(--yellow-dark);
}

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

.game-input-area {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  background: var(--header-bg);
  box-shadow: 0 -2px 10px rgba(0,0,0,0.06);
}

.multi-eliminated-banner {
  position: absolute;
  inset: 46px 16px auto;
  display: flex;
  justify-content: center;
  z-index: 3;
  pointer-events: none;
}

.multi-eliminated-box {
  width: min(100%, 420px);
  background: rgba(239, 68, 68, 0.94);
  color: white;
  border-radius: var(--radius);
  padding: 18px 20px;
  text-align: center;
  box-shadow: 0 14px 30px rgba(0,0,0,0.2);
}

.multi-eliminated-box h3 {
  font-family: 'Fredoka One', cursive;
  font-size: 1.5rem;
  margin-bottom: 8px;
}

.multi-eliminated-box p {
  font-weight: 700;
  opacity: 0.95;
}
.word-input {
  flex: 1;
  font-family: 'Nunito', sans-serif;
  font-size: 16px;
  font-weight: 700;
  padding: 14px 18px;
  border: 3px solid var(--border-color);
  background: var(--input-bg);
  color: var(--text);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.2s;
}
.word-input:focus {
  border-color: var(--purple);
}
.btn-submit {
  padding: 14px 24px;
  font-size: 1rem;
}

/* ===== GAME OVER ===== */
.gameover-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 40px 20px;
  text-align: center;
}
.gameover-container h2 {
  font-family: 'Fredoka One', cursive;
  font-size: 2rem;
  color: var(--purple);
  margin-bottom: 30px;
}
.gameover-stats {
  display: flex;
  gap: 20px;
  margin-bottom: 40px;
  flex-wrap: wrap;
  justify-content: center;
}
.stat-item {
  background: var(--card-bg);
  padding: 16px 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}
.stat-item .stat-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-light);
  margin-bottom: 4px;
}
.stat-item .stat-value {
  font-family: 'Fredoka One', cursive;
  font-size: 1.8rem;
  color: var(--purple);
}
.gameover-actions {
  width: 100%;
  max-width: 320px;
}

#screen-multi-gameover .gameover-container {
  justify-content: flex-start;
  min-height: 100%;
  overflow-y: auto;
  padding-bottom: 32px;
}

/* ===== MULTI PLAYERS SCORES ===== */
.multi-players-scores {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  overflow-x: auto;
  flex-shrink: 0;
}
.player-score-chip {
  background: var(--card-bg);
  padding: 8px 14px;
  border-radius: 25px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  font-weight: 700;
  font-size: 0.85rem;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}
.player-score-chip.active-turn {
  border: 2px solid var(--purple);
  background: rgba(124, 58, 237, 0.08);
}
.player-score-chip.eliminated {
  opacity: 0.4;
  text-decoration: line-through;
}

/* ===== MULTI GAME OVER RANKINGS ===== */
.multi-go-rankings {
  width: 100%;
  max-width: 400px;
  margin-bottom: 30px;
  max-height: min(52vh, 420px);
  overflow-y: auto;
  padding-right: 4px;
}
.ranking-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card-bg);
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}
.ranking-position {
  font-family: 'Fredoka One', cursive;
  font-size: 1.4rem;
  width: 36px;
  text-align: center;
}
.ranking-item:first-child .ranking-position { color: #eab308; }
.ranking-item:nth-child(2) .ranking-position { color: #94a3b8; }
.ranking-item:nth-child(3) .ranking-position { color: #cd7c2f; }
.ranking-name { flex: 1; font-weight: 700; }
.ranking-score { font-family: 'Fredoka One', cursive; color: var(--purple); }

/* ===== LOBBY ===== */
.lobby-players {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}
.lobby-player {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card-bg);
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
  font-weight: 700;
}
.lobby-player .ready-badge {
  background: var(--green);
  color: white;
  padding: 4px 12px;
  border-radius: 25px;
  font-size: 0.8rem;
}
.lobby-player .not-ready-badge {
  background: var(--surface-muted);
  color: var(--text-light);
  padding: 4px 12px;
  border-radius: 25px;
  font-size: 0.8rem;
}
.lobby-player .host-badge {
  background: var(--yellow);
  color: #92400e;
  padding: 4px 12px;
  border-radius: 25px;
  font-size: 0.75rem;
  margin-left: 8px;
}
.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.lobby-actions-top {
  margin-bottom: 20px;
}
.lobby-invite-section {
  margin-top: 24px;
  background: var(--card-bg);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.lobby-invite-section h3 {
  font-family: 'Fredoka One', cursive;
  font-size: 1rem;
  color: var(--purple);
  margin-bottom: 12px;
}
.lobby-invite-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-soft);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}
.lobby-invite-item:last-child {
  margin-bottom: 0;
}
.lobby-invite-name {
  font-weight: 800;
}

/* ===== JOIN INPUT ===== */
.join-input {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.code-input {
  font-family: 'Fredoka One', cursive;
  font-size: 1.6rem;
  text-align: center;
  letter-spacing: 8px;
  width: 180px;
  padding: 12px;
  border: 3px solid var(--border-color);
  background: var(--input-bg);
  color: var(--text);
  border-radius: var(--radius);
  outline: none;
  text-transform: uppercase;
}
.code-input:focus {
  border-color: var(--purple);
}

/* ===== LEADERBOARD ===== */
.leaderboard-toggle {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 20px;
}
.leaderboard-tabs {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.lb-section {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.lb-section h3 {
  font-family: 'Fredoka One', cursive;
  font-size: 1rem;
  margin-bottom: 12px;
  color: var(--purple);
}
.lb-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.lb-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
}
.lb-item:nth-child(1) { background: #fef9c3; }
.lb-item:nth-child(2) { background: #f1f5f9; }
.lb-item:nth-child(3) { background: #fff7ed; }
.lb-rank {
  font-family: 'Fredoka One', cursive;
  font-size: 1.1rem;
  width: 30px;
  text-align: center;
}
.lb-item:nth-child(1) .lb-rank { color: #eab308; }
.lb-item:nth-child(2) .lb-rank { color: #94a3b8; }
.lb-item:nth-child(3) .lb-rank { color: #cd7c2f; }
.lb-name { flex: 1; font-weight: 700; }
.lb-score { font-family: 'Fredoka One', cursive; color: var(--purple); }

/* ===== GUEST MESSAGE ===== */
.guest-message {
  text-align: center;
  padding: 40px 20px;
  font-size: 1.1rem;
  color: var(--text-light);
  font-weight: 700;
}

/* ===== FRIENDS ===== */
.add-friend-area {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}
.friend-input {
  flex: 1;
  font-family: 'Nunito', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  padding: 12px 16px;
  border: 3px solid var(--border-color);
  background: var(--input-bg);
  color: var(--text);
  border-radius: var(--radius);
  outline: none;
}
.friend-input:focus {
  border-color: var(--purple);
}

#friends-content h3 {
  font-family: 'Fredoka One', cursive;
  font-size: 1rem;
  margin-bottom: 12px;
  color: var(--purple);
}

.friend-item, .friend-request-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--card-bg);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}
.friend-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.friend-item .friend-name, .friend-request-item .friend-name {
  font-weight: 700;
}
.friend-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 800;
}
.friend-status.online {
  color: var(--green-dark);
}
.friend-status.offline {
  color: var(--text-light);
}
.friend-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.16);
}
.friend-request-actions {
  display: flex;
  gap: 6px;
}

/* ===== QUESTS ===== */
.chest-section {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
  text-align: center;
}
.chest-section h3 {
  font-family: 'Fredoka One', cursive;
  font-size: 1.1rem;
  margin-bottom: 16px;
  color: var(--purple);
}
.chest-btn {
  position: relative;
}
.chest-emoji {
  font-size: 2rem;
}
.chest-streak-status {
  margin-top: 12px;
  font-weight: 800;
  color: var(--purple);
}
.chest-streak-hint {
  margin-top: 6px;
  font-size: 0.86rem;
  color: var(--text-light);
}
.chest-btn.super-chest {
  background: linear-gradient(135deg, #f59e0b, #facc15);
  color: #4a2500;
}

#quests-content h3 {
  font-family: 'Fredoka One', cursive;
  font-size: 1rem;
  margin-bottom: 12px;
  color: var(--purple);
}

.quest-item {
  background: var(--card-bg);
  padding: 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
  display: flex;
  align-items: center;
  gap: 12px;
}
.quest-info {
  flex: 1;
}
.quest-title {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 4px;
}
.quest-progress {
  font-size: 0.8rem;
  color: var(--text-light);
}
.quest-progress-bar {
  height: 6px;
  background: var(--surface-muted);
  border-radius: 3px;
  margin-top: 6px;
  overflow: hidden;
}
.quest-progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 3px;
  transition: width 0.3s;
}
.quest-reward-btn {
  white-space: nowrap;
}
.quest-reward-btn.claimed {
  background: var(--surface-muted);
  color: var(--text-light);
  box-shadow: none;
  cursor: default;
}

/* ===== PROFILE ===== */
.profile-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  text-align: center;
  margin-bottom: 20px;
}
.profile-avatar {
  font-size: 3rem;
  margin-bottom: 12px;
}
.profile-pseudo-area {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 12px;
}
.pseudo-input {
  font-family: 'Fredoka One', cursive;
  font-size: 1.2rem;
  text-align: center;
  padding: 8px 16px;
  border: 3px solid var(--border-color);
  background: var(--input-bg);
  color: var(--text);
  border-radius: var(--radius);
  outline: none;
  width: 200px;
}
.pseudo-input:focus {
  border-color: var(--purple);
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.stat-card {
  background: var(--card-bg);
  padding: 16px;
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
  text-align: center;
}
.stat-card .stat-value {
  font-family: 'Fredoka One', cursive;
  font-size: 1.8rem;
  color: var(--purple);
  display: block;
}
.stat-card .stat-label {
  font-size: 0.8rem;
  color: var(--text-light);
}

.profile-stats h3 {
  font-family: 'Fredoka One', cursive;
  font-size: 1.1rem;
  margin-bottom: 12px;
  color: var(--purple);
}

.profile-actions {
  margin-top: 20px;
}

/* ===== SHOP ===== */
.shop-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card-bg);
  padding: 16px 20px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.shop-item-info {
  display: flex;
  align-items: center;
  gap: 12px;
}
.shop-emoji {
  font-size: 2rem;
}
.shop-item-info h4 {
  font-family: 'Fredoka One', cursive;
  font-size: 1rem;
}
.shop-item-info p {
  font-size: 0.8rem;
  color: var(--text-light);
}
.btn-shop-buy {
  font-size: 0.9rem;
  padding: 10px 18px;
}
.btn-shop-buy.unaffordable {
  background: var(--red);
  color: white;
  box-shadow: 0 4px 0 var(--red-dark);
}

/* ===== SETTINGS ===== */
.settings-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.settings-card h3 {
  font-family: 'Fredoka One', cursive;
  font-size: 1.1rem;
  color: var(--purple);
  margin-bottom: 14px;
}
.settings-desc {
  font-size: 0.9rem;
  color: var(--text-light);
  margin-bottom: 18px;
}
.settings-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}
.settings-row:last-child {
  margin-bottom: 0;
}
.settings-label {
  font-weight: 800;
  font-size: 0.95rem;
}
.settings-value {
  font-size: 0.85rem;
  color: var(--text-light);
}
.settings-slider {
  width: 100%;
  appearance: none;
  height: 14px;
  border-radius: 999px;
  background: linear-gradient(90deg, #60a5fa, #7c3aed, #f59e0b);
  outline: none;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.12);
  cursor: pointer;
  touch-action: pan-y;
}
.settings-slider::-webkit-slider-thumb {
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--card-bg);
  border: 4px solid var(--purple);
  box-shadow: 0 3px 0 rgba(0,0,0,0.15);
  cursor: pointer;
}
.settings-slider::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--card-bg);
  border: 4px solid var(--purple);
  box-shadow: 0 3px 0 rgba(0,0,0,0.15);
  cursor: pointer;
}
.settings-help-text {
  margin-top: 12px;
  color: var(--text-light);
  line-height: 1.55;
  font-size: 0.98rem;
}

/* ===== CHEST OVERLAY ===== */
.overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.overlay.hidden { display: none; }
.chest-animation {
  position: relative;
  text-align: center;
  min-width: min(80vw, 320px);
  padding: 10px 18px 26px;
}
.chest-box {
  position: relative;
  z-index: 1;
  width: 180px;
  height: 150px;
  margin: 0 auto;
  perspective: 800px;
  transform-style: preserve-3d;
  transform-origin: center bottom;
  animation: chestBounce 0.72s ease-in-out infinite alternate;
}
.chest-box.opened {
  animation: chestShake 0.45s ease-in-out 2, chestFadeOut 0.9s ease forwards 0.62s;
}
.chest-lid,
.chest-base {
  position: absolute;
  left: 0;
  width: 100%;
  background: linear-gradient(180deg, #fbbf24 0%, #f59e0b 100%);
  border: 6px solid #92400e;
  box-shadow: 0 16px 30px rgba(15, 23, 42, 0.24);
}
.chest-lid {
  top: 8px;
  height: 58px;
  border-radius: 26px 26px 14px 14px;
  transform-origin: center bottom;
  transform-style: preserve-3d;
  backface-visibility: hidden;
}
.chest-base {
  bottom: 0;
  height: 92px;
  border-radius: 18px;
}
.chest-lid::before,
.chest-base::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 16px;
  transform: translateX(-50%);
  background: linear-gradient(180deg, #fde68a 0%, #facc15 100%);
  border-left: 4px solid #92400e;
  border-right: 4px solid #92400e;
}
.chest-lock {
  position: absolute;
  left: 50%;
  top: 18px;
  width: 30px;
  height: 34px;
  transform: translateX(-50%);
  border-radius: 8px;
  background: linear-gradient(180deg, #fef3c7 0%, #facc15 100%);
  border: 4px solid #92400e;
}
.chest-lock::before {
  content: '';
  position: absolute;
  left: 50%;
  top: -20px;
  width: 18px;
  height: 18px;
  transform: translateX(-50%);
  border: 4px solid #92400e;
  border-bottom: none;
  border-radius: 16px 16px 0 0;
}
.chest-light {
  position: absolute;
  left: 50%;
  top: 24px;
  width: 150px;
  height: 96px;
  transform: translateX(-50%) scaleY(0.1);
  transform-origin: center top;
  border-radius: 50% 50% 24% 24%;
  background: radial-gradient(circle at top, rgba(255,255,255,0.95), rgba(253,224,71,0.85) 32%, rgba(253,224,71,0.28) 64%, rgba(253,224,71,0) 100%);
  filter: blur(4px);
  opacity: 0;
  pointer-events: none;
}
@keyframes chestBounce {
  from { transform: translateY(0) scale(1); }
  to { transform: translateY(-8px) scale(1.05); }
}
@keyframes chestShake {
  0%, 100% { transform: translateX(0) scale(1.02); }
  20% { transform: translateX(-6px) scale(1.03); }
  40% { transform: translateX(6px) scale(1.05); }
  60% { transform: translateX(-5px) scale(1.07); }
  80% { transform: translateX(5px) scale(1.1); }
}
@keyframes chestFadeOut {
  from { opacity: 1; transform: scale(1.04); }
  to { opacity: 0; transform: translateY(-20px) scale(0.88); }
}
.chest-box.opened .chest-lid {
  animation: chestLidLift 0.72s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}
.chest-box.opened .chest-base {
  animation: chestBaseGlow 0.72s ease forwards;
}
.chest-box.opened .chest-light {
  animation: chestLightBeam 0.72s ease forwards;
}
@keyframes chestLidLift {
  0% { transform: rotateX(0deg) translateY(0); }
  55% { transform: rotateX(102deg) translateY(-6px); }
  100% { transform: rotateX(112deg) translateY(-8px); }
}
@keyframes chestBaseGlow {
  0% { filter: brightness(1); }
  100% { filter: brightness(1.18) drop-shadow(0 0 20px rgba(253,224,71,0.45)); }
}
@keyframes chestLightBeam {
  0% { opacity: 0; transform: translateX(-50%) scaleY(0.1); }
  50% { opacity: 1; transform: translateX(-50%) scaleY(1); }
  100% { opacity: 0.2; transform: translateX(-50%) scaleY(1.2); }
}
.chest-reward {
  position: relative;
  z-index: 1;
  margin-top: 20px;
}
.chest-reward.hidden { display: none; }
.reward-coins {
  font-family: 'Fredoka One', cursive;
  font-size: 2.5rem;
  color: #fbbf24;
  text-shadow: 0 3px 0 rgba(0,0,0,0.3);
  display: inline-block;
  animation: rewardPop 0.7s cubic-bezier(0.2, 0.8, 0.2, 1), rewardFloat 1.4s ease-in-out infinite alternate;
}
@keyframes rewardPop {
  from { transform: translateY(18px) scale(0.35); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}
@keyframes rewardFloat {
  from { transform: translateY(0); }
  to { transform: translateY(-8px); }
}
#btn-chest-close {
  margin-top: 20px;
}
.chest-sparkles {
  position: absolute;
  inset: -56px;
  pointer-events: none;
}
.chest-sparkles.hidden {
  display: none;
}
.chest-sparkles span {
  position: absolute;
  font-size: 2rem;
  opacity: 0;
  animation: sparkleBurst 1.1s ease-out forwards;
}
.chest-sparkles span:nth-child(1) { top: 0; left: 50%; animation-delay: 0s; }
.chest-sparkles span:nth-child(2) { top: 18%; right: 5%; animation-delay: 0.06s; }
.chest-sparkles span:nth-child(3) { bottom: 20%; right: 8%; animation-delay: 0.12s; }
.chest-sparkles span:nth-child(4) { bottom: 0; left: 48%; animation-delay: 0.18s; }
.chest-sparkles span:nth-child(5) { bottom: 26%; left: 4%; animation-delay: 0.24s; }
.chest-sparkles span:nth-child(6) { top: 18%; left: 6%; animation-delay: 0.3s; }
@keyframes sparkleBurst {
  0% { opacity: 0; transform: translate(0, 0) scale(0.4) rotate(0deg); }
  18% { opacity: 1; }
  100% { opacity: 0; transform: translate(0, -32px) scale(1.55) rotate(28deg); }
}

/* ===== TOAST NOTIFICATIONS ===== */
#toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--card-bg);
  color: var(--text);
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  font-weight: 700;
  font-size: 0.9rem;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 4.7s forwards;
  pointer-events: auto;
  max-width: 320px;
}
.toast.success { border-left: 4px solid var(--green); }
.toast.error { border-left: 4px solid var(--red); }
.toast.info { border-left: 4px solid var(--blue); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(50px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(50px); }
}

/* ===== FRIEND REQUEST POPUP ===== */
.popup {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1500;
  background: var(--card-bg);
  color: var(--text);
  padding: 16px 20px;
  border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(0,0,0,0.2);
  border-left: 4px solid var(--purple);
  animation: toastIn 0.3s ease;
  max-width: 320px;
}
.popup.hidden { display: none; }
.popup-content p {
  font-weight: 700;
  margin-bottom: 10px;
}
.popup-actions {
  display: flex;
  gap: 8px;
}
#language-popup {
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  max-width: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.55);
  border-left: none;
}
#language-popup.hidden {
  display: none;
}
.language-popup-content {
  width: min(100%, 420px);
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 14px 40px rgba(0,0,0,0.22);
}
.language-popup-content h3 {
  font-family: 'Fredoka One', cursive;
  color: var(--purple);
  margin-bottom: 12px;
}
.language-popup-note {
  margin-top: 8px;
  color: var(--text-light);
  font-size: 0.92rem;
  line-height: 1.45;
  font-weight: 700;
}
.language-choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 18px;
}

/* ===== BADGES ===== */
.badge {
  position: absolute;
  top: 2px;
  right: 12px;
  background: var(--red);
  color: white;
  font-family: 'Fredoka One', cursive;
  font-size: 0.65rem;
  min-width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}
.badge.hidden { display: none; }

/* ===== BOTTOM NAV ===== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--nav-bg);
  display: flex;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.08);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav.hidden { display: none; }
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-light);
  position: relative;
  overflow: hidden;
  transition: color 0.2s, transform 0.16s ease;
}
.nav-btn.active {
  color: var(--purple);
}

html[data-theme="dark"] .login-container {
  background:
    radial-gradient(circle at top left, rgba(96, 165, 250, 0.16), transparent 34%),
    radial-gradient(circle at bottom right, rgba(251, 191, 36, 0.1), transparent 30%),
    linear-gradient(180deg, #29313d 0%, #1d232d 100%);
}

html[data-theme="dark"] .login-container::before {
  background: rgba(96, 165, 250, 0.12);
}

html[data-theme="dark"] .login-container::after {
  background: rgba(251, 191, 36, 0.1);
}

html[data-theme="dark"] .btn-google {
  box-shadow: 0 4px 0 #1a2029;
}

html[data-theme="dark"] .btn-google:active {
  box-shadow: 0 2px 0 #1a2029;
}

html[data-theme="dark"] .btn-back:active,
html[data-theme="dark"] .nav-btn:hover::after,
html[data-theme="dark"] .btn-item:hover::after,
html[data-theme="dark"] .letter-btn:hover::after,
html[data-theme="dark"] .btn:hover::after {
  background: linear-gradient(135deg, rgba(255,255,255,0.14), rgba(255,255,255,0));
}

html[data-theme="dark"] .word-item.invalid {
  background: rgba(239, 68, 68, 0.18);
}

html[data-theme="dark"] .word-item.hint {
  background: rgba(250, 204, 21, 0.18);
  color: #fde68a;
}

html[data-theme="dark"] .ranking-item,
html[data-theme="dark"] .player-score-chip,
html[data-theme="dark"] .friend-item,
html[data-theme="dark"] .friend-request-item,
html[data-theme="dark"] .quest-item,
html[data-theme="dark"] .shop-item,
html[data-theme="dark"] .stat-item,
html[data-theme="dark"] .lobby-player {
  box-shadow: 0 8px 18px rgba(0,0,0,0.18);
}

html[data-theme="dark"] .lb-item:nth-child(1) {
  background: rgba(234, 179, 8, 0.2);
}

html[data-theme="dark"] .lb-item:nth-child(2) {
  background: rgba(148, 163, 184, 0.16);
}

html[data-theme="dark"] .lb-item:nth-child(3) {
  background: rgba(205, 124, 47, 0.18);
}

html[data-theme="dark"] .overlay {
  background: rgba(7, 10, 16, 0.72);
}

html[data-theme="dark"] .multi-eliminated-box {
  background: rgba(185, 28, 28, 0.96);
}
.nav-icon {
  font-size: 1.4rem;
}
.nav-label {
  font-size: 0.65rem;
  font-weight: 700;
}

/* ===== UTILITIES ===== */
.hidden { display: none !important; }

@media (hover: hover) and (pointer: fine) {
  .btn:hover {
    transform: translateY(-4px) rotate(-1deg) scale(1.01);
    box-shadow: 0 10px 0 rgba(0,0,0,0.14);
  }

  .btn:hover::after,
  .btn-back:hover::after,
  .nav-btn:hover::after,
  .letter-btn:hover::after,
  .btn-item:hover::after {
    opacity: 1;
  }

  .btn-back:hover {
    transform: translateY(-2px) rotate(-4deg);
    background: rgba(124, 58, 237, 0.08);
  }

  .nav-btn:hover {
    transform: translateY(-3px);
  }

  .letter-btn:hover {
    transform: translateY(-4px) rotate(-2deg) scale(1.04);
    box-shadow: 0 8px 0 var(--purple-dark);
  }

  .btn-item:hover {
    transform: translateY(-3px) rotate(-3deg);
    border-color: var(--purple);
    background: #f5f3ff;
  }
}

/* ===== RESPONSIVE ===== */
@media (min-width: 600px) {
  .screen-body {
    max-width: 500px;
    margin: 0 auto;
    width: 100%;
  }
  .login-container {
    max-width: 100%;
  }
  .gameover-container {
    max-width: 500px;
    margin: 0 auto;
  }
}
