/* ========== CSS 变量 ========== */
:root {
  --bg: #FFFFFF;
  --card-bg: #F0F0F0;
  --card-placeholder-bg: #ECECEC;
  --text: #000000;
  --accent: #333333;
  --border: #CCCCCC;
  --gap: 16px;
  --card-radius: 12px;
  --btn-size: 40px;
}

/* ========== 全局重置 ========== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ========== App 容器 ========== */
#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
}

/* ========== 主页标题 ========== */
#home-title {
  text-align: center;
  font-size: 28px;
  font-weight: bold;
  margin-bottom: 24px;
  user-select: none;
}

/* ========== 卡片网格 ========== */
.grid-container {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--gap);
  margin-bottom: 20px;
}

/* ========== 游戏卡片 ========== */
.game-card {
  aspect-ratio: 1 / 1;
  border-radius: var(--card-radius);
  cursor: pointer;
  transition: transform 0.15s ease;
  user-select: none;
  position: relative;
  perspective: 1000px;
  background: transparent;
}

.game-card:not(.flipped):hover {
  transform: scale(1.03);
}

.game-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.6s;
  transform-style: preserve-3d;
}

.game-card.flipped .game-card-inner {
  transform: rotateY(180deg);
}

.card-front,
.card-back {
  position: absolute;
  inset: 0;
  border-radius: var(--card-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  backface-visibility: hidden;
}

.card-back {
  background: #333;
  color: #fff;
  flex-direction: column;
  justify-content: flex-start;
  padding: 8px;
  gap: 6px;
  overflow-y: auto;
  transform: rotateY(180deg);
}

.diff-btn {
  width: 100%;
  border: none;
  border-radius: 8px;
  padding: 8px 4px;
  font-size: 10px;
  font-weight: bold;
  cursor: pointer;
  color: #111;
}

.game-card.placeholder {
  background-color: var(--card-placeholder-bg);
  border: 1px dashed var(--border);
  color: #AAAAAA;
  cursor: default;
}

.game-card.placeholder:hover {
  transform: none;
}

/* ========== 分页器 ========== */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
}

.page-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.page-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.page-btn:hover:not(.active) {
  background: #F5F5F5;
}

/* ========== 游戏容器 ========== */
#game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 50px;
  margin-bottom: 16px;
}

#game-title {
  font-size: 20px;
  font-weight: 600;
}

.icon-btn {
  width: var(--btn-size);
  height: var(--btn-size);
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
  line-height: 1;
}

.icon-btn:hover {
  background: #F5F5F5;
}

/* ========== 2048 模块样式 ========== */
.game-2048 {
  width: 100%;
}

.score-board {
  display: flex;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}

.score-item {
  flex: 1;
  background: var(--card-bg);
  border-radius: 8px;
  padding: 8px 12px;
  text-align: center;
}

.score-label {
  display: block;
  font-size: 12px;
  color: #888;
  margin-bottom: 4px;
}

.score-value {
  font-size: 24px;
  font-weight: bold;
}

.grid-2048 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 8px;
  background: #E8E8E8;
  border-radius: 12px;
  padding: 8px;
  margin-bottom: 12px;
}

.cell-2048 {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-weight: bold;
  transition: transform 0.1s ease-in-out, background-color 0.1s ease-in-out, color 0.1s ease-in-out;
  user-select: none;
}

.cell-2048.cell-spawn {
  animation: cellSpawn2048 0.12s ease-out;
}

@keyframes cellSpawn2048 {
  0% {
    transform: scale(0.6);
  }
  100% {
    transform: scale(1);
  }
}

.game-controls {
  text-align: center;
  margin-bottom: 8px;
}

.control-btn {
  padding: 8px 20px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: white;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.control-btn:hover {
  background: #F5F5F5;
}

.game-message {
  text-align: center;
  font-size: 18px;
  font-weight: bold;
  padding: 12px;
}

/* ========== 24 点模块样式 ========== */
.game-twentyfour {
  width: 100%;
}

.t24-stats {
  display: flex;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 8px;
}

.t24-stat-item {
  flex: 1;
  background: var(--card-bg);
  border-radius: 8px;
  padding: 8px;
  text-align: center;
}

.t24-stat-label {
  display: block;
  font-size: 12px;
  color: #888;
  margin-bottom: 4px;
}

.t24-stat-value {
  font-size: 20px;
  font-weight: bold;
}

.t24-zone-label {
  font-size: 13px;
  color: #666;
  margin-bottom: 8px;
  font-weight: 600;
}

.t24-card-area {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-bottom: 12px;
  min-height: 80px;
  padding: 16px;
  border-radius: 12px;
  border: 1px dashed var(--border);
}

.t24-card-area-original {
  background: #FAFAFA;
}

.t24-card-area-center {
  background: #F0F4F8;
  border-color: #B8C5D0;
}

.t24-card {
  width: 70px;
  height: 90px;
  background: white;
  border: 2px solid var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.t24-card:hover {
  border-color: #999;
}

.t24-card.selected {
  border: 2px dashed var(--accent);
  background: #F5F5F5;
}

.t24-card-derived {
  position: relative;
}

.t24-card-derived::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  opacity: 0.5;
}

.t24-card-derived:hover::after {
  opacity: 1;
}

.t24-operator-area {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 16px;
}

.t24-op-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: white;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.t24-op-btn:hover {
  background: #F5F5F5;
}

.t24-op-btn.selected {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.t24-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 8px;
}

.t24-actions .control-btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: white;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.t24-actions .control-btn:hover {
  background: #F5F5F5;
}

.t24-actions .control-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 24 点倒计时条 */
.t24-timer-bar {
  width: 100%;
  height: 8px;
  background: #eee;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 12px;
}

.t24-timer-fill {
  height: 100%;
  width: 100%;
  border-radius: 4px;
  background: #4caf50;
  transition: width 1s linear, background-color 0.3s ease;
}

/* 24 点结算弹窗 */
.t24-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.t24-modal {
  background: var(--bg);
  border-radius: 16px;
  padding: 20px;
  max-width: 320px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.t24-modal-title {
  font-size: 18px;
  margin-bottom: 12px;
  text-align: center;
}

.t24-modal-body {
  font-size: 14px;
  margin-bottom: 16px;
  text-align: center;
  color: #444;
}

.t24-modal-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
}

.t24-modal-btn {
  min-width: 100px;
}

.t24-modal-btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
/* ========== 2048 颜色设置面板 ========== */
.df2048-settings {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-top: 16px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.color-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  max-height: 200px;
  overflow-y: auto;
  margin-top: 12px;
}

.color-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}

.color-row input[type="color"] {
  border: none;
  width: 32px;
  height: 32px;
  cursor: pointer;
  background: none;
}

/* ========== 数阵脉冲 (Pulse) 样式 ========== */
.game-pulse {
  width: 100%;
}

.pulse-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 260px;
  margin: 0 auto;
  padding: 16px;
  background: #f0f0f0;
  border-radius: 12px;
}

.pulse-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: bold;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  user-select: none;
}

.pulse-cell:active {
  transform: scale(0.95);
}

/* 脉冲缩放动画 */
.pulse-cell.anim-pulse {
  animation: pulseEffect 0.15s ease-out;
}

@keyframes pulseEffect {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
  100% { transform: scale(1); }
}

/* ========== 数独游戏样式 ========== */
.sudoku-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  user-select: none;
}

.sudoku-stats {
  display: flex;
  justify-content: space-between;
  width: 100%;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.sudoku-stat {
  background: var(--card-bg);
  padding: 6px 12px;
  border-radius: 8px;
  text-align: center;
  flex: 1;
  min-width: 70px;
}

.sudoku-stat-label {
  font-size: 12px;
  color: #888;
}

.sudoku-stat-value {
  font-size: 18px;
  font-weight: bold;
}

.sudoku-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  background: #ccc;
  border: 2px solid #888;
  width: 100%;
  max-width: 450px;
  aspect-ratio: 1 / 1;
  margin-bottom: 16px;
}

.sudoku-cell {
  background: white;
  border: 1px solid #ddd;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.1s;
}

.sudoku-cell.prefilled {
  color: #2c3e50;
  font-weight: bold;
  background: #f9f9f9;
}

.sudoku-cell.user-number {
  color: #27ae60;
}

.sudoku-cell.selected {
  background: #e3f2fd;
  box-shadow: inset 0 0 0 2px #2196f3;
}

.sudoku-cell.conflict {
  background: #ffebee;
  color: #c62828;
}

.sudoku-number-pad {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-bottom: 16px;
}

.sudoku-number-btn {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: white;
  font-size: 20px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.1s;
}

.sudoku-number-btn:hover {
  background: #f0f0f0;
}

.sudoku-number-btn.special {
  background: #ffecb3;
}

.sudoku-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
}

.sudoku-actions .control-btn {
  padding: 8px 12px;
  font-size: 14px;
}

.sudoku-timer-bar {
  width: 100%;
  height: 6px;
  background: #eee;
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 12px;
}

.sudoku-timer-fill {
  height: 100%;
  width: 100%;
  background: #4caf50;
  transition: width 0.2s linear;
}

.sudoku-number-pad {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.sudoku-number-row {
  display: flex;
  gap: 10px;
}

.sudoku-number-btn {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: white;
  font-size: 20px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.1s;
}

.sudoku-number-btn:hover {
  background: #f0f0f0;
}

.sudoku-number-btn.special {
  background: #ffecb3;
}

/* ========== 数字华容道样式 ========== */
.game-huarongdao {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  user-select: none;
}

.hrd-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: 100%;
  margin-bottom: 16px;
}

.hrd-stat {
  background: var(--card-bg);
  border-radius: 8px;
  padding: 6px 4px;
  text-align: center;
}

.hrd-stat-label {
  display: block;
  font-size: 11px;
  color: #888;
}

.hrd-stat-value {
  display: block;
  font-size: 18px;
  font-weight: bold;
  color: var(--text);
}

.hrd-grid-container {
  display: grid;
  gap: 6px;
  width: 100%;
  max-width: 400px;
  aspect-ratio: 1 / 1;
  background: #E8E8E8;
  border-radius: 12px;
  padding: 8px;
  margin-bottom: 12px;
}

.hrd-cell {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: #fff;
  font-weight: bold;
  font-size: 28px;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 2px solid #ddd;
  box-shadow: 0 2px 4px rgba(0,0,0,0.06);
}

.hrd-cell:not(.hrd-cell-empty):hover {
  transform: scale(1.04);
  border-color: #aaa;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}

.hrd-cell:active:not(.hrd-cell-empty) {
  transform: scale(0.94);
}

.hrd-cell-empty {
  background: #E8E8E8 !important;
  border-color: #ddd !important;
  cursor: default;
  box-shadow: none !important;
}

.hrd-cell-empty:hover {
  transform: none !important;
}

.hrd-toast {
  text-align: center;
  font-size: 14px;
  color: #666;
  padding: 6px 12px;
  background: #f5f5f5;
  border-radius: 8px;
  margin: 4px 0 8px 0;
  min-height: 30px;
}

.hrd-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.hrd-actions .control-btn {
  padding: 8px 20px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: white;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.hrd-actions .control-btn:hover {
  background: #F5F5F5;
}

.hrd-goal-hint {
  text-align: center;
  font-size: 14px;
  color: #555;
  background: #f5f5f5;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid #ddd;
  width: 100%;
  max-width: 400px;
  margin-bottom: 8px;
}

/* 华容道弹窗（复用了 pulse/24 点风格，但独立命名避免冲突） */
.hrd-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.hrd-modal {
  background: var(--bg);
  border-radius: 16px;
  padding: 20px;
  max-width: 320px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.hrd-modal-title {
  font-size: 18px;
  margin-bottom: 12px;
  text-align: center;
}

.hrd-modal-body {
  font-size: 14px;
  margin-bottom: 16px;
  text-align: center;
  color: #444;
}

.hrd-modal-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
}

.hrd-modal-btn {
  min-width: 100px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: white;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.hrd-modal-btn:hover {
  background: #f5f5f5;
}

.hrd-modal-btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.hrd-modal-btn-primary:hover {
  background: #555;
}

/* 响应式调整 */
@media (max-width: 420px) {
  .hrd-stats {
    grid-template-columns: repeat(3, 1fr);
  }
  .hrd-stat-value {
    font-size: 15px;
  }
  .hrd-grid-container {
    padding: 6px;
    gap: 4px;
  }
  .hrd-cell {
    font-size: 20px;
    border-radius: 6px;
  }
}
/* ========== 数织 (Nonogram) 样式 ========== */
.game-nonogram {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  user-select: none;
}

.nono-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: 100%;
  margin-bottom: 12px;
}

.nono-stat {
  background: var(--card-bg);
  border-radius: 8px;
  padding: 4px 6px;
  text-align: center;
}

.nono-stat-label {
  display: block;
  font-size: 11px;
  color: #888;
}

.nono-stat-value {
  display: block;
  font-size: 16px;
  font-weight: bold;
}

.nono-grid-container {
  width: 100%;
  max-width: 480px;
  margin-bottom: 12px;
}

.nono-wrapper {
  display: grid;
  gap: 2px;
  width: 100%;
  aspect-ratio: 1 / 1;
}

.nono-corner {
  background: #f0f0f0;
  border-radius: 4px;
}

.nono-col-hints,
.nono-row-hints {
  display: grid;
  gap: 2px;
  background: #f0f0f0;
  padding: 2px;
}

.nono-col-hints {
  grid-auto-flow: column;
  justify-items: center;
}

.nono-row-hints {
  align-items: center;
  justify-items: end;
  padding-right: 4px;
}

.nono-hint-cell {
  font-weight: bold;
  color: #333;
  font-size: 14px;
  line-height: 1.2;
  text-align: center;
  white-space: pre-wrap;
  word-break: break-all;
  padding: 0 2px;
}

.nono-grid {
  display: grid;
  gap: 1px;
  background: #ccc;
  border: 2px solid #888;
  aspect-ratio: 1 / 1;
}

.nono-cell {
  background: white;
  cursor: pointer;
  transition: background 0.1s;
  border: 1px solid #ddd;
}

.nono-cell.nono-filled {
  background: #333;
  border-color: #555;
}

.nono-cell.nono-marked {
  background: #ffcdd2;
  position: relative;
}
.nono-cell.nono-marked::after {
  content: '✕';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 80%;
  font-weight: bold;
  color: #d32f2f;
}

.nono-cell.nono-win {
  border-color: #4CAF50;
  box-shadow: inset 0 0 0 2px #4CAF50;
}

.nono-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
}

.nono-controls .control-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: white;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}

.nono-controls .control-btn:hover {
  background: #f5f5f5;
}

.nono-controls .control-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.nono-legend {
  font-size: 12px;
  color: #666;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 4px;
}

/* 数织弹窗（复用样式） */
.nono-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.nono-modal {
  background: var(--bg);
  border-radius: 16px;
  padding: 20px;
  max-width: 320px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.nono-modal-title { font-size: 18px; margin-bottom: 12px; text-align: center; }
.nono-modal-body { font-size: 14px; margin-bottom: 16px; text-align: center; color: #444; }
.nono-modal-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px; }
.nono-modal-btn {
  min-width: 100px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: white;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}
.nono-modal-btn:hover { background: #f5f5f5; }
.nono-modal-btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.nono-modal-btn-primary:hover { background: #555; }

@media (max-width: 480px) {
  .nono-stats {
    grid-template-columns: repeat(3, 1fr);
  }
  .nono-stat-value { font-size: 14px; }
  .nono-hint-cell { font-size: 12px; }
}