/* ================================
   2048 游戏 - 自定义样式
   ================================ */

:root {
  --bg: #FAFAF9;
  --bg-alt: #F5F5F4;
  --surface: #FFFFFF;
  --border: #E7E5E4;
  --border-strong: #D6D3D1;
  --text: #1E293B;
  --text-secondary: #52525B;
  --text-muted: #71717A;
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --primary-light: rgba(79, 70, 229, 0.08);
  --secondary: #F97316;
  --accent: #EC4899;
  --success: #059669;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', 'Noto Sans SC', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.toast {
  position: fixed; top: 24px; right: 24px;
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 100px;
  font-size: 14px; font-weight: 500;
  display: flex; align-items: center; gap: 8px;
  z-index: 1000;
  transform: translateX(calc(100% + 40px));
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}
.toast.show { transform: translateX(0); }
.toast-dot { width: 8px; height: 8px; background: var(--success); border-radius: 50%; }

.page { max-width: 960px; margin: 0 auto; padding: 0 32px; }

#header.scrolled {
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 2px 20px rgba(0,0,0,0.06);
}

/* ── 游戏容器 ── */
.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0 32px;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 400px;
  margin-bottom: 20px;
}

.game-scores {
  display: flex;
  gap: 12px;
}

.score-box {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 20px;
  text-align: center;
  min-width: 80px;
}

.score-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.score-value {
  display: block;
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.btn-restart {
  padding: 10px 24px;
  background: var(--primary);
  border: none;
  border-radius: 100px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: white;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.btn-restart:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(0,0,0,0.10);
  transform: translateY(-1px);
}
.btn-restart:active { transform: translateY(0); }

/* ── 网格 ── */
.grid-container {
  position: relative;
  width: 100%;
  max-width: 400px;
  aspect-ratio: 1;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.grid-bg {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 10px;
  width: 100%;
  height: 100%;
}

.grid-bg-cell {
  background: var(--border);
  border-radius: var(--radius);
}

.grid-tiles {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  bottom: 12px;
}

.tile {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 28px;
  transition: transform 0.1s ease;
  z-index: 1;
}

.tile-2 { background: #FFF8E1; color: #776E65; }
.tile-4 { background: #FFECB3; color: #776E65; }
.tile-8 { background: #FFB74D; color: #FFF; }
.tile-16 { background: #FF9800; color: #FFF; }
.tile-32 { background: #FF7043; color: #FFF; }
.tile-64 { background: #F4511E; color: #FFF; }
.tile-128 { background: #FFD54F; color: #FFF; font-size: 24px; }
.tile-256 { background: #FFCA28; color: #FFF; font-size: 24px; }
.tile-512 { background: #FFC107; color: #FFF; font-size: 24px; }
.tile-1024 { background: #FFB300; color: #FFF; font-size: 22px; }
.tile-2048 { background: #FFA000; color: #FFF; font-size: 20px; box-shadow: 0 0 20px rgba(255,160,0,0.4); }
.tile-4096 { background: #FF8F00; color: #FFF; font-size: 18px; }
.tile-8192 { background: #FF6F00; color: #FFF; font-size: 16px; }

.tile-new {
  animation: tile-appear 0.2s ease;
}
.tile-merged {
  animation: tile-pop 0.2s ease;
}

@keyframes tile-appear {
  from { opacity: 0; transform: scale(0); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes tile-pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.game-notice {
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

/* ── 自定义滚动条 ── */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: #f1f5f9; }
::-webkit-scrollbar-thumb { background: #A5B4FC; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #4F46E5; }

::selection { background: rgba(79, 70, 229, 0.2); color: #1E293B; }

/* ── 使用说明手风琴 ── */
.guide-section {
  margin-top: 16px;
  margin-bottom: 64px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.guide-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 14px 20px;
  background: none;
  border: none;
  cursor: pointer;
  transition: background 0.15s ease;
}
.guide-toggle:hover { background: var(--bg-alt); }
.guide-toggle-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: #1E293B;
}
.guide-toggle.open .toggle-arrow { transform: rotate(180deg); }
.toggle-arrow {
  transition: transform 0.2s ease;
  color: var(--text-muted);
}
.guide-list { padding: 0 20px 20px; }
.guide-list.hidden { display: none; }
.guide-item {
  padding: 16px 0;
  border-top: 1px solid var(--border);
}
.guide-item:first-child { border-top: 1px solid var(--border); }
.guide-item-title {
  font-size: 14px;
  font-weight: 600;
  color: #1E293B;
  margin-bottom: 6px;
}
.guide-item-body {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.8;
}
.guide-item-body kbd {
  padding: 1px 6px;
  background: var(--bg-alt);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  font-family: 'SF Mono', 'Cascadia Code', monospace;
  font-size: 12px;
  color: var(--text-secondary);
}

/* ── 响应式 ── */
@media (max-width: 768px) {
  .page { padding: 0 16px; }
  .game-header { flex-direction: column; gap: 12px; }
  .tile { font-size: 22px; }
  .tile-128, .tile-256, .tile-512 { font-size: 20px; }
  .tile-1024 { font-size: 18px; }
  .tile-2048 { font-size: 16px; }
  .tile-4096 { font-size: 14px; }
  .tile-8192 { font-size: 12px; }
}
