:root {
  --bg: #0d0f1a;
  --panel: rgba(20, 23, 38, 0.9);
  --panel-soft: rgba(26, 30, 49, 0.75);
  --accent: #f4d35e;
  --accent-2: #ee6c4d;
  --accent-3: #5bd3c7;
  --text: #f5f5f5;
  --muted: #9aa4c7;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  background: radial-gradient(circle at top, #1d2040 0%, #0d0f1a 55%, #0b0c13 100%);
  color: var(--text);
  min-height: 100vh;
  padding: 32px;
}

a {
  color: var(--accent);
  text-decoration: none;
}

button {
  font-family: inherit;
}

.ambient {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 20% 20%, rgba(244, 211, 94, 0.12), transparent 40%),
    radial-gradient(circle at 80% 10%, rgba(91, 211, 199, 0.12), transparent 35%),
    radial-gradient(circle at 70% 80%, rgba(238, 108, 77, 0.15), transparent 40%);
  pointer-events: none;
  z-index: -1;
}

.badge {
  display: inline-flex;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(244, 211, 94, 0.15);
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  margin-bottom: 28px;
}

.topbar h1 {
  font-family: "Unbounded", sans-serif;
  font-size: 32px;
  margin: 6px 0 4px;
}

.topbar p {
  margin: 0;
  color: var(--muted);
}

.user-panel {
  background: var(--panel);
  padding: 16px 20px;
  border-radius: 18px;
  box-shadow: var(--shadow);
  min-width: 220px;
}

.balance {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  color: var(--muted);
}

.balance strong {
  font-size: 20px;
  color: var(--accent);
  transition: all 0.3s ease;
}

.balance strong.balance-changed {
  animation: balanceFlash 1s ease;
}

@keyframes balanceFlash {
  0%, 100% {
    transform: scale(1);
    color: var(--accent);
  }
  25% {
    transform: scale(1.15);
    color: #fbbf24;
  }
  50% {
    transform: scale(1.1);
    color: #f59e0b;
  }
  75% {
    transform: scale(1.05);
    color: #f59e0b;
  }
}

.user-name {
  margin-top: 10px;
  font-weight: 600;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
}

.user-avatar.fallback {
  background: rgba(244, 211, 94, 0.2);
  color: var(--accent);
}

.user-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.user-actions a,
.user-actions button {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: var(--text);
  padding: 6px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 12px;
}

.hidden {
  display: none;
}

/* Leaderboard Sidebar */
.leaderboard-sidebar {
  width: 280px;
  flex-shrink: 0;
}

.leaderboard-card {
  background: rgba(20, 20, 30, 0.6);
  backdrop-filter: blur(12px);
  border-radius: 20px;
  border: 1px solid rgba(244, 211, 94, 0.2);
  padding: 20px;
  position: sticky;
  top: 20px;
}

.leaderboard-card h3 {
  margin: 0 0 15px;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
}

.leaderboard-list {
  max-height: 400px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.leaderboard-list::-webkit-scrollbar {
  width: 6px;
}

.leaderboard-list::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
}

.leaderboard-list::-webkit-scrollbar-thumb {
  background: rgba(244, 211, 94, 0.3);
  border-radius: 3px;
}

.leaderboard-list::-webkit-scrollbar-thumb:hover {
  background: rgba(244, 211, 94, 0.5);
}

.leaderboard-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  transition: all 0.2s;
}

.leaderboard-item:hover {
  background: rgba(255, 255, 255, 0.06);
  transform: translateX(3px);
}

.leaderboard-item.top-3 {
  background: rgba(244, 211, 94, 0.1);
  border: 1px solid rgba(244, 211, 94, 0.3);
}

.leaderboard-rank {
  font-size: 14px;
  font-weight: 700;
  min-width: 24px;
  text-align: center;
  color: rgba(255, 255, 255, 0.5);
}

.leaderboard-item.top-3 .leaderboard-rank {
  font-size: 18px;
}

.leaderboard-rank.rank-1 { color: #FFD700; }
.leaderboard-rank.rank-2 { color: #C0C0C0; }
.leaderboard-rank.rank-3 { color: #CD7F32; }

.leaderboard-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.12);
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.leaderboard-avatar.fallback {
  background: rgba(244, 211, 94, 0.2);
  color: var(--accent);
}

.leaderboard-info {
  flex: 1;
  min-width: 0;
}

.leaderboard-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leaderboard-balance {
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
}

.leaderboard-list .loading {
  text-align: center;
  color: rgba(255, 255, 255, 0.5);
  padding: 20px;
  font-size: 14px;
}

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--panel);
  padding: 28px;
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.auth-card h1 {
  margin: 12px 0 6px;
  font-family: "Unbounded", sans-serif;
}

.form {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.form input {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--panel-soft);
  color: var(--text);
}

.form button {
  padding: 12px 14px;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: #0a0d14;
  font-weight: 700;
  cursor: pointer;
}

.hint {
  margin-top: 12px;
  color: var(--muted);
  font-size: 14px;
}

.error {
  margin-top: 10px;
  color: #ff9f9f;
  min-height: 20px;
}

.lobby {
  max-width: 1400px;
  margin: 40px auto;
  padding: 0 30px;
  display: flex;
  gap: 30px;
}

.game-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}

@media (max-width: 968px) {
  .lobby {
    flex-direction: column;
  }
  
  .leaderboard-sidebar {
    width: 100%;
  }
  
  .leaderboard-card {
    position: static;
  }
  
  .leaderboard-list {
    max-height: 300px;
  }
}

.game-card {
  background: var(--panel);
  padding: 22px;
  border-radius: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow);
}

.game-card h2 {
  margin: 0 0 6px;
}

.game-card button,
.game-card a.primary {
  padding: 10px 16px;
  border-radius: 12px;
  border: none;
  background: var(--accent-3);
  color: #0a0d14;
  font-weight: 700;
  cursor: pointer;
}

.game-card.featured {
  border: 1px solid rgba(244, 211, 94, 0.4);
}

.panel {
  background: var(--panel);
  padding: 20px 24px;
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 14px;
  display: block;
  max-height: 720px;
  overflow: auto;
}

.table th,
.table td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.table thead,
.table tbody tr {
  display: table;
  width: 100%;
  table-layout: fixed;
}

.table tbody {
  display: block;
  width: 100%;
}

.table th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.table td.positive {
  color: #22c55e;
  font-weight: 600;
}

.table td.negative {
  color: #ef4444;
  font-weight: 600;
}

.input-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.input-row input,
.input-row select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--panel-soft);
  color: var(--text);
}

.input-row textarea {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--panel-soft);
  color: var(--text);
  font-family: inherit;
}

.input-row button {
  padding: 10px 14px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #0a0d14;
  font-weight: 700;
  cursor: pointer;
}

@media (max-width: 980px) {
  body {
    padding: 20px;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .game-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
}

.global-chat {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: min(320px, 90vw);
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
  z-index: 56;
}

.global-chat header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.06);
  font-weight: 600;
}

.global-chat .chat-body {
  max-height: 220px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 12px;
  display: grid;
  gap: 6px;
  font-size: 13px;
  scroll-behavior: smooth;
}

.global-chat .chat-input {
  display: flex;
  gap: 8px;
  padding: 10px 12px 12px;
}

.global-chat input {
  flex: 1;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--panel-soft);
  color: var(--text);
}

.global-chat button {
  padding: 8px 10px;
  border-radius: 10px;
  border: none;
  background: var(--accent-3);
  color: #0a0d14;
  font-weight: 700;
  cursor: pointer;
}

.global-chat.minimized {
  width: auto;
}

.global-chat.minimized .chat-body,
.global-chat.minimized .chat-input {
  display: none;
}

.toast-wrap {
  position: fixed;
  right: 20px;
  top: 20px;
  display: grid;
  gap: 8px;
  z-index: 60;
}

/* Toast Messages System */
.toast-container {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  min-width: 300px;
  padding: 16px 20px;
  background: var(--panel);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  gap: 12px;
  animation: slideIn 0.3s ease;
  border-left: 4px solid var(--accent);
  pointer-events: auto;
}

.toast.success {
  border-left-color: #22c55e;
}

.toast.error {
  border-left-color: #ef4444;
}

.toast.info {
  border-left-color: #3b82f6;
}

.toast-icon {
  font-size: 20px;
  flex-shrink: 0;
  font-weight: 700;
}

.toast-message {
  flex: 1;
  font-size: 14px;
  color: var(--text);
}

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

@keyframes toastIn {
  from {
    transform: translateY(-8px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.music-player {
  position: fixed;
  left: 20px;
  bottom: 20px;
  width: min(300px, 90vw);
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow);
  z-index: 55;
  overflow: hidden;
}

.music-player header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.06);
  font-weight: 600;
}

.music-player .controls {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
}

.music-player .timeline {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 10px;
  font-size: 12px;
  color: var(--muted);
}

.music-player input[type="range"] {
  flex: 1;
}

.music-player button {
  padding: 6px 10px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #0a0d14;
  font-weight: 700;
  cursor: pointer;
}

.music-player .list {
  max-height: 160px;
  overflow: auto;
  padding: 8px 12px 12px;
  font-size: 13px;
  display: grid;
  gap: 6px;
}

.music-player .list .active {
  color: var(--accent);
  font-weight: 600;
}

.music-player.minimized {
  width: auto;
}

.music-player.minimized .controls,
.music-player.minimized .timeline,
.music-player.minimized .list {
  display: none;
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(13, 15, 26, 0.8);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(4px);
}

.loading-overlay.active {
  display: flex;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(244, 211, 94, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

.loading-overlay .loading-text {
  color: var(--text);
  font-size: 14px;
  margin-top: 8px;
  opacity: 0.9;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Avatar Frame Animations */
.avatar-frame-animated {
  position: relative;
  animation: frameShimmer 3s ease-in-out infinite;
}

@keyframes frameShimmer {
  0%, 100% {
    filter: brightness(1) contrast(1);
  }
  50% {
    filter: brightness(1.15) contrast(1.1);
  }
}

/* Gems Shop Frame Animation - Glow Pulse Effect */
.avatar-frame-rotating {
  position: relative;
  animation: gemsGlowPulse 2.5s ease-in-out infinite;
}

@keyframes gemsGlowPulse {
  0%, 100% {
    filter: brightness(1) drop-shadow(0 0 2px rgba(255, 255, 255, 0.3));
  }
  50% {
    filter: brightness(1.3) drop-shadow(0 0 8px rgba(255, 255, 255, 0.8));
  }
}

/* Gems Shop Name Color Animation */
.name-color-gems-animated {
  animation: nameGlowPulse 2.5s ease-in-out infinite;
}

@keyframes nameGlowPulse {
  0%, 100% {
    filter: brightness(1) drop-shadow(0 0 1px currentColor);
  }
  50% {
    filter: brightness(1.4) drop-shadow(0 0 6px currentColor);
  }
}

/* Gems Shop Profile Frame Animation */
.profile-frame-gems-animated {
  animation: profileGlowPulse 2.5s ease-in-out infinite;
}

@keyframes profileGlowPulse {
  0%, 100% {
    filter: brightness(1);
    box-shadow: 0 0 0 rgba(255, 255, 255, 0);
  }
  50% {
    filter: brightness(1.2);
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
  }
}

/* Home Button */
.home-button {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  border: none;
  border-radius: 50%;
  box-shadow: 0 8px 24px rgba(244, 211, 94, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition: all 0.3s ease;
  z-index: 50;
  text-decoration: none;
  color: #0d0f1a;
}

.home-button:hover {
  transform: translateX(-50%) translateY(-4px);
  box-shadow: 0 12px 32px rgba(244, 211, 94, 0.6);
}

.home-button:active {
  transform: translateX(-50%) translateY(-2px);
}

/* Date input Vietnamese format */
input[type="date"],
input[type="datetime-local"] {
  position: relative;
}

input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  position: absolute;
  right: 8px;
  cursor: pointer;
}

input[type="date"]:before,
input[type="datetime-local"]:before {
  content: attr(data-placeholder);
  color: var(--muted);
  margin-right: 8px;
}

input[type="date"]:focus:before,
input[type="date"]:valid:before,
input[type="datetime-local"]:focus:before,
input[type="datetime-local"]:valid:before {
  content: "";
}

/* Verified badge styles */
.verified-badge {
  display: inline-block;
  margin-left: 4px;
  font-size: 0.9em;
  vertical-align: middle;
}

.user-name .verified-badge {
  font-size: 14px;
}

/* Name Glow Effects for Rarity (Topbar) */
.user-name.name-glow-legendary,
.name-glow-legendary {
  animation: name-glow-legendary-anim 2s infinite;
  filter: drop-shadow(0 0 6px rgba(255, 215, 0, 0.5));
}

@keyframes name-glow-legendary-anim {
  0%, 100% {
    filter: drop-shadow(0 0 6px rgba(255, 215, 0, 0.5)) drop-shadow(0 0 12px rgba(255, 107, 0, 0.3));
  }
  50% {
    filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.8)) drop-shadow(0 0 20px rgba(255, 107, 0, 0.5));
  }
}

.user-name.name-glow-epic,
.name-glow-epic {
  animation: name-glow-epic-anim 2.5s infinite;
  filter: drop-shadow(0 0 5px rgba(168, 85, 247, 0.4));
}

@keyframes name-glow-epic-anim {
  0%, 100% {
    filter: drop-shadow(0 0 5px rgba(168, 85, 247, 0.4)) drop-shadow(0 0 10px rgba(236, 72, 153, 0.3));
  }
  50% {
    filter: drop-shadow(0 0 8px rgba(168, 85, 247, 0.7)) drop-shadow(0 0 15px rgba(236, 72, 153, 0.5));
  }
}

.user-name.name-glow-rare,
.name-glow-rare {
  animation: name-glow-rare-anim 3s infinite;
  filter: drop-shadow(0 0 4px rgba(59, 130, 246, 0.4));
}

@keyframes name-glow-rare-anim {
  0%, 100% {
    filter: drop-shadow(0 0 4px rgba(59, 130, 246, 0.4)) drop-shadow(0 0 8px rgba(6, 182, 212, 0.3));
  }
  50% {
    filter: drop-shadow(0 0 6px rgba(59, 130, 246, 0.6)) drop-shadow(0 0 12px rgba(6, 182, 212, 0.5));
  }
}

/* Avatar Glow Effects for Rarity (Topbar & Small Avatars) */
.user-avatar.avatar-glow-legendary,
.avatar-glow-legendary {
  position: relative;
  animation: avatar-glow-legendary-anim 2s infinite;
}

.user-avatar.avatar-glow-legendary::after,
.avatar-glow-legendary::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ffd700, #ff6b00);
  z-index: -1;
  opacity: 0.4;
  filter: blur(8px);
  animation: avatar-pulse-blur-legendary 2s infinite;
}

@keyframes avatar-glow-legendary-anim {
  0%, 100% {
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.5), 0 0 25px rgba(255, 107, 0, 0.3);
  }
  50% {
    box-shadow: 0 0 25px rgba(255, 215, 0, 0.8), 0 0 40px rgba(255, 107, 0, 0.5);
  }
}

@keyframes avatar-pulse-blur-legendary {
  0%, 100% {
    opacity: 0.4;
    filter: blur(8px);
  }
  50% {
    opacity: 0.6;
    filter: blur(12px);
  }
}

.user-avatar.avatar-glow-epic,
.avatar-glow-epic {
  position: relative;
  animation: avatar-glow-epic-anim 2.5s infinite;
}

.user-avatar.avatar-glow-epic::after,
.avatar-glow-epic::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: linear-gradient(135deg, #a855f7, #ec4899);
  z-index: -1;
  opacity: 0.4;
  filter: blur(8px);
  animation: avatar-pulse-blur-epic 2.5s infinite;
}

@keyframes avatar-glow-epic-anim {
  0%, 100% {
    box-shadow: 0 0 12px rgba(168, 85, 247, 0.4), 0 0 20px rgba(236, 72, 153, 0.3);
  }
  50% {
    box-shadow: 0 0 18px rgba(168, 85, 247, 0.6), 0 0 30px rgba(236, 72, 153, 0.5);
  }
}

@keyframes avatar-pulse-blur-epic {
  0%, 100% {
    opacity: 0.4;
    filter: blur(8px);
  }
  50% {
    opacity: 0.6;
    filter: blur(11px);
  }
}

.user-avatar.avatar-glow-rare,
.avatar-glow-rare {
  position: relative;
  animation: avatar-glow-rare-anim 3s infinite;
}

.user-avatar.avatar-glow-rare::after,
.avatar-glow-rare::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #06b6d4);
  z-index: -1;
  opacity: 0.3;
  filter: blur(7px);
  animation: avatar-pulse-blur-rare 3s infinite;
}

@keyframes avatar-glow-rare-anim {
  0%, 100% {
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.4), 0 0 18px rgba(6, 182, 212, 0.3);
  }
  50% {
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.6), 0 0 25px rgba(6, 182, 212, 0.5);
  }
}

@keyframes avatar-pulse-blur-rare {
  0%, 100% {
    opacity: 0.3;
    filter: blur(7px);
  }
  50% {
    opacity: 0.5;
    filter: blur(10px);
  }
}
