/* 进化 2048 · AI 进化之路 —— 原创暗色霓虹风格 */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { min-height: 100%; }

body {
  background: radial-gradient(1200px 800px at 70% -10%, #16213f 0%, #0b1020 55%, #070b16 100%);
  color: #e8ecf5;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  display: flex;
  justify-content: center;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#app { width: min(94vw, 520px); padding: 18px 0 32px; }

/* ---------- 头部 ---------- */
header { text-align: center; }

h1 { font-size: clamp(26px, 6vw, 36px); letter-spacing: 3px; font-weight: 800; }
h1 span {
  margin-left: 10px;
  background: linear-gradient(90deg, #38e1ff, #b06bff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle { color: #8b94ad; font-size: 13px; margin-top: 4px; letter-spacing: 1px; }

.hud { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }

.hud-box {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 10px;
  padding: 6px 18px;
  min-width: 88px;
  position: relative;
}
.hud-box label { font-size: 11px; color: #8b94ad; letter-spacing: 3px; display: block; }
.hud-box > div { font-size: 20px; font-weight: 700; margin-top: 1px; }

#timer.urgent { color: #ff6b81; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.45; } }

.score-float {
  position: absolute;
  right: 10px;
  top: -6px;
  color: #7ef0c8;
  font-weight: 800;
  font-size: 15px;
  pointer-events: none;
  animation: floatUp 0.8s ease-out forwards;
}
@keyframes floatUp {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-28px); }
}

/* ---------- 模式与工具按钮 ---------- */
.modes { display: flex; gap: 8px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.toolbar { display: flex; gap: 8px; justify-content: center; margin-top: 10px; flex-wrap: wrap; }

.mode-tab, .tool-btn {
  background: rgba(255, 255, 255, 0.06);
  color: #dfe6f5;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.mode-tab:hover, .tool-btn:hover { border-color: #38e1ff; color: #7ee9ff; }
.mode-tab.active {
  background: linear-gradient(90deg, rgba(56, 225, 255, 0.18), rgba(176, 107, 255, 0.18));
  border-color: #38e1ff;
  color: #7ee9ff;
  font-weight: 700;
}
.tool-btn:disabled { opacity: 0.35; cursor: default; }
.tool-btn:disabled:hover { border-color: rgba(255, 255, 255, 0.13); color: #dfe6f5; }

/* ---------- 棋盘 ---------- */
#board-wrap {
  margin-top: 16px;
  background: linear-gradient(160deg, rgba(56, 225, 255, 0.06), rgba(176, 107, 255, 0.06));
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45), inset 0 0 60px rgba(56, 225, 255, 0.03);
}

#board { position: relative; width: 100%; aspect-ratio: 1; touch-action: none; }

#board-bg { position: absolute; inset: 0; display: grid; }
.cell { background: rgba(255, 255, 255, 0.05); border-radius: 8px; }

#tile-layer { position: absolute; inset: 0; }

.tile {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: left 0.15s ease-in-out, top 0.15s ease-in-out;
  z-index: 5;
  color: #fff;
  overflow: hidden;
}
.tile-name {
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  padding: 0 2px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.tile-lv { font-size: 0.55em; opacity: 0.8; margin-top: 2px; letter-spacing: 1px; }

/* 各级方块配色（原创霓虹渐变，非原版 2048 配色） */
.lv1  { background: linear-gradient(135deg, #155e75, #0e7490); box-shadow: 0 0 10px rgba(14, 116, 144, 0.45); }
.lv2  { background: linear-gradient(135deg, #0f766e, #14b8a6); box-shadow: 0 0 10px rgba(20, 184, 166, 0.45); }
.lv3  { background: linear-gradient(135deg, #15803d, #22c55e); box-shadow: 0 0 10px rgba(34, 197, 94, 0.45); }
.lv4  { background: linear-gradient(135deg, #4d7c0f, #a3e635); box-shadow: 0 0 12px rgba(163, 230, 53, 0.5); }
.lv5  { background: linear-gradient(135deg, #a16207, #facc15); box-shadow: 0 0 12px rgba(250, 204, 21, 0.5); }
.lv6  { background: linear-gradient(135deg, #c2410c, #fb923c); box-shadow: 0 0 12px rgba(251, 146, 60, 0.5); }
.lv7  { background: linear-gradient(135deg, #be123c, #fb7185); box-shadow: 0 0 12px rgba(251, 113, 133, 0.5); }
.lv8  { background: linear-gradient(135deg, #a21caf, #e879f9); box-shadow: 0 0 14px rgba(232, 121, 249, 0.55); }
.lv9  { background: linear-gradient(135deg, #6d28d9, #a78bfa); box-shadow: 0 0 14px rgba(167, 139, 250, 0.55); }
.lv10 { background: linear-gradient(135deg, #3730a3, #818cf8); box-shadow: 0 0 14px rgba(129, 140, 248, 0.55); }
.lv11 { background: linear-gradient(135deg, #0369a1, #38bdf8); box-shadow: 0 0 18px rgba(56, 189, 248, 0.7); border: 1px solid rgba(250, 204, 21, 0.65); }
.lv12 { background: linear-gradient(135deg, #7e22ce, #c084fc); box-shadow: 0 0 20px rgba(192, 132, 252, 0.75); border: 1px solid rgba(255, 255, 255, 0.5); }
.lv13 { background: linear-gradient(135deg, #111827, #4f46e5); box-shadow: 0 0 24px rgba(99, 102, 241, 0.85); border: 1px solid rgba(176, 107, 255, 0.7); }

/* 出现与合并动画 */
.tile-new { animation: tileAppear 0.18s ease-out; }
@keyframes tileAppear {
  0%   { transform: scale(0); opacity: 0; }
  60%  { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}
.tile-merged { animation: tileMerge 0.22s ease-out; z-index: 8; }
@keyframes tileMerge {
  0%   { transform: scale(0.6); }
  55%  { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* ---------- 提示 ---------- */
.hint { text-align: center; color: #69718c; font-size: 12px; margin-top: 14px; line-height: 1.8; }

/* ---------- 遮罩层（胜利 / 失败） ---------- */
#overlay, #modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 18, 0.72);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
#modal { z-index: 55; }
.hidden { display: none !important; }

.overlay-card, .modal-card {
  background: #121a30;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  padding: 26px 24px;
  width: min(92vw, 430px);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  animation: cardIn 0.25s ease-out;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px) scale(0.96); }
  to   { opacity: 1; transform: none; }
}

.overlay-card h2 {
  font-size: 26px;
  letter-spacing: 2px;
  background: linear-gradient(90deg, #38e1ff, #b06bff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.overlay-card p { margin-top: 12px; color: #c6cde0; font-size: 15px; line-height: 1.7; }
.overlay-stats { color: #8b94ad !important; font-size: 13px !important; }

.overlay-btns { display: flex; gap: 10px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
.btn-primary, .btn-ghost {
  border-radius: 999px;
  padding: 10px 22px;
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  transition: filter 0.15s, border-color 0.15s, color 0.15s;
}
.btn-primary {
  background: linear-gradient(90deg, #38e1ff, #4f8cff);
  color: #04101c;
  border: none;
  font-weight: 700;
}
.btn-primary:hover { filter: brightness(1.12); }
.btn-ghost {
  background: transparent;
  color: #dfe6f5;
  border: 1px solid rgba(255, 255, 255, 0.2);
}
.btn-ghost:hover { border-color: #38e1ff; color: #7ee9ff; }

/* ---------- 弹窗（图鉴 / 成就） ---------- */
.modal-card { width: min(92vw, 580px); text-align: left; max-height: 86vh; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { font-size: 20px; letter-spacing: 2px; }
#modal-close {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #dfe6f5;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
#modal-close:hover { border-color: #38e1ff; color: #7ee9ff; }
#modal-body { margin-top: 14px; overflow-y: auto; padding-right: 4px; }

/* 图鉴 */
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.gal-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 10px;
}
.gal-swatch {
  height: 44px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  margin-bottom: 8px;
}
.gal-name { font-weight: 700; font-size: 14px; }
.gal-desc { font-size: 12px; color: #8b94ad; margin-top: 4px; line-height: 1.6; }
.gal-card.locked { opacity: 0.5; }
.gal-card.locked .gal-swatch { background: #232a3d; box-shadow: none; color: #5a6478; }

/* 成就 */
.ach-progress { font-size: 13px; color: #8b94ad; margin-bottom: 10px; }
.ach-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  margin-bottom: 8px;
}
.ach-badge {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f6d365, #fda085);
  color: #3a2b00;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 16px;
  flex: none;
}
.ach-name { font-weight: 700; font-size: 14px; }
.ach-desc { font-size: 12px; color: #8b94ad; margin-top: 2px; }
.ach-state { margin-left: auto; font-size: 12px; color: #7ef0c8; flex: none; }
.ach-item.locked { opacity: 0.5; }
.ach-item.locked .ach-badge { background: #2a3247; color: #6b7490; }
.ach-item.locked .ach-state { color: #69718c; }

/* ---------- 成就解锁提示 ---------- */
#toasts {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  z-index: 60;
  pointer-events: none;
  width: max-content;
  max-width: 92vw;
}
.toast {
  background: rgba(20, 28, 48, 0.96);
  border: 1px solid rgba(246, 211, 101, 0.5);
  border-radius: 12px;
  padding: 10px 18px;
  text-align: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  animation: toastIn 0.3s ease-out;
}
.toast b { color: #f6d365; font-size: 13px; letter-spacing: 2px; display: block; }
.toast span { color: #dfe6f5; font-size: 14px; margin-top: 2px; display: block; }
.toast.out { animation: toastOut 0.3s ease-in forwards; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: none; }
}
@keyframes toastOut {
  to { opacity: 0; transform: translateY(10px); }
}
