/* ==============================================================
   2048 Game Hub — 主样式
   ============================================================== */

/* --- Hub 布局 --- */
.hub-body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--color-bg, #faf8ef);
  transition: background 0.5s ease;
  padding: 20px;
  overflow-x: hidden;
}

.hub-container {
  max-width: 900px;
  width: 100%;
  text-align: center;
  position: relative;
}

/* Hub 标题 */
.hub-title {
  font: var(--font-title, 700 48px/1 'Clear Sans', sans-serif);
  color: var(--color-text-dark, #776e65);
  margin-bottom: 6px;
  position: relative;
  display: inline-block;
  letter-spacing: -1px;
}

.hub-title::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 60%;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--color-primary, #8f7a66), transparent);
  border-radius: 2px;
}

.hub-subtitle {
  font-size: clamp(14px, 3vw, 18px);
  color: var(--color-text-dark, #776e65);
  opacity: 0.7;
  margin-bottom: 40px;
}

.hub-subtitle strong {
  color: var(--color-primary, #8f7a66);
  opacity: 1;
}

/* --- 游戏卡片网格 --- */
.hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 24px;
  margin-bottom: 40px;
}

/* --- 游戏卡片 --- */
.game-card {
  position: relative;
  background: var(--color-cell-bg, #cdc1b4);
  border-radius: var(--border-radius-lg, 12px);
  padding: 24px;
  cursor: pointer;
  transition: transform 0.35s var(--ease-spring),
              box-shadow 0.35s var(--ease-out-expo),
              background var(--transition-theme);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.game-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.15) 0%, transparent 50%);
  pointer-events: none;
}

@media (hover: hover) {
  .game-card:hover {
    transform: translateY(-6px) scale(1.02);
    box-shadow: none;
  }
}

.game-card:active {
  transform: translateY(-2px) scale(1.01);
}

/* 卡片预览区域 */
.game-card-preview {
  width: 100%;
  height: 140px;
  border-radius: var(--border-radius-md, 6px);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

/* 2048 预览 */
.game-card-preview.preview-2048 {
  background: linear-gradient(135deg, #faf8ef, #eee4da);
}

.preview-2048 .preview-tiles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  width: 100px;
}

.preview-2048 .preview-tile {
  width: 44px;
  height: 44px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
}

.preview-2048 .preview-tile-2 { background: #eee4da; color: #776e65; }
.preview-2048 .preview-tile-4 { background: #ede0c8; color: #776e65; }
.preview-2048 .preview-tile-8 { background: #f2b179; color: #f9f6f2; }
.preview-2048 .preview-tile-16 { background: #f59563; color: #f9f6f2; }
.preview-2048 .preview-tile-2048 { background: #edc22e; color: #f9f6f2; }

/* 泡泡龙预览 */
.game-card-preview.preview-bubble {
  background: linear-gradient(135deg, #faf8ef, #eee4da);
  max-width: 390px;
  width: 100%;
  height: 140px;
  margin-left: auto;
  margin-right: auto;
  border-radius: 6px;
}

.preview-bubbles {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 16px 0;
}

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

.preview-bubbles .row.offset {
  padding-left: 22px;
}

.preview-bubble {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  box-shadow: inset -2px -2px 4px rgba(0,0,0,0.15), inset 2px 2px 4px rgba(255,255,255,0.3);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.preview-bubble-l { background: #ff6b6b; }
.preview-bubble-g { background: #6bcb77; }
.preview-bubble-b { background: #4d96ff; }
.preview-bubble-y { background: #ffd93d; }
.preview-bubble-p { background: #ce93d8; }
.preview-bubble-o { background: #ffa726; }

.preview-bubbles-grid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.preview-bubbles-grid .row {
  display: flex;
  gap: 5px;
  justify-content: center;
}

.preview-bubbles-grid .row.offset {
  padding-left: 15px;
}

/* --- 恐龙跑酷预览 --- */
.game-card-preview.preview-trex {
  background: linear-gradient(135deg, #f3e8ff, #e8d5ff);
  max-width: 390px;
  width: 100%;
  height: 140px;
  margin-left: auto;
  margin-right: auto;
  border-radius: 6px;
  position: relative;
  overflow: hidden;
}

/* 预览史莱姆 */
.preview-slime-wrap {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 20px;
  width: 100%;
  height: 100%;
  padding: 20px 24px 16px;
}

.preview-slime {
  width: 32px;
  height: 30px;
  background: radial-gradient(ellipse at 35% 30%, #7eddc0, #4fc3a1 45%, #3a9e82);
  border-radius: 50% 50% 45% 45% / 55% 55% 40% 40%;
  position: relative;
  box-shadow: 0 2px 8px rgba(79,195,161,0.3);
  animation: previewSlimeBounce 1.5s ease-in-out infinite;
}

@keyframes previewSlimeBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.preview-slime-eye {
  position: absolute;
  width: 6px;
  height: 6px;
  background: #fff;
  border-radius: 50%;
  top: 8px;
}

.preview-slime-eye.left { left: 8px; }
.preview-slime-eye.right { left: 18px; }

.preview-slime-eye::after {
  content: '';
  position: absolute;
  top: 1px;
  left: 2px;
  width: 3px;
  height: 3px;
  background: #333;
  border-radius: 50%;
}

/* 预览水晶 */
.preview-crystal {
  width: 12px;
  height: 28px;
  background: linear-gradient(180deg, #e8d5ff, #b388ff);
  clip-path: polygon(50% 0%, 100% 20%, 100% 80%, 50% 100%, 0% 80%, 0% 20%);
  border-radius: 2px;
  box-shadow: 0 0 8px rgba(179,136,255,0.4);
  margin-bottom: 2px;
  animation: previewCrystalGlow 2s ease-in-out infinite alternate;
}

@keyframes previewCrystalGlow {
  0% { opacity: 0.6; transform: scaleY(0.95); }
  100% { opacity: 1; transform: scaleY(1.05); }
}

/* 卡片名称 */
.game-card-name {
  font-size: clamp(18px, 4vw, 22px);
  font-weight: 700;
  color: var(--color-text-dark, #776e65);
  margin-bottom: 4px;
}

.game-card-desc {
  font-size: clamp(12px, 2.5vw, 14px);
  color: var(--color-text-dark, #776e65);
  opacity: 0.6;
  margin-bottom: 12px;
  line-height: 1.4;
}

/* 卡片标签 */
.game-card-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.game-card-tag {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--color-primary, #8f7a66);
  color: var(--color-text-light, #f9f6f2);
  opacity: 0.85;
}

/* --- Hub 底部栏 --- */
.hub-footer {
  width: 100%;
  text-align: center;
  padding: 20px 0;
  font-size: 13px;
  color: var(--color-text-dark, #776e65);
  opacity: 0.5;
}

.hub-footer p {
  margin: 2px 0;
}

.hub-footer strong {
  color: var(--color-primary, #8f7a66);
  opacity: 0.8;
}

.hub-footer-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px;
  margin: 2px 0;
}

.hub-user-area {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.hub-user-sep {
  opacity: 0.3;
}

.hub-user-edit-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
  opacity: 0.5;
  color: inherit;
  transition: opacity 0.2s, transform 0.2s;
}
.hub-user-edit-btn:hover {
  opacity: 1;
  transform: scale(1.15);
}
@media (pointer: coarse) {
  .hub-user-edit-btn {
    min-width: 44px;
    min-height: 44px;
    font-size: 18px;
  }
}

.hub-footer-sep {
  opacity: 0.2;
}

#hub-user-name {
  font-weight: 600;
}
#hub-user-id {
  font-size: 11px;
  opacity: 0.5;
  font-family: monospace;
}

.hub-clear-btn {
  background: none;
  border: none;
  padding: 0 2px;
  font-size: inherit;
  font-family: inherit;
  color: inherit;
  opacity: 0.35;
  cursor: pointer;
  transition: opacity 0.2s, color 0.2s;
  white-space: nowrap;
}
.hub-clear-btn:hover {
  opacity: 0.8;
  color: var(--color-danger, #e74c3c);
}
.hub-clear-btn:active {
  opacity: 1;
}

/* --- 游戏嵌入容器 --- */
#game-embed {
  display: none;
  width: 100%;
  min-height: 100vh;
  position: relative;
}

#game-embed.active {
  display: block;
}

#game-frame {
  width: 100%;
  min-height: 100vh;
  border: none;
}

/* Hub 切换按钮（返回大厅） */
.btn-back-hub {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 2147483647;
  background: var(--color-primary, #8f7a66);
  color: var(--color-text-light, #f9f6f2);
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0,0,0,0.2);
  display: none;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s var(--ease-out-expo), box-shadow 0.2s var(--ease-out-expo);
  -webkit-tap-highlight-color: transparent;
}

.btn-back-hub.visible {
  display: flex;
  pointer-events: auto;
}

@media (hover: hover) {
  .btn-back-hub:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  }
}

.btn-back-hub:active {
  transform: scale(0.95);
}

.btn-back-hub.visible {
  display: flex;
  animation: backBtnAppear 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes backBtnAppear {
  from {
    transform: scale(0);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* --- 排行榜浮动入口（圆形图标按钮） --- */
.hub-leaderboard-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  background: linear-gradient(135deg, #f6d365, #fda085);
  color: #5a2d0a;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(253, 160, 133, 0.4);
  display: none;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.hub-leaderboard-btn.visible {
  display: flex;
  animation: backBtnAppear 0.3s var(--ease-spring) both;
}

@media (hover: hover) {
  .hub-leaderboard-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(253, 160, 133, 0.5);
  }
}

/* --- 背景粒子装饰（可选） --- */
.hub-particles {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.hub-particle {
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  opacity: 0.15;
  background: var(--color-primary, #8f7a66);
  animation: particleFloat linear infinite;
}

@keyframes particleFloat {
  0% {
    transform: translateY(100vh) rotate(0deg);
    opacity: 0;
  }
  10% {
    opacity: 0.15;
  }
  90% {
    opacity: 0.15;
  }
  100% {
    transform: translateY(-20vh) rotate(720deg);
    opacity: 0;
  }
}

/* --- 响应式 --- */
@media (max-width: 640px) {
  .hub-grid {
    grid-template-columns: 1fr;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
    gap: 16px;
  }

  .game-card-preview {
    height: 110px;
  }

  .hub-title {
    font-size: 32px;
  }

  .hub-subtitle {
    margin-bottom: 24px;
  }
}

/* 小屏适配 — 导航按钮缩小 */
@media (max-width: 520px) {
  .btn-back-hub {
    top: 10px;
    left: 10px;
    width: 36px;
    height: 36px;
    font-size: 16px;
    box-shadow: 0 1px 6px rgba(0,0,0,0.15);
  }

  .hub-leaderboard-btn {
    top: 10px;
    right: 10px;
    width: 38px;
    height: 38px;
    font-size: 17px;
    box-shadow: 0 1px 6px rgba(253, 160, 133, 0.3);
  }

  .hub-footer {
    font-size: 11px;
    padding: 12px 0;
  }
}

/* 极小屏适配 (< 380px) */
@media (max-width: 380px) {
  .hub-body {
    padding: 12px;
  }

  .hub-title {
    font-size: 26px;
  }

  .hub-subtitle {
    font-size: 12px;
    margin-bottom: 16px;
  }

  .game-card {
    padding: 16px;
  }

  .game-card-preview {
    height: 100px;
  }

  .game-card-tag {
    font-size: 10px;
    padding: 2px 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .game-card {
    transition: none;
  }
  .game-card:hover {
    transform: none;
  }
}

/* --- 昵称编辑模态框 --- */
.prompt-modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.55);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.prompt-modal-dialog {
  background: var(--color-bg, #faf8ef);
  border-radius: 14px;
  padding: 28px 24px 20px;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 12px 48px rgba(0,0,0,0.3);
  position: relative;
}

.prompt-modal-title {
  font: var(--font-subtitle, 700 16px/1.3 'Clear Sans', sans-serif);
  color: var(--color-text-dark, #776e65);
  margin-bottom: 16px;
  text-align: center;
}

.prompt-modal-input {
  display: block;
  width: 100%;
  padding: 10px 14px;
  font-size: 15px;
  font-family: inherit;
  border: 2px solid var(--color-border, #d6cdc4);
  border-radius: 10px;
  background: var(--color-input-bg, #fff);
  color: var(--color-text-dark, #776e65);
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.2s ease;
}
.prompt-modal-input:focus {
  border-color: var(--color-primary, #8f7a66);
}

.prompt-modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  justify-content: flex-end;
}

.prompt-modal-cancel,
.prompt-modal-confirm {
  min-width: 80px;
  padding: 8px 18px;
  font-size: 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.prompt-modal-cancel:active,
.prompt-modal-confirm:active {
  transform: scale(0.96);
}
