/*
 * 2048 拓展页 —— 深蓝夜色主题（嵌入版）
 *
 * 与独立版的差异：
 *   - body 顶部预留 5.5rem，避开主站悬浮在 iframe 之上的导航栏
 *   - 页面运行在隔离 iframe 中，脚本无外部依赖
 *
 * 配色取自「月夜湖畔」意象：
 *   夜空深蓝背景 → 面板蓝棋盘 → 月光白文字 → 灯火暖橙点缀
 * 结构：变量 → 布局骨架 → 棋盘与方块 → 结束面板 → 飘字 → 无动画降级
 */
:root {
  --bg: #232f44;            /* 夜空深蓝 */
  --bg-deep: #1c2637;       /* 更深的夜 */
  --panel: #2c3a53;         /* 面板蓝 */
  --cell-empty: rgba(255, 255, 255, 0.07);
  --text: #e8eef8;          /* 月光白 */
  --text-dim: #9db0cc;
  --accent: #f2a94b;        /* 灯火暖橙 */
  --accent-soft: #f7bd6e;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { height: 100%; }
body {
  min-height: 100vh;
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  background: radial-gradient(ellipse at 70% 20%, #2b3a55 0%, var(--bg) 45%, var(--bg-deep) 100%);
  background-attachment: fixed;
  color: var(--text);
  display: flex;
  justify-content: center;
  align-items: center;
  user-select: none;
  /* 顶部大留白给主站悬浮导航；左右小边距防贴边 */
  padding: 6rem 12px 2rem;
}
#container { width: 460px; max-width: 92vw; }

/* ---------- 顶栏 ---------- */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
h1 {
  font-size: clamp(34px, 13vw, 56px);
  font-weight: 800;
  color: var(--text);
  text-shadow: 0 0 24px rgba(242, 169, 75, 0.25);
}
.scores { display: flex; gap: 8px; }
.score-box {
  position: relative; /* 飘字的定位基准 */
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 6px 16px;
  text-align: center;
  min-width: 80px;
}
.score-box .label {
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 2px;
}
.score-box .value { font-size: 22px; font-weight: 700; color: var(--text); }

/* ---------- 控制栏 ---------- */
#controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}
#msg {
  color: var(--text-dim);
  font-size: 14px;
  min-height: 20px;
  flex: 1 1 150px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#btns {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
button {
  background: var(--accent);
  color: #2b2013;
  border: none;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(242, 169, 75, 0.35);
  transition: background 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}
button:hover { background: var(--accent-soft); }

#animToggle {
  background: var(--panel);
  color: var(--text-dim);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: none;
  font-size: 14px;
  padding: 10px 14px;
}
#animToggle:hover { background: #35455f; color: var(--text); }

/* ---------- 棋盘 ---------- */
#board {
  position: relative;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 10px;
  width: 100%;
  aspect-ratio: 1;
  touch-action: none; /* 滑动手势只禁掉棋盘上的页面滚动 */
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}
.cell-bg, .tile {
  position: absolute;
  border-radius: 8px;
}
.cell-bg { background: var(--cell-empty); }
.tile {
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 800;
  transition: top 0.12s ease-in-out, left 0.12s ease-in-out;
  z-index: 2;
}
.tile.new { animation: pop 0.18s ease; }
.tile.merged { animation: merge 0.18s ease; z-index: 3; }
@keyframes pop {
  0% { transform: scale(0); }
  100% { transform: scale(1); }
}
@keyframes merge {
  0% { transform: scale(1); }
  50% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* ---------- 结束 / 胜利面板 ---------- */
#overlay {
  position: absolute;
  inset: 0;
  background: rgba(28, 38, 55, 0.82);
  border-radius: 12px;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 10;
  text-align: center;
}
#overlay.show { display: flex; }
#overlay .big {
  font-size: 44px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 8px;
}
#overlay .sub {
  font-size: 15px;
  color: var(--text-dim);
  margin-bottom: 18px;
}

/* ---------- 合并加分飘字 ----------
   空间足够时向上飘（.up），贴近视口顶时向下淡出（.down），
   由 game.js 实时检测后决定方向。 */
.score-float {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 10;
  font-size: 18px;
  font-weight: 800;
  color: rgba(242, 169, 75, 0.95);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}
.score-float.up {
  top: -24px;
  animation: floatUp 0.7s ease-out forwards;
}
.score-float.down {
  top: calc(100% + 2px);
  animation: floatDown 0.7s ease-out forwards;
}
@keyframes floatUp {
  0% { opacity: 1; transform: translateY(6px); }
  100% { opacity: 0; transform: translateY(-18px); }
}
@keyframes floatDown {
  0% { opacity: 1; transform: translateY(6px); }
  100% { opacity: 0; transform: translateY(22px); }
}

/* ---------- 无动画降级 ----------
   关闭动画：方块移动瞬时完成、弹出/合并/飘字不做动效；
   飘字保持静止显示（信息保留，动效移除）。 */
body.no-anim .tile { transition: none; }
body.no-anim .tile.new,
body.no-anim .tile.merged { animation: none; }
body.no-anim .score-float { animation: none; }

/* ---------- 小屏适配 ---------- */
@media (max-width: 760px) {
  body { padding: 5rem 10px 1.5rem; }
}
@media (prefers-reduced-motion: reduce) {
  button { transition: none; }
}
