/* ============================================================
   合成数字 2048 —— 样式表
   霓虹夜色主题：冷色起步，逐级过渡到紫 / 粉 / 金
   ============================================================ */

:root {
  --primary: #7c5cff;
  --cyan: #22d3ee;
  --pink: #ff5ca8;
  --gold: #ffb347;
  --panel-bg: rgba(255, 255, 255, .06);
  --panel-border: rgba(255, 255, 255, .12);
  --text-main: #eef1ff;
  --text-dim: rgba(238, 241, 255, .62);
  --board-gap: 12px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text-main);
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: radial-gradient(circle at 50% 30%, #171a3a, #0b0e20);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
}

.app {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 18px 16px 26px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------------- 顶部栏 ---------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 9px;
  border-radius: 10px;
  font-size: .8rem;
  font-weight: 800;
  letter-spacing: .5px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--cyan));
  box-shadow: 0 4px 16px rgba(124, 92, 255, .45);
}

.brand-title {
  margin: 0;
  font-size: 1.28rem;
  font-weight: 800;
  letter-spacing: 1px;
  background: linear-gradient(90deg, #fff, #b9c6ff 55%, var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap;
}

.back-link {
  flex: none;
  padding: 8px 14px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: var(--panel-bg);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: var(--text-main);
  font-size: .88rem;
  text-decoration: none;
  transition: transform .15s ease, background .2s ease, border-color .2s ease;
}

.back-link:hover { background: rgba(255, 255, 255, .12); transform: translateY(-1px); }
.back-link:active { transform: translateY(1px); }

/* ---------------- 通用面板与按钮 ---------------- */

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.btn {
  font-family: inherit;
  font-size: .92rem;
  font-weight: 700;
  color: var(--text-main);
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: var(--panel-bg);
  cursor: pointer;
  transition: transform .12s ease, box-shadow .15s ease, background .2s ease, opacity .2s ease;
}

.btn:hover { background: rgba(255, 255, 255, .12); transform: translateY(-1px); }
.btn:active { transform: translateY(1px) scale(.97); }
.btn:disabled { opacity: .38; cursor: not-allowed; transform: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #5b8cff);
  border-color: rgba(124, 92, 255, .55);
  box-shadow: 0 6px 18px rgba(124, 92, 255, .38);
}

.btn-primary:hover { background: linear-gradient(135deg, #8d72ff, #6f9bff); }

/* ---------------- HUD 计分栏 ---------------- */

.hud {
  width: 100%;
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 12px;
  margin-bottom: 14px;
}

.score-box {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 4px;
  border-radius: 14px;
  background: rgba(255, 255, 255, .045);
  border: 1px solid rgba(255, 255, 255, .07);
}

.score-label {
  font-size: .72rem;
  letter-spacing: 2px;
  color: var(--text-dim);
}

.score-value {
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

#scoreValue.bump { animation: score-bump .26s ease; }

@keyframes score-bump {
  0% { transform: scale(1); color: var(--text-main); }
  45% { transform: scale(1.28); color: var(--cyan); text-shadow: 0 0 14px rgba(34, 211, 238, .8); }
  100% { transform: scale(1); color: var(--text-main); }
}

/* 分数增加飘字 */
.score-float {
  position: absolute;
  top: 2px;
  left: 50%;
  font-size: .95rem;
  font-weight: 800;
  color: var(--cyan);
  text-shadow: 0 0 10px rgba(34, 211, 238, .75);
  pointer-events: none;
  animation: score-rise .8s ease-out forwards;
}

@keyframes score-rise {
  0% { opacity: 0; transform: translate(-50%, 8px) scale(.8); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -30px) scale(1.1); }
}

.hud-actions {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  justify-content: center;
}

.hud-actions .btn { padding: 8px 16px; white-space: nowrap; }

/* ---------------- 棋盘 ---------------- */

.board-wrap { width: 100%; display: flex; justify-content: center; }

.board {
  position: relative;
  width: min(94vw, 480px);
  aspect-ratio: 1 / 1;
  border-radius: 20px;
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--panel-border);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .45), inset 0 0 30px rgba(124, 92, 255, .06);
  --gap: var(--board-gap);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}

.cell-layer,
.tile-layer,
.fx-layer {
  position: absolute;
  inset: 0;
}

.tile-layer, .fx-layer { pointer-events: none; }

.cell {
  position: absolute;
  top: 0;
  left: 0;
  border-radius: 14px;
  background: rgba(255, 255, 255, .045);
  border: 1px solid rgba(255, 255, 255, .06);
}

/* ---------------- 数字方块 ---------------- */

.tile {
  position: absolute;
  top: 0;
  left: 0;
  will-change: transform;
}

.tile-inner {
  width: 100%;
  height: 100%;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  line-height: 1;
  border: 1px solid transparent;
}

.tile-num { display: block; font-variant-numeric: tabular-nums; }

/* 各级霓虹配色：2 / 4 冷色起步，逐级过渡到紫 / 粉 / 金 */
.tile-lv1 .tile-inner {
  background: linear-gradient(135deg, #2c4a8f, #1d3263);
  color: #d8e4ff;
  border-color: rgba(140, 170, 255, .28);
}

.tile-lv2 .tile-inner {
  background: linear-gradient(135deg, #0f6f92, #0b83a3);
  color: #e7fcff;
  border-color: rgba(34, 211, 238, .35);
  box-shadow: 0 0 12px rgba(34, 211, 238, .16);
}

.tile-lv3 .tile-inner {
  background: linear-gradient(135deg, #0891b2, #06b6d4);
  color: #f0feff;
  border-color: rgba(103, 232, 249, .45);
  box-shadow: 0 0 14px rgba(34, 211, 238, .3);
}

.tile-lv4 .tile-inner {
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  color: #f4f5ff;
  border-color: rgba(165, 180, 252, .5);
  box-shadow: 0 0 16px rgba(99, 102, 241, .38);
}

.tile-lv5 .tile-inner {
  background: linear-gradient(135deg, #7c5cff, #6a48f0);
  color: #fff;
  border-color: rgba(196, 181, 255, .55);
  box-shadow: 0 0 18px rgba(124, 92, 255, .45);
}

.tile-lv6 .tile-inner {
  background: linear-gradient(135deg, #9333ea, #b05df7);
  color: #fff;
  border-color: rgba(216, 180, 254, .55);
  box-shadow: 0 0 18px rgba(168, 85, 247, .45);
}

.tile-lv7 .tile-inner {
  background: linear-gradient(135deg, #c026d3, #e879f9);
  color: #fff;
  border-color: rgba(240, 171, 252, .6);
  box-shadow: 0 0 20px rgba(192, 38, 211, .5);
}

.tile-lv7 .tile-num,
.tile-lv8 .tile-num,
.tile-lv9 .tile-num,
.tile-lv10 .tile-num { text-shadow: 0 0 10px rgba(255, 255, 255, .55); }

.tile-lv8 .tile-inner {
  background: linear-gradient(135deg, #db2777, #ff5ca8);
  color: #fff;
  border-color: rgba(255, 150, 200, .65);
  box-shadow: 0 0 22px rgba(255, 92, 168, .55);
}

.tile-lv9 .tile-inner {
  background: linear-gradient(135deg, #f43f5e, #fb7185);
  color: #fff;
  border-color: rgba(253, 164, 175, .65);
  box-shadow: 0 0 22px rgba(244, 63, 94, .5);
}

.tile-lv10 .tile-inner {
  background: linear-gradient(135deg, #f97316, #ffb347);
  color: #fff8ec;
  border-color: rgba(255, 200, 140, .7);
  box-shadow: 0 0 24px rgba(255, 179, 71, .5);
}

.tile-lv11 .tile-inner {
  background: linear-gradient(135deg, #f59e0b, #ffd24a);
  color: #4a2c00;
  border-color: rgba(255, 236, 170, .85);
  box-shadow: 0 0 16px rgba(255, 179, 71, .6), 0 0 38px rgba(255, 179, 71, .3);
  animation: gold-pulse 1.7s ease-in-out infinite;
}

.tile-lv11 .tile-num { text-shadow: 0 0 12px rgba(255, 244, 200, .9); }

.tile-lv12 .tile-inner {
  background: linear-gradient(135deg, #fff1b8, #ffd24a 45%, #ff8a3d);
  color: #5a2d00;
  border-color: rgba(255, 255, 230, .9);
  box-shadow: 0 0 20px rgba(255, 210, 74, .8), 0 0 50px rgba(255, 138, 61, .45);
  animation: gold-pulse 1.1s ease-in-out infinite;
}

.tile-lv12 .tile-num { text-shadow: 0 0 14px rgba(255, 255, 235, .95); }

@keyframes gold-pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.22); }
}

/* 出现与合并弹跳动画（作用于内层，不干扰外层位移动画） */
.tile-inner.anim-appear { animation: tile-appear .16s ease-out; }
.tile-inner.anim-pop { animation: tile-pop .22s cubic-bezier(.2, 1.4, .4, 1); }

@keyframes tile-appear {
  0% { transform: scale(0); opacity: .2; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes tile-pop {
  0% { transform: scale(.3); }
  55% { transform: scale(1.22); }
  100% { transform: scale(1); }
}

/* 棋盘内合并飘字 */
.merge-fx {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 0 12px rgba(255, 255, 255, .8), 0 0 22px rgba(124, 92, 255, .8);
  pointer-events: none;
  animation: merge-rise .7s ease-out forwards;
}

@keyframes merge-rise {
  0% { opacity: 0; transform: translateY(10px) scale(.7); }
  25% { opacity: 1; transform: translateY(-4px) scale(1.05); }
  100% { opacity: 0; transform: translateY(-34px) scale(1); }
}

/* ---------------- 遮罩（胜利 / 失败） ---------------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  border-radius: 20px;
  background: rgba(9, 11, 28, .62);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: overlay-in .25s ease;
}

.hidden { display: none !important; }

@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.overlay-card {
  width: 100%;
  max-width: 320px;
  padding: 26px 22px;
  text-align: center;
  box-shadow: 0 16px 44px rgba(0, 0, 0, .5);
}

.overlay-title {
  margin: 0 0 8px;
  font-size: 1.6rem;
  font-weight: 800;
}

.overlay-title.win {
  background: linear-gradient(90deg, var(--gold), #ffe39a, var(--pink));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.overlay-title.lose { color: var(--pink); text-shadow: 0 0 18px rgba(255, 92, 168, .5); }

.overlay-text {
  margin: 0 0 20px;
  font-size: .95rem;
  line-height: 1.6;
  color: var(--text-dim);
}

.overlay-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---------------- 底部说明 ---------------- */

.tips {
  margin-top: 14px;
  text-align: center;
  font-size: .8rem;
  line-height: 1.7;
  color: var(--text-dim);
}

/* ---------------- 手机端自适应 ---------------- */

@media (max-width: 480px) {
  .app { padding: 12px 10px 20px; }
  .board { --gap: 10px; border-radius: 18px; }
  .brand-title { font-size: 1.08rem; }
  .brand-mark { font-size: .72rem; padding: 5px 8px; }
  .back-link { padding: 7px 10px; font-size: .8rem; }
  .score-value { font-size: 1.25rem; }
  .hud { gap: 8px; padding: 10px; }
  .hud-actions .btn { padding: 8px 12px; font-size: .85rem; }
  .cell, .tile-inner { border-radius: 11px; }
}

@media (max-width: 360px) {
  .board { --gap: 8px; }
  .brand-mark { display: none; }
}
