:root {
  --bg-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1920 1080"><defs><linearGradient id="grad" x1="0%" y1="0%" x2="100%" y2="100%"><stop offset="0%" style="stop-color:%23f0f2f5;stop-opacity:1" /><stop offset="100%" style="stop-color:%23ffffff;stop-opacity:1" /></linearGradient></defs><rect width="1920" height="1080" fill="url(%23grad)"/></svg>');
  --primary-color: #3b82f6;
  --primary-hover: #2563eb;
  --bg-color: #f8fafc;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --card-bg: rgba(255, 255, 255, 0.9);
  --border-radius: 16px;
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: var(--bg-image) center/cover no-repeat fixed;
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Prevent bounce effect on mobile */
  overscroll-behavior-y: none;
}

.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  padding-top: var(--safe-area-top);
  padding-bottom: var(--safe-area-bottom);
  padding-left: var(--safe-area-left);
  padding-right: var(--safe-area-right);
}

/* 主页容器 */
.homepage {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  transition: transform 0.3s ease;
}

.homepage.with-game {
  transform: translateY(-50%);
}

/* 用户信息卡片 */
.user-card {
  background: var(--card-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: var(--border-radius);
  padding: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.5);
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-avatar {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.user-name {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
}

.user-uid {
  font-size: 12px;
  color: var(--text-secondary);
}

.user-balance {
  font-size: 15px;
  font-weight: 600;
  color: #10b981;
  display: flex;
  align-items: center;
  gap: 4px;
}

.user-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(59, 130, 246, 0.1);
  color: var(--primary-color);
  font-size: 11px;
  font-weight: 600;
  border: 1px solid rgba(59, 130, 246, 0.2);
}

/* 游戏分类标签 */
.category-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Firefox */
  position: relative;
}

.category-tabs::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.category-tab {
  padding: 8px 16px;
  border: none;
  border-radius: 20px;
  background: var(--card-bg);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  position: relative;
  z-index: 1;
}

.category-tab.active {
  background: var(--primary-color);
  color: #fff;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
  transform: scale(1.05);
}

/* 游戏列表 - 优化图标布局 */
.game-list-container {
  position: relative;
  width: 100%;
  overflow: hidden;
  min-height: 200px; /* 防止内容替换时高度坍塌 */
}

.game-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)); /* 关键：使用 minmax(0, 1fr) 确保列宽严格一致 */
  gap: 12px;
  padding-bottom: 20px;
  width: 100%;
  transition: transform 0.5s cubic-bezier(0.23, 1, 0.32, 1), opacity 0.5s cubic-bezier(0.23, 1, 0.32, 1);
  will-change: transform, opacity;
}

/* 离开时的列表 */
.game-list.leaving {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 1;
}

.game-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  width: 100%;
  min-width: 0; /* 防止内容撑开网格 */
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.game-item:active {
  transform: scale(0.9);
}

.game-item.clicked {
  transform: scale(0.85);
  opacity: 0.7;
}

.game-icon-container {
  width: 100%;
  position: relative;
  padding-top: 100%; /* 强制正方形比例，即使图片没加载或宽高不同 */
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  background: #fff;
}

.game-icon {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover; /* 确保图标填满容器且不变形 */
  transition: transform 0.3s;
}

.game-item:hover .game-icon {
  transform: scale(1.05);
}

.game-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 游戏加载遮罩 */
.game-loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.5s ease, visibility 0.5s;
  visibility: hidden;
  opacity: 0;
}

.game-loading-overlay.show {
  visibility: visible;
  opacity: 1;
}

.loader {
  width: 48px;
  height: 48px;
  border: 5px solid #fff;
  border-bottom-color: var(--primary-color);
  border-radius: 50%;
  display: inline-block;
  box-sizing: border-box;
  animation: rotation 0.5s linear infinite;
  margin-bottom: 16px;
}

@keyframes rotation {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.loading-text {
  color: #fff;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
}

.loading-dots::after {
  content: '.';
  display: inline-block;
  animation: loading-dots 0.6s infinite steps(4);
  width: 1.5em;
  text-align: left;
}

@keyframes loading-dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

/* 维护中提醒样式 */
.maintenance-notice {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #000; /* 与加载遮罩统一 */
  padding: 30px;
  text-align: center;
  color: #fff; /* 与加载遮罩统一 */
}

.maintenance-notice-icon {
  width: 48px;
  height: 48px;
  border: 5px solid rgba(255, 255, 255, 0.2);
  border-bottom-color: var(--primary-color);
  border-radius: 50%;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.maintenance-notice-title {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 12px;
  letter-spacing: 1px;
}

.maintenance-notice-msg {
  font-size: 14px;
  line-height: 1.6;
  max-width: 280px;
  color: rgba(255, 255, 255, 0.8);
}

/* 响应式调整 */
@media (min-width: 480px) {
  .game-list {
    grid-template-columns: repeat(5, 1fr);
  }
}

@media (min-width: 768px) {
  .game-list {
    grid-template-columns: repeat(8, 1fr);
  }
}

/* 保持原有弹窗等逻辑，但优化视觉 */

/* 主页背景覆盖层 */
.homepage-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: url('./bk.png');
  background-size: cover;
  background-position: top center;
  background-repeat: no-repeat;
  z-index: 997;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  pointer-events: none;
}

.homepage-overlay.show {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

/* 遮罩层 */
.game-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: transparent;
  z-index: 998;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  pointer-events: none;
}

.game-overlay.show {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

/* 游戏 iframe 容器（浮动显示） */
.game-container {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  transform: translateY(100%) scale(0.95);
  background: #000;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  z-index: 999;
  transition: transform 0.4s cubic-bezier(0.4, 0, 1, 1), opacity 0.3s ease-in, visibility 0.4s;
  width: 100vw;
  overflow: hidden;
  padding-bottom: var(--safe-area-bottom);
  visibility: hidden;
  pointer-events: none;
  opacity: 0;
}

.game-container.show {
  visibility: visible;
  opacity: 1;
  transform: translateY(0) scale(1);
  transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease-out;
  pointer-events: auto;
}

.game-iframe-wrapper {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

.game-close-button {
  position: fixed;
  top: calc(var(--safe-area-top) + 16px);
  right: calc(var(--safe-area-right) + 16px);
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  border-radius: 50%;
  cursor: pointer;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 99999; /* 提高到极高层级，确保在全屏模式下依然在最顶层 */
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0;
  visibility: hidden;
  transform: scale(0.5) rotate(-90deg);
  pointer-events: none;
  margin: 0;
  padding: 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  user-select: none;
  -webkit-user-select: none;
}

.game-close-button.show {
  visibility: visible;
  opacity: 1;
  transform: scale(1) rotate(0deg);
  pointer-events: auto;
}

.game-iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #000;
  display: block;
}

/* 加载状态 */
.loading {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* 通用弹窗样式优化 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
  padding: 20px;
}

.modal-overlay.show {
  display: flex;
  opacity: 1;
}

.modal-content {
  background: #fff;
  border-radius: 24px;
  padding: 24px;
  width: 100%;
  max-width: 320px;
  transform: scale(0.9);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.modal-overlay.show .modal-content {
  transform: scale(1);
}

/* 适配原有的类名 */
.confirm-modal-overlay, .recharge-modal-overlay, .recharge-result-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
  padding: 20px;
}

.confirm-modal-overlay.show, .recharge-modal-overlay.show, .recharge-result-modal-overlay.show {
  display: flex;
  opacity: 1;
}

.confirm-modal, .recharge-modal, .recharge-result-modal {
  background: #fff;
  border-radius: 24px;
  padding: 24px;
  width: 100%;
  max-width: 320px;
  transform: scale(0.9);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  text-align: center;
}

.confirm-modal-overlay.show .confirm-modal, 
.recharge-modal-overlay.show .recharge-modal,
.recharge-result-modal-overlay.show .recharge-result-modal {
  transform: scale(1);
}

.confirm-modal-title, .recharge-modal-title, .recharge-result-modal-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.confirm-modal-message, .recharge-result-modal-message {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 24px;
}

.confirm-modal-actions, .recharge-modal-actions, .recharge-result-modal-actions {
  display: flex;
  gap: 12px;
}

.confirm-modal-button, .recharge-modal-button, .recharge-result-modal-button {
  flex: 1;
  height: 44px;
  border-radius: 22px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.confirm-modal-button-cancel, .recharge-modal-button-cancel {
  background: #f1f5f9;
  color: var(--text-secondary);
}

.confirm-modal-button-confirm, .recharge-modal-button-confirm, .recharge-result-modal-button {
  background: var(--primary-color);
  color: #fff;
}

.recharge-modal-input {
  width: 100%;
  height: 48px;
  border-radius: 12px;
  border: 2px solid #e2e8f0;
  padding: 0 16px;
  font-size: 16px;
  margin-bottom: 16px;
  outline: none;
  transition: border-color 0.2s;
}

.recharge-modal-input:focus {
  border-color: var(--primary-color);
}

.recharge-modal-error {
  color: #ef4444;
  font-size: 12px;
  margin-top: -12px;
  margin-bottom: 12px;
  display: none;
}

.recharge-modal-error.show {
  display: block;
}

