/* Base Styles */
:root {
  --primary-color: #007aff;
  --text-color: #333;
  --bg-color: #f5f5f5;
  --card-bg: #fff;
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.15);
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 12px;
  --spacing-lg: 16px;
  --spacing-xl: 24px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-color);
  color: var(--text-color);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Layout */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--spacing-lg);
}

/* Navigation */
.nav {
  display: flex;
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-xl);
  justify-content: center;
  padding: var(--spacing-sm);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.nav::-webkit-scrollbar {
  display: none;
}

.nav-btn {
  padding: 10px 24px;
  border: none;
  border-radius: var(--radius-lg);
  background: var(--card-bg);
  color: var(--text-color);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}

.nav-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.nav-btn.active {
  background: var(--primary-color);
  color: white;
}


/* 搜索框样式 */
.search-container {
  margin: 20px 0;
  position: relative;
}

.search-input {
  width: 100%;
  padding: 12px 16px;
  font-size: 16px;
  border: 1px solid #ddd;
  border-radius: 8px;
  outline: none;
  transition: all 0.3s ease;
}

.search-input:focus {
  border-color: #4a90e2;
  box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.2);
}

.heart {
  position: relative;
  width: 20px;
  height: 14px;
}

.heart:before,
.heart:after {
  position: absolute;
  content: "";
  left: 10px;
  top: 0;
  width: 10px;
  height: 16px;
  background-color: #999;
  -moz-border-radius: 50px 50px 0 0;
  border-radius: 50px 50px 0 0;
  -webkit-transform: rotate(-45deg);
  -moz-transform: rotate(-45deg);
  -ms-transform: rotate(-45deg);
  -o-transform: rotate(-45deg);
  transform: rotate(-45deg);
  -webkit-transform-origin: 0 100%;
  -moz-transform-origin: 0 100%;
  -ms-transform-origin: 0 100%;
  -o-transform-origin: 0 100%;
  transform-origin: 0 100%;
}

.heart:after {
  left: 0;
  -webkit-transform: rotate(45deg);
  -moz-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  -o-transform: rotate(45deg);
  transform: rotate(45deg);
  -webkit-transform-origin: 100% 100%;
  -moz-transform-origin: 100% 100%;
  -ms-transform-origin: 100% 100%;
  -o-transform-origin: 100% 100%;
  transform-origin: 100% 100%;
}

.heart.active:before,
.heart.active:after {
  background-color: #ff3b30;
}

/* Game Grid */
.game-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(8, minmax(280px / 4 * 5, auto));
  /* 8行6列的布局 */
  gap: var(--spacing-lg);
  margin-bottom: var(--spacing-xl);
  /* 防止自动换行 */
  overflow: hidden;
}

.game-card {
  background: var(--card-bg);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  position: relative;
  display: flex;
}

.game-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
}

.game-card img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  background: #f0f0f0;
}

.game-info {
  padding: var(--spacing-lg);
  flex: 1;
  display: flex;
  flex-direction: column;
}

.game-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: var(--spacing-xs);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.game-meta {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: #666;
}

.favorite-btn {
  position: absolute;
  top: var(--spacing-md);
  right: var(--spacing-md);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #999;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-sm);
}

.favorite-btn:hover {
  transform: scale(1.1);
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--spacing-xl);
  margin-top: var(--spacing-xl);
}

.pagination button {
  padding: 10px 24px;
  border: none;
  border-radius: var(--radius-lg);
  background: var(--primary-color);
  color: white;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 100px;
}

.pagination button:disabled {
  background: #ccc;
  cursor: not-allowed;
}

#page-info {
  font-size: 15px;
  color: #666;
  min-width: 100px;
  text-align: center;
}

/* Game Screen Styles */
.game-header {
  position: fixed;
  top: 0;
  left: 10px;
  right: 10px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 102;
}

.header-center {
  flex-grow: 1;
  text-align: center;
  margin: 0 20px;
  opacity: 0.7;
  /* Make title visible but translucent */
}

.control-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  font-size: 16px;
  opacity: 1;
  /* Keep control buttons fully visible */
}

.control-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.05);
}

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

.control-btn.muted {
  color: #ff3b30;
}

.game-title {
  color: white;
  font-size: 16px;
  margin: 0;
  font-weight: 500;
}

.main {
  padding-top: 60px;
  background: #000;
  min-height: 100vh;
}

.screen {
  max-width: 100%;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  height: calc(100vh - 60px);
}

#emulator {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 101;
}

#emulator canvas {
  width: 100%;
  height: 100%;
}

/* Loading State */
.loading {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.loading::after {
  content: "";
  width: 40px;
  height: 40px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .container {
    padding: var(--spacing-md);
  }

  .game-card {
    aspect-ratio: 4/3;
    height: auto;
    /* 移除固定高度限制 */
  }

  .game-info {
    padding: var(--spacing-lg);
  }

  .game-title {
    font-size: 16px;
    /* 增大字体 */
  }

  .nav-btn {
    padding: 8px 20px;
    font-size: 14px;
  }

  .pagination {
    gap: var(--spacing-lg);
  }

  .pagination button {
    padding: 8px 20px;
    font-size: 14px;
    min-width: 80px;
  }

  #page-info {
    font-size: 14px;
    min-width: 80px;
  }
}

/* Safe Area Support */
@supports (padding: max(0px)) {
  .container {
    padding-left: max(var(--spacing-lg), env(safe-area-inset-left));
    padding-right: max(var(--spacing-lg), env(safe-area-inset-right));
    padding-bottom: max(var(--spacing-lg), env(safe-area-inset-bottom));
  }

  .controls {
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-color: #1c1c1e;
    --card-bg: #2c2c2e;
    --text-color: #fff;
  }

  .game-meta {
    color: #999;
  }

  .nav-btn {
    background: var(--card-bg);
    color: #fff;
  }

  .loading {
    background: rgba(0, 0, 0, 0.9);
  }
}

/* 移动端控制区域基础样式 */
.mobile-controls {
  width: 100%;
  display: block;
}

/* 通用按钮样式 */
.direction-button,
.system-button,
.action-button {
  width: 45px;
  height: 45px;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.6);
  color: rgba(255, 255, 255, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 通用按钮点击效果 */
.direction-button:active,
.system-button:active,
.action-button:active {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.8);
  transform: scale(0.95);
}

.up-button {
  grid-area: 1 / 2;
}

.down-button {
  grid-area: 3 / 2;
}

.left-button {
  grid-area: 2 / 1;
}

.right-button {
  grid-area: 2 / 3;
}

.direction-pad {
  display: grid;
  grid-template-columns: repeat(3, 45px);
  grid-template-rows: repeat(3, 45px);
  gap: 2px;
}

.action-button {
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: bold;
}

.system-button {
  min-width: 90px;
  height: 30px;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 20px;
  color: rgba(255, 255, 255, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

/* PC端隐藏虚拟按键 */
@media (min-width: 768px) {
  .mobile-controls {
    display: none;
  }
}

/* 移动端横屏样式 */
@media (max-width: 926px) and (orientation: landscape) {
  .game-grid {
    grid-template-columns: repeat(3, 1fr);
    /* 固定3列 */
    gap: var(--spacing-lg);
  }

  .landscape-controls {
    display: flex !important;
    position: fixed;
    bottom: 40px;
    left: 20px;
    right: 20px;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    z-index: 102;
  }

  /* 系统按钮容器样式 */
  .system-buttons {
    display: flex;
    gap: 15px;
    align-items: flex-start;
    margin-top: 200px;
  }

  /* 动作按钮容器样式 */
  .action-buttons {
    display: flex;
    gap: 15px;
  }

  /* B按钮位置调整 */
  .action-button[data-key="b"] {
    transform: translateY(20px);
  }

  #emulator {
    z-index: 102;
  }
}

/* 移动端竖屏样式 */
@media (max-width: 926px) and (orientation: portrait) {
  .game-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-lg);
  }

  .portrait-controls {
    position: absolute;
    bottom: 80px;
    left: 0;
    right: 0;
  }

  .portrait-controls {
    z-index: 102;
  }

  /* 系统按钮容器样式 */
  .system-buttons {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 20px;
    margin-top: 20px;
  }

  /* 控制器底部区域 */
  .controls-bottom {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
  }

  /* 动作按钮容器样式 */
  .action-buttons {
    display: flex;
    gap: 20px;
  }

  #emulator {
    align-items: flex-start;
  }

  #emulator canvas {
    width: 400px;
    height: 350px;
  }
}