/* ===========================
   消消乐游戏样式
   =========================== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f0f1a;
  --bg2: #1a1a2e;
  --bg3: #16213e;
  --accent: #e94560;
  --accent-h: #c73652;
  --gold: #f0c040;
  --text: #eaeaea;
  --muted: #8892a4;
  --r-sm: 8px;
  --r-md: 16px;
  --r-lg: 24px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  --tr: 0.25s ease;
}

body {
  font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===========================
   顶部导航
   =========================== */
.game-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--bg2);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-back {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  transition: color var(--tr);
}

.nav-back:hover {
  color: var(--gold);
}

.nav-title {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 2px;
  background: linear-gradient(135deg, var(--gold), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ===========================
   大厅样式
   =========================== */
.lobby {
  min-height: calc(100vh - 64px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.lobby-card {
  background: var(--bg2);
  border-radius: var(--r-md);
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 32px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow);
}

.lobby-step {
  text-align: center;
  position: relative;
}

.lobby-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  display: block;
}

.lobby-title {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.lobby-desc {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 24px;
}

.mode-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}

.mode-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--bg3);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--r-sm);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: all var(--tr);
}

.mode-card:hover {
  background: rgba(240, 192, 64, 0.1);
  border-color: rgba(240, 192, 64, 0.25);
  transform: translateY(-2px);
}

/* 关卡选择网格 */
.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.level-card {
  padding: 16px;
  background: var(--bg3);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: all var(--tr);
  text-align: center;
}

.level-card:hover {
  background: rgba(240, 192, 64, 0.1);
  border-color: rgba(240, 192, 64, 0.25);
  transform: translateY(-2px);
}

.level-card.locked {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.level-card-num {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--gold);
  margin-bottom: 4px;
}

.level-card-name {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.level-card-desc {
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.level-card-badge {
  font-size: 0.7rem;
  color: var(--gold);
  font-weight: 600;
}

.level-card-score {
  font-size: 0.7rem;
  color: var(--muted);
}

.lock-icon {
  font-size: 1.2rem;
}

.mode-emoji {
  font-size: 1.5rem;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: var(--r-sm);
  flex-shrink: 0;
}

.mode-name {
  font-weight: 700;
  font-size: 0.95rem;
  flex: 1;
}

.mode-desc {
  color: var(--muted);
  font-size: 0.75rem;
  flex-shrink: 0;
}

.back-btn {
  position: absolute;
  top: 16px;
  left: 16px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: color var(--tr);
}

.back-btn:hover {
  color: var(--gold);
}

/* ===========================
   游戏主界面
   =========================== */
.app {
  min-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  padding: 24px;
}

.header {
  text-align: center;
  margin-bottom: 24px;
}

.title {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.subtitle {
  color: var(--muted);
  font-size: 0.9rem;
}

.main {
  display: flex;
  gap: 24px;
  flex: 1;
  min-height: 0;
}

.board-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

.game-info {
  display: flex;
  gap: 24px;
  margin-bottom: 16px;
  padding: 12px 24px;
  background: var(--bg2);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow);
}

.score-box,
.target-box,
.time-box {
  display: flex;
  align-items: center;
  gap: 8px;
}

.score-label,
.target-label,
.time-label {
  color: var(--muted);
  font-size: 0.9rem;
}

.score-value,
.target-value,
.time-value {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--gold);
}

.game-board {
  display: grid;
  grid-template-columns: repeat(8, 60px);
  grid-template-rows: repeat(8, 60px);
  gap: 4px;
  background: var(--bg2);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--r-sm);
  padding: 12px;
  box-shadow: var(--shadow);
}

.game-board .tile {
  width: 60px;
  height: 60px;
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  cursor: pointer;
  transition: all var(--tr);
  border: 2px solid transparent;
}

.game-board .tile:hover {
  transform: scale(1.05);
  border-color: var(--gold);
}

.game-board .tile.selected {
  border-color: var(--gold);
  background: rgba(240, 192, 64, 0.2);
}

.game-board .tile.matching {
  animation: match 0.5s ease;
}

@keyframes match {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); opacity: 0.7; }
  100% { transform: scale(0); opacity: 0; }
}

/* 不同颜色的方块 */
.tile.color-1 { background: #e94560; }
.tile.color-2 { background: #0f3460; }
.tile.color-3 { background: #16213e; }
.tile.color-4 { background: #f0c040; }
.tile.color-5 { background: #c73652; }
.tile.color-6 { background: #8b1a1a; }

.panel {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--bg2);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--r-md);
  padding: 20px;
  box-shadow: var(--shadow);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg3);
  border-radius: var(--r-sm);
}

.status-icon {
  font-size: 1.5rem;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: var(--r-sm);
  flex-shrink: 0;
}

#statusText {
  font-weight: 600;
  flex: 1;
}

.btn-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn {
  padding: 10px 16px;
  border: none;
  border-radius: var(--r-sm);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--tr);
  text-align: center;
}

.btn-primary {
  background: linear-gradient(135deg, var(--gold), #e6a800);
  color: var(--bg);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(240, 192, 64, 0.3);
}

.btn-secondary {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.1);
}

.game-info-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.info-title {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--muted);
}

.info-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  padding-right: 4px;
}

.info-list li {
  padding: 6px 8px;
  background: var(--bg3);
  border-radius: var(--r-sm);
  margin-bottom: 4px;
  font-size: 0.8rem;
  line-height: 1.4;
}

.info-list li:nth-child(odd) {
  background: rgba(255, 255, 255, 0.03);
}

/* 滚动条样式 */
.info-list::-webkit-scrollbar {
  width: 4px;
}

.info-list::-webkit-scrollbar-track {
  background: var(--bg);
  border-radius: 2px;
}

.info-list::-webkit-scrollbar-thumb {
  background: var(--muted);
  border-radius: 2px;
}

.info-list::-webkit-scrollbar-thumb:hover {
  background: var(--gold);
}

/* ===========================
   胜利弹窗
   =========================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--tr);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg2);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--r-md);
  padding: 32px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow);
  transform: translateY(20px);
  transition: transform var(--tr);
}

.modal-overlay.active .modal {
  transform: translateY(0);
}

.modal-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  display: block;
}

.modal-title {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.modal-desc {
  color: var(--muted);
  font-size: 1rem;
  margin-bottom: 24px;
}

.modal-btn-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ===========================
   页面入场遮罩
   =========================== */
.page-enter-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 99999;
  transition: opacity 0.5s ease, visibility 0.5s ease;
  opacity: 1;
  visibility: visible;
}

.page-enter-overlay.fade-out {
  opacity: 0;
  visibility: hidden;
}

/* ===========================
   响应式
   =========================== */
@media (max-width: 768px) {
  .main {
    flex-direction: column;
  }

  .panel {
    width: 100%;
    order: -1;
  }

  .game-board {
    grid-template-columns: repeat(8, 40px);
    grid-template-rows: repeat(8, 40px);
  }

  .game-board .tile {
    width: 40px;
    height: 40px;
    font-size: 1rem;
  }

  .game-info {
    flex-wrap: wrap;
    justify-content: center;
  }

  .lobby-card {
    padding: 24px;
  }

  .app {
    padding: 16px;
  }
}

@media (max-width: 480px) {
  .lobby-card {
    padding: 20px;
  }

  .mode-card {
    flex-direction: column;
    text-align: center;
    padding: 12px;
  }

  .mode-emoji {
    margin-bottom: 8px;
  }

  .app {
    padding: 12px;
    padding-top: 60px;
  }

  .title {
    font-size: 1.3rem;
  }

  .game-info {
    gap: 12px;
    padding: 8px 12px;
    font-size: .82rem;
  }

  .game-board {
    grid-template-columns: repeat(8, calc((100vw - 64px) / 8));
    grid-template-rows: repeat(8, calc((100vw - 64px) / 8));
    padding: 8px;
    gap: 3px;
  }

  .game-board .tile {
    width: 100%;
    height: 100%;
    font-size: .9rem;
  }

  .btn-group {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .btn-group .btn {
    flex: 1;
    min-width: 0;
    font-size: .82rem;
    padding: 8px 6px;
  }

  .level-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .modal {
    padding: 24px 20px;
  }

  .modal-title {
    font-size: 1.3rem;
  }
}