/**
 * @file        main.css
 * @module      UI / Styles
 * @role        Developer
 * @session     2026-06-13
 * @dependency  UI-2048组件规范-v1.0.md
 * @description 2048 游戏主样式：布局、主题系统、方块色板、组件样式
 * @handoff     CSS 变量由 UI Designer 定义，开发者实现
 */

/* ==============================================================
   0. CSS 变量 — Classic 主题 (默认)
   ============================================================== */
:root {
  /* 背景 */
  --color-bg:            #faf8ef;
  --color-grid-bg:       #bbada0;
  --color-cell-bg:       #cdc1b4;

  /* 文字 */
  --color-text-dark:     #776e65;
  --color-text-light:    #f9f6f2;
  --color-text-score:    #776e65;

  /* 交互 */
  --color-primary:       #8f7a66;
  --color-secondary:     #bbada0;
  --color-danger:        #f65e3b;
  --color-success:       #6abf69;

  /* 遮罩 */
  --color-overlay:       rgba(238, 228, 218, 0.73);

  /* 字体 — 优化字体栈 + 响应式字号 */
  --font-family:         'Clear Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI',
                          'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif;
  --font-title:          700 clamp(32px, 10vw, 52px)/1 var(--font-family);
  --font-score-label:    400 clamp(11px, 2.5vw, 14px)/1 var(--font-family);
  --font-score-value:    700 clamp(18px, 5vw, 28px)/1 var(--font-family);
  --font-tile:           700 clamp(24px, 6vw, 52px)/1 var(--font-family);
  --font-button:         700 clamp(13px, 3vw, 18px)/1 var(--font-family);
  --font-settings-title: 700 20px/1 var(--font-family);
  --font-danmaku:        700 clamp(16px, 3vw, 22px)/1 'Microsoft YaHei', 'PingFang SC', sans-serif;

  /* 间距 */
  --spacing-xs:  4px;
  --spacing-sm:  8px;
  --spacing-md:  12px;
  --spacing-lg:  20px;
  --spacing-xl:  32px;

  /* 圆角 */
  --border-radius-sm: 3px;
  --border-radius-md: 6px;
  --border-radius-lg: 12px;

  /* 动画 */
  --transition-fast: 0.15s ease;
}

/* 暗黑主题 — FIX: 优化色板阶梯（深蓝→紫红渐变，区分度更好） */
[data-theme="dark"] {
  --color-bg:            #1a1a2e;
  --color-grid-bg:       #16213e;
  --color-cell-bg:       #0f3460;
  --color-text-dark:     #e0e0e0;
  --color-text-light:    #ffffff;
  --color-text-score:    #e0e0e0;
  --color-primary:       #e94560;
  --color-secondary:     #0f3460;
  --color-overlay:       rgba(26, 26, 46, 0.85);
}

/* 霓虹主题 — FIX: 改善文字对比度（白色文字+绿色发光） */
[data-theme="neon"] {
  --color-bg:            #0a0a1a;
  --color-grid-bg:       #1a1a3e;
  --color-cell-bg:       #2a2a5e;
  --color-text-dark:     #ffffff;
  --color-text-light:    #ffffff;
  --color-text-score:    #00ff88;
  --color-primary:       #ff00ff;
  --color-secondary:     #2a2a5e;
  --color-overlay:       rgba(10, 10, 26, 0.85);
}

/* 粉彩主题 (NEW) */
[data-theme="pastel"] {
  --color-bg:            #fef6fb;
  --color-grid-bg:       #e8d5e0;
  --color-cell-bg:       #f3e5f5;
  --color-text-dark:     #4a3040;
  --color-text-light:    #ffffff;
  --color-text-score:    #4a3040;
  --color-primary:       #ce93d8;
  --color-secondary:     #e8d5e0;
  --color-overlay:       rgba(238, 228, 218, 0.73);
}

/* 森林主题 (NEW) */
[data-theme="forest"] {
  --color-bg:            #e8f5e9;
  --color-grid-bg:       #a5d6a7;
  --color-cell-bg:       #c8e6c9;
  --color-text-dark:     #1b5e20;
  --color-text-light:    #ffffff;
  --color-text-score:    #1b5e20;
  --color-primary:       #66bb6a;
  --color-secondary:     #a5d6a7;
  --color-overlay:       rgba(232, 245, 233, 0.8);
}

/* 海洋主题 (NEW) */
[data-theme="ocean"] {
  --color-bg:            #e1f5fe;
  --color-grid-bg:       #81d4fa;
  --color-cell-bg:       #b3e5fc;
  --color-text-dark:     #01579b;
  --color-text-light:    #ffffff;
  --color-text-score:    #01579b;
  --color-primary:       #0288d1;
  --color-secondary:     #81d4fa;
  --color-overlay:       rgba(225, 245, 254, 0.8);
}

/* ==============================================================
   1. 基础重置与布局
   ============================================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
}

body {
  font-family: var(--font-family);
  background: var(--color-bg);
  color: var(--color-text-dark);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: var(--spacing-lg);
  max-width: 540px;
  margin: 0 auto;
  position: relative;
}

/* ==============================================================
   2. 头部
   ============================================================== */
.game-header {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-md);
}

.title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.game-title {
  font: var(--font-title);
  color: var(--color-text-dark);
  line-height: 1;
}

.score-board {
  display: flex;
  gap: var(--spacing-sm);
}

.score-box {
  background: var(--color-cell-bg);
  border-radius: var(--border-radius-md);
  padding: var(--spacing-xs) var(--spacing-lg);
  text-align: center;
  min-width: 80px;
}

.score-label {
  font: var(--font-score-label);
  color: var(--color-text-light);
  text-transform: uppercase;
  display: block;
}

.score-value {
  font: var(--font-score-value);
  color: var(--color-text-light);
  display: block;
}

.action-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.game-subtitle {
  font-size: 14px;
  color: var(--color-text-dark);
  opacity: 0.7;
}

.action-buttons {
  display: flex;
  gap: var(--spacing-sm);
}

/* ==============================================================
   3. 按钮
   ============================================================== */
.btn {
  border: none;
  border-radius: var(--border-radius-md);
  padding: 8px 16px;
  font: 700 14px/1 var(--font-family);
  cursor: pointer;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  outline: none;
}

.btn:hover {
  opacity: 0.9;
}

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

.btn-primary {
  background: var(--color-primary);
  color: var(--color-text-light);
}

.btn-secondary {
  background: var(--color-secondary);
  color: var(--color-text-light);
}

.btn-large {
  padding: 12px 32px;
  font-size: 18px;
}

/* ==============================================================
   4. 网格
   ============================================================== */
#grid-wrapper {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
}

#grid-container {
  position: relative;
  background: var(--color-grid-bg);
  border-radius: var(--border-radius-md);
  padding: 0;
}

#tile-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.grid-cell {
  position: absolute;
  background: var(--color-cell-bg);
  border-radius: var(--border-radius-sm);
}

/* ==============================================================
   5. 方块
   ============================================================== */
.tile {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--border-radius-sm);
  transition: none; /* GSAP 控制动画 */
  z-index: 3;
  will-change: transform, opacity;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
}

.tile-2048,
.tile-4096,
.tile-8192,
.tile-super {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12), 0 2px 4px rgba(0, 0, 0, 0.08);
}

.tile-text {
  font: var(--font-tile);
  color: var(--color-text-dark);
  text-align: center;
  line-height: 1;
  pointer-events: none;
}

/* 各值方块颜色 */
.tile-2     { background: #eee4da; }
.tile-4     { background: #ede0c8; }
.tile-8     { background: #f2b179; }
.tile-16    { background: #f59563; }
.tile-32    { background: #f67c5f; }
.tile-64    { background: #f65e3b; }
.tile-128   { background: #edcf72; }
.tile-256   { background: #edcc61; }
.tile-512   { background: #edc850; }
.tile-1024  { background: #edc53f; }
.tile-2048  { background: #edc22e; }
.tile-4096  { background: #3c3a32; }
.tile-8192  { background: #3c3a32; }
.tile-super { background: #1a1a1a; }

.tile-8 .tile-text,
.tile-16 .tile-text,
.tile-32 .tile-text,
.tile-64 .tile-text {
  color: var(--color-text-light);
}

.tile-128 .tile-text,
.tile-256 .tile-text,
.tile-512 .tile-text,
.tile-1024 .tile-text,
.tile-2048 .tile-text {
  color: var(--color-text-light);
}

.tile-4096 .tile-text,
.tile-8192 .tile-text,
.tile-super .tile-text {
  color: var(--color-text-light);
}

/* 合成粒子 */
.merge-particle {
  position: absolute;
  pointer-events: none;
  border-radius: 50%;
  z-index: 10;
  will-change: transform, opacity;
}

/* 暗黑主题方块适配 — FIX: 更好的颜色阶梯 */
[data-theme="dark"] .tile-2     { background: #1a1a3e; color: #e0e0e0; }
[data-theme="dark"] .tile-4     { background: #1a2a5e; color: #e0e0e0; }
[data-theme="dark"] .tile-8     { background: #2a3a7e; color: #ffffff; }
[data-theme="dark"] .tile-16    { background: #3a4a9e; color: #ffffff; }
[data-theme="dark"] .tile-32    { background: #4a3a8e; color: #ffffff; }
[data-theme="dark"] .tile-64    { background: #5a2a7e; color: #ffffff; }
[data-theme="dark"] .tile-128   { background: #6a2a6e; color: #ffffff; }
[data-theme="dark"] .tile-256   { background: #8a2a5e; color: #ffffff; }
[data-theme="dark"] .tile-512   { background: #aa2a4e; color: #ffffff; }
[data-theme="dark"] .tile-1024  { background: #ca2a3e; color: #ffffff; }
[data-theme="dark"] .tile-2048  { background: #e94560; color: #ffffff; text-shadow: 0 0 8px rgba(233,69,96,0.5); }
[data-theme="dark"] .tile-4096  { background: #1a0a2e; color: #ffffff; }
[data-theme="dark"] .tile-8192  { background: #0a0520; color: #ffffff; }
[data-theme="dark"] .tile-super { background: #050515; color: #ffffff; }

/* 霓虹主题方块适配 — FIX: 白色文字+发光效果，提升可读性 */
[data-theme="neon"] .tile   { border: 1px solid rgba(0, 255, 136, 0.4); }
[data-theme="neon"] .tile-2     { background: #0a2a1a; color: #ffffff; }
[data-theme="neon"] .tile-4     { background: #0a3a2a; color: #ffffff; }
[data-theme="neon"] .tile-8     { background: #0a4a3a; color: #ffffff; }
[data-theme="neon"] .tile-16    { background: #0a5a4a; color: #ffffff; }
[data-theme="neon"] .tile-32    { background: #0a6a5a; color: #ffffff; }
[data-theme="neon"] .tile-64    { background: #0a7a6a; color: #ffffff; }
[data-theme="neon"] .tile-128   { background: #0a8a7a; color: #ffffff; }
[data-theme="neon"] .tile-256   { background: #0a9a8a; color: #ffffff; }
[data-theme="neon"] .tile-512   { background: #0aaa9a; color: #ffffff; }
[data-theme="neon"] .tile-1024  { background: #0aba9a; color: #ffffff; }
[data-theme="neon"] .tile-2048  { background: #00ff88; color: #0a0a1a; text-shadow: none; box-shadow: 0 0 24px #00ff88; }
[data-theme="neon"] .tile-4096  { background: #00cc77; color: #ffffff; }
[data-theme="neon"] .tile-8192  { background: #009955; color: #ffffff; }
[data-theme="neon"] .tile-super { background: #006633; color: #ffffff; }

[data-theme="neon"] .tile-text {
  color: #ffffff;
  text-shadow: 0 0 12px rgba(0, 255, 136, 0.6);
}

/* 粉彩主题方块适配 (NEW) */
[data-theme="pastel"] .tile-2     { background: #fce4ec; color: #4a3040; }
[data-theme="pastel"] .tile-4     { background: #f8bbd0; color: #4a3040; }
[data-theme="pastel"] .tile-8     { background: #f48fb1; color: #ffffff; }
[data-theme="pastel"] .tile-16    { background: #f06292; color: #ffffff; }
[data-theme="pastel"] .tile-32    { background: #ec407a; color: #ffffff; }
[data-theme="pastel"] .tile-64    { background: #e91e63; color: #ffffff; }
[data-theme="pastel"] .tile-128   { background: #d81b60; color: #ffffff; }
[data-theme="pastel"] .tile-256   { background: #ce93d8; color: #ffffff; }
[data-theme="pastel"] .tile-512   { background: #ba68c8; color: #ffffff; }
[data-theme="pastel"] .tile-1024  { background: #ab47bc; color: #ffffff; }
[data-theme="pastel"] .tile-2048  { background: #8e24aa; color: #ffffff; }
[data-theme="pastel"] .tile-4096  { background: #6a1b9a; color: #ffffff; }
[data-theme="pastel"] .tile-8192  { background: #4a148c; color: #ffffff; }
[data-theme="pastel"] .tile-super { background: #2a0a4a; color: #ffffff; }

/* 森林主题方块适配 (NEW) */
[data-theme="forest"] .tile-2     { background: #e8f5e9; color: #1b5e20; }
[data-theme="forest"] .tile-4     { background: #c8e6c9; color: #1b5e20; }
[data-theme="forest"] .tile-8     { background: #a5d6a7; color: #1b5e20; }
[data-theme="forest"] .tile-16    { background: #81c784; color: #1b5e20; }
[data-theme="forest"] .tile-32    { background: #66bb6a; color: #ffffff; }
[data-theme="forest"] .tile-64    { background: #4caf50; color: #ffffff; }
[data-theme="forest"] .tile-128   { background: #43a047; color: #ffffff; }
[data-theme="forest"] .tile-256   { background: #388e3c; color: #ffffff; }
[data-theme="forest"] .tile-512   { background: #2e7d32; color: #ffffff; }
[data-theme="forest"] .tile-1024  { background: #1b5e20; color: #ffffff; }
[data-theme="forest"] .tile-2048  { background: #0d3b0f; color: #ffffff; }
[data-theme="forest"] .tile-4096  { background: #082a0a; color: #ffffff; }
[data-theme="forest"] .tile-8192  { background: #051a06; color: #ffffff; }
[data-theme="forest"] .tile-super { background: #020a03; color: #ffffff; }

/* 海洋主题方块适配 (NEW) */
[data-theme="ocean"] .tile-2     { background: #e1f5fe; color: #01579b; }
[data-theme="ocean"] .tile-4     { background: #b3e5fc; color: #01579b; }
[data-theme="ocean"] .tile-8     { background: #81d4fa; color: #01579b; }
[data-theme="ocean"] .tile-16    { background: #4fc3f7; color: #01579b; }
[data-theme="ocean"] .tile-32    { background: #29b6f6; color: #ffffff; }
[data-theme="ocean"] .tile-64    { background: #039be5; color: #ffffff; }
[data-theme="ocean"] .tile-128   { background: #0288d1; color: #ffffff; }
[data-theme="ocean"] .tile-256   { background: #0277bd; color: #ffffff; }
[data-theme="ocean"] .tile-512   { background: #01579b; color: #ffffff; }
[data-theme="ocean"] .tile-1024  { background: #014a8a; color: #ffffff; }
[data-theme="ocean"] .tile-2048  { background: #01397a; color: #ffffff; }
[data-theme="ocean"] .tile-4096  { background: #012a6a; color: #ffffff; }
[data-theme="ocean"] .tile-8192  { background: #011a5a; color: #ffffff; }
[data-theme="ocean"] .tile-super { background: #000a4a; color: #ffffff; }

/* ==============================================================
   6. 游戏结束遮罩
   ============================================================== */
.game-over-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--color-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  border-radius: var(--border-radius-md);
}

.game-over-content {
  text-align: center;
}

.game-over-title {
  font-size: 48px;
  font-weight: 700;
  color: var(--color-text-dark);
  margin-bottom: var(--spacing-md);
}

.final-score-label {
  font-size: 16px;
  color: var(--color-text-dark);
  opacity: 0.7;
  margin-bottom: var(--spacing-xs);
}

.final-score {
  font-size: 48px;
  font-weight: 700;
  color: var(--color-text-dark);
  margin-bottom: var(--spacing-sm);
}

.best-score-overlay {
  font-size: 16px;
  color: var(--color-text-dark);
  margin-bottom: var(--spacing-lg);
}

/* ==============================================================
   7. 设置面板
   ============================================================== */
.settings-panel {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  display: none;
}

.settings-panel.open {
  display: block;
}

.settings-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
}

.settings-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--color-bg);
  border-radius: var(--border-radius-lg);
  width: 90%;
  max-width: 400px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-lg) var(--spacing-lg) var(--spacing-sm);
  border-bottom: 1px solid var(--color-cell-bg);
}

.settings-header h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--color-text-dark);
}

.settings-close {
  background: none;
  border: none;
  font-size: 28px;
  color: var(--color-text-dark);
  cursor: pointer;
  padding: 0 4px;
  opacity: 0.6;
  transition: opacity var(--transition-fast);
}

.settings-close:hover {
  opacity: 1;
}

.settings-body {
  padding: var(--spacing-md) var(--spacing-lg) var(--spacing-lg);
}

.settings-section {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text-dark);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: var(--spacing-md) 0 var(--spacing-sm);
  opacity: 0.6;
}

.settings-section:first-child {
  margin-top: 0;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-sm) 0;
  border-bottom: 1px solid var(--color-cell-bg);
}

.setting-row:last-child {
  border-bottom: none;
}

.setting-row label:first-child {
  font-size: 15px;
  color: var(--color-text-dark);
}

.setting-row select {
  font-size: 14px;
  padding: 4px 8px;
  border: 1px solid var(--color-cell-bg);
  border-radius: var(--border-radius-sm);
  background: var(--color-bg);
  color: var(--color-text-dark);
  outline: none;
}

.setting-range {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.setting-range input[type="range"] {
  width: 120px;
  accent-color: var(--color-primary);
}

.range-value {
  font-size: 13px;
  color: var(--color-text-dark);
  min-width: 40px;
  text-align: right;
}

/* Toggle 开关 */
.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  cursor: pointer;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--color-cell-bg);
  border-radius: 24px;
  transition: background var(--transition-fast);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: var(--color-text-light);
  border-radius: 50%;
  transition: transform var(--transition-fast);
}

.toggle input:checked + .toggle-slider {
  background: var(--color-primary);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

/* ==============================================================
   8. 页脚
   ============================================================== */
.game-footer {
  margin-top: auto;
  padding: var(--spacing-lg) 0 var(--spacing-sm);
  text-align: center;
  font-size: 12px;
  color: var(--color-text-dark);
  opacity: 0.5;
}

.game-footer p {
  margin-bottom: 4px;
}

/* ==============================================================
   9. 响应式 + 移动端适配 (FIX)
   ============================================================== */
#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: clamp(8px, 3vw, 20px);
  max-width: 540px;
  margin: 0 auto;
  position: relative;
}

/* 小屏适配 (< 520px) */
@media (max-width: 520px) {
  .game-title {
    font-size: clamp(24px, 7vw, 36px);
  }

  .score-box {
    min-width: clamp(50px, 15vw, 70px);
    padding: clamp(2px, 1vw, 8px) clamp(8px, 3vw, 16px);
  }

  .score-value {
    font-size: clamp(16px, 5vw, 22px);
  }

  .score-label {
    font-size: clamp(10px, 3vw, 13px);
  }

  .game-subtitle {
    font-size: clamp(10px, 3vw, 13px);
  }

  .btn {
    font-size: clamp(11px, 3vw, 13px);
    padding: clamp(5px, 1.5vw, 8px) clamp(10px, 3vw, 16px);
  }

  .action-row {
    gap: clamp(4px, 1.5vw, 8px);
  }

  .game-footer {
    font-size: clamp(10px, 2.5vw, 12px);
    padding: clamp(8px, 2vw, 16px) 0;
  }

  /* 设置面板移动端适配 */
  .settings-content {
    width: 95%;
    max-height: 85vh;
  }

  .setting-range input[type="range"] {
    width: clamp(80px, 25vw, 120px);
  }

  .theme-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: clamp(6px, 2vw, 12px);
  }

  .theme-selector-title {
    font-size: clamp(32px, 10vw, 48px);
  }
}

/* 极小屏适配 (< 380px) */
@media (max-width: 380px) {
  .title-row {
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-xs);
  }

  .game-title {
    text-align: center;
  }

  .action-row {
    flex-direction: column;
    align-items: stretch;
    gap: var(--spacing-xs);
  }

  .action-buttons {
    justify-content: center;
  }

  .game-subtitle {
    display: none;
  }

  .score-box {
    min-width: 45px;
    padding: 1px 6px;
  }

  .theme-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
  }

  .theme-card {
    padding: 4px;
  }

  .preview-tile {
    font-size: 7px;
  }

  .theme-name {
    font-size: 11px;
  }
}

/* 设置面板过渡动画 */
.settings-panel.open .settings-backdrop {
  animation: fadeIn 0.2s ease;
}

.settings-panel.open .settings-content {
  animation: slideUp 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.95); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* 页脚底部安全区 */
.game-footer {
  margin-top: auto;
  padding: clamp(8px, 2vw, 20px) 0 clamp(4px, 1vw, 8px);
  text-align: center;
  font-size: clamp(10px, 2.5vw, 12px);
  color: var(--color-text-dark);
  opacity: 0.5;
  width: 100%;
}

.game-footer p {
  margin-bottom: 2px;
}

/* 底部操作按钮组 */
.bottom-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  width: 100%;
  margin-top: 12px;
  flex-wrap: wrap;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  font-size: 13px;
  border-radius: var(--border-radius-md);
  transition: background var(--transition-fast), transform var(--transition-fast);
  cursor: pointer;
  border: none;
  font-weight: 700;
  line-height: 1;
}

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

.btn-icon-symbol {
  font-size: 16px;
  line-height: 1;
}

.btn-automerge-active {
  background: var(--color-success) !important;
  color: #fff !important;
}

@media (max-width: 380px) {
  .bottom-actions {
    gap: 4px;
  }
  .btn-icon {
    font-size: 11px;
    padding: 4px 8px;
  }
}

/* 高分板微调 */
.score-board {
  display: flex;
  gap: clamp(4px, 1.5vw, 8px);
}

/* 按钮微调 */
.btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* 输入控件 - 选择框 */
.setting-row select {
  font-size: clamp(12px, 3vw, 14px);
  padding: clamp(3px, 1vw, 6px) clamp(6px, 2vw, 10px);
}

/* ==============================================================
   10. 主题选择页面
   ============================================================== */
.theme-selector {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--color-bg);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-lg);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.theme-selector.hidden {
  opacity: 0;
  transform: scale(1.05);
  pointer-events: none;
}

.theme-selector-content {
  text-align: center;
  max-width: 600px;
  width: 100%;
}

.theme-selector-title {
  font: 700 56px/1 var(--font-family);
  color: var(--color-text-dark);
  margin-bottom: 4px;
}

.theme-selector-subtitle {
  font-size: 16px;
  color: var(--color-text-dark);
  opacity: 0.7;
  margin-bottom: var(--spacing-xl);
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-xl);
}

.theme-card {
  background: var(--color-cell-bg);
  border-radius: var(--border-radius-md);
  padding: var(--spacing-sm);
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  border: 2px solid transparent;
  outline: none;
}

.theme-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

.theme-card:focus-visible {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(143, 122, 102, 0.3);
}

.theme-card-active {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px var(--color-primary);
}

.theme-preview {
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--border-radius-sm);
  overflow: hidden;
  margin-bottom: var(--spacing-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-cell-bg);
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 6px;
  width: 100%;
  height: 100%;
}

.preview-tile {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  border-radius: 2px;
  color: #776e65;
}

/* 经典主题预览色 */
.preview-classic { background: #bbada0; border-radius: 4px; }
.preview-tile-2    { background: #eee4da; }
.preview-tile-4    { background: #ede0c8; }
.preview-tile-8    { background: #f2b179; color: #f9f6f2; }
.preview-tile-16   { background: #f59563; color: #f9f6f2; }
.preview-tile-128  { background: #edcf72; color: #f9f6f2; }
.preview-tile-2048 { background: #edc22e; color: #f9f6f2; }

/* 暗黑主题预览色 */
.preview-dark { background: #16213e; border-radius: 4px; }
.preview-tile-dark-2    { background: #2d2d5e; color: #e0e0e0; }
.preview-tile-dark-4    { background: #3d3d7e; color: #e0e0e0; }
.preview-tile-dark-8    { background: #4a3d8e; color: #e0e0e0; }
.preview-tile-dark-16   { background: #5a2d9e; color: #e0e0e0; }
.preview-tile-dark-128  { background: #8a0d8e; color: #e0e0e0; }
.preview-tile-dark-2048 { background: #ca0d2e; color: #fff; }

/* 霓虹主题预览色 */
.preview-neon { background: #1a1a3e; border-radius: 4px; }
.preview-tile-neon-2    { background: #0a2a1a; color: #00ff88; }
.preview-tile-neon-4    { background: #0a3a2a; color: #00ff88; }
.preview-tile-neon-8    { background: #0a4a3a; color: #00ff88; }
.preview-tile-neon-16   { background: #0a5a4a; color: #00ff88; }
.preview-tile-neon-128  { background: #0a8a7a; color: #00ff88; }
.preview-tile-neon-2048 { background: #00ff88; color: #0a0a1a; }

/* 粉彩主题预览色 */
.preview-pastel { background: #e8d5e0; border-radius: 4px; }
.preview-tile-pastel-2    { background: #fce4ec; }
.preview-tile-pastel-4    { background: #f8bbd0; }
.preview-tile-pastel-8    { background: #f48fb1; }
.preview-tile-pastel-128  { background: #ce93d8; color: #fff; }
.preview-tile-pastel-512  { background: #ab47bc; color: #fff; }
.preview-tile-pastel-2048 { background: #8e24aa; color: #fff; }

/* 森林主题预览色 */
.preview-forest { background: #a5d6a7; border-radius: 4px; }
.preview-tile-forest-2    { background: #e8f5e9; }
.preview-tile-forest-4    { background: #c8e6c9; }
.preview-tile-forest-8    { background: #a5d6a7; }
.preview-tile-forest-128  { background: #66bb6a; }
.preview-tile-forest-512  { background: #43a047; color: #fff; }
.preview-tile-forest-2048 { background: #1b5e20; color: #fff; }

/* 海洋主题预览色 */
.preview-ocean { background: #b3e5fc; border-radius: 4px; }
.preview-tile-ocean-2    { background: #e1f5fe; }
.preview-tile-ocean-4    { background: #b3e5fc; }
.preview-tile-ocean-8    { background: #81d4fa; }
.preview-tile-ocean-128  { background: #4fc3f7; }
.preview-tile-ocean-512  { background: #0288d1; color: #fff; }
.preview-tile-ocean-2048 { background: #01579b; color: #fff; }

.theme-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--color-text-dark);
  display: block;
  padding: 2px 0 4px;
}

.btn-start {
  padding: 14px 48px;
  font-size: 18px;
  border-radius: var(--border-radius-md);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.btn-start:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

/* ==============================================================
   11. 无障碍 — 减少动画
   ============================================================== */
@media (prefers-reduced-motion: reduce) {
  .tile {
    transition: none;
  }
}
