/* 2048 · 独立样式（选择器统一前缀 .g-g2048） */

.g-g2048 {
  --g2048-slot: rgba(255, 255, 255, 0.045);
  justify-content: center;
}

/* ---------------- 顶部计分 ---------------- */

.g-g2048 .g-head { align-items: stretch; }

.g-g2048 .g-g2048-scores {
  display: flex;
  align-items: stretch;
  gap: 8px;
  min-width: 0;
}

.g-g2048 .g-g2048-sc {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  min-width: 76px;
  padding: 5px 11px;
  border-radius: 12px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.025));
  border: 1px solid var(--line);
}

.g-g2048 .g-g2048-sc-k {
  font-size: 9.5px;
  line-height: 1.2;
  letter-spacing: 0.1em;
  color: var(--faint);
}

.g-g2048 .g-g2048-sc-v {
  display: inline-block;
  font-size: 19px;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.g-g2048 .g-g2048-sc-v.bump { animation: g2048-bump 0.2s cubic-bezier(0.2, 1.2, 0.4, 1) both; }
@keyframes g2048-bump {
  0% { transform: scale(1); color: var(--text); }
  45% { transform: scale(1.16); color: #ffd166; }
  100% { transform: scale(1); color: var(--text); }
}

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

.g-g2048 .g-g2048-boardwrap {
  flex: 0 0 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.g-g2048 .board {
  position: relative;
  width: clamp(220px, calc(100dvh - 332px), 100%);
  max-width: 100%;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  border-radius: 18px;
  background:
    radial-gradient(120% 120% at 0% 0%, rgba(255, 138, 92, 0.08), transparent 58%),
    linear-gradient(160deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.018));
  border: 1px solid var(--line-2);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 22px 54px -32px rgba(0, 0, 0, 0.95);
  touch-action: none;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  font-size: 80px; /* 由脚本设为格子像素，供瓦片 em 字号使用 */
  -webkit-touch-callout: none;
}

.g-g2048 .slots {
  position: absolute;
  inset: 8px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 8px;
}

.g-g2048 .slot {
  border-radius: 12px;
  background: var(--g2048-slot);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.g-g2048 .tiles {
  position: absolute;
  inset: 0;
}

.g-g2048 .tile {
  position: absolute;
  width: calc(25% - 10px);
  height: calc(25% - 10px);
  left: calc(var(--c, 0) * 25% - var(--c, 0) * 2px + 8px);
  top: calc(var(--r, 0) * 25% - var(--r, 0) * 2px + 8px);
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  font-weight: 800;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.05);
  transform-origin: center center;
  transition:
    left 0.12s cubic-bezier(0.2, 0.8, 0.3, 1),
    top 0.12s cubic-bezier(0.2, 0.8, 0.3, 1),
    background 0.16s ease,
    box-shadow 0.16s ease;
  will-change: left, top;
}

/* 数字位数自适应字号（1em = 格子像素） */
.g-g2048 .tile[data-len="1"],
.g-g2048 .tile[data-len="2"] { font-size: 0.44em; }
.g-g2048 .tile[data-len="3"] { font-size: 0.37em; }
.g-g2048 .tile[data-len="4"] { font-size: 0.3em; }
.g-g2048 .tile[data-len="5"] { font-size: 0.25em; }
.g-g2048 .tile[data-len="6"] { font-size: 0.205em; }

/* 分层配色 */
/* 低数值块提亮一档 + 亮边框/字光晕，保证深色底上第一眼可辨；
   8 → 16 → 32 → 64 为连续暖色阶 */
.g-g2048 .tile[data-v="2"] {
  background: linear-gradient(160deg, #63759b, #4a5a7a);
  color: #f4f7fe;
  border-color: rgba(255, 255, 255, 0.2);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.38);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 3px 10px -6px rgba(0, 0, 0, 0.8);
}
.g-g2048 .tile[data-v="4"] {
  background: linear-gradient(160deg, #7a8db5, #5a6c92);
  color: #fbfdff;
  border-color: rgba(255, 255, 255, 0.24);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.38);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.24), 0 4px 12px -6px rgba(0, 0, 0, 0.8);
}
.g-g2048 .tile[data-v="8"] {
  background: linear-gradient(160deg, #ffe2bb, #f7ba7c);
  color: #4d2c12;
  box-shadow: 0 6px 16px -8px rgba(247, 186, 124, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}
.g-g2048 .tile[data-v="16"] {
  background: linear-gradient(160deg, #ffca8e, #f19a58);
  color: #4a2610;
  box-shadow: 0 6px 16px -8px rgba(241, 154, 88, 0.82), inset 0 1px 0 rgba(255, 255, 255, 0.42);
}
.g-g2048 .tile[data-v="32"] {
  background: linear-gradient(160deg, #ffb072, #ec8546);
  color: #421f0a;
  box-shadow: 0 6px 16px -8px rgba(236, 133, 70, 0.85), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.g-g2048 .tile[data-v="64"] {
  background: linear-gradient(160deg, #ff915c, #e4652f);
  color: #fff4ec;
  box-shadow: 0 8px 18px -8px rgba(228, 101, 47, 0.88), inset 0 1px 0 rgba(255, 255, 255, 0.36);
}
.g-g2048 .tile[data-v="128"] {
  background: linear-gradient(160deg, #f6dd97, #e8c25f);
  color: #3e2c07;
  box-shadow: 0 8px 20px -9px rgba(232, 194, 95, 0.85), inset 0 1px 0 rgba(255, 255, 255, 0.42);
}
.g-g2048 .tile[data-v="256"] {
  background: linear-gradient(160deg, #f3d47e, #e2b640);
  color: #3a2905;
  box-shadow: 0 8px 22px -9px rgba(226, 182, 64, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.42);
}
.g-g2048 .tile[data-v="512"] {
  background: linear-gradient(160deg, #f0ca62, #d9a52c);
  color: #332303;
  box-shadow: 0 9px 24px -9px rgba(217, 165, 44, 0.95), inset 0 1px 0 rgba(255, 255, 255, 0.42);
}
.g-g2048 .tile[data-v="1024"] {
  background: linear-gradient(160deg, #eec14a, #cf8f18);
  color: #2e1f00;
  box-shadow: 0 10px 26px -9px rgba(207, 143, 24, 0.95), inset 0 1px 0 rgba(255, 255, 255, 0.42);
}
.g-g2048 .tile[data-v="2048"] {
  background: linear-gradient(150deg, #ffe066, #ffb020);
  color: #4a2c00;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
  box-shadow: 0 0 26px rgba(255, 176, 32, 0.5), 0 12px 28px -10px rgba(255, 176, 32, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.55);
}
.g-g2048 .tile[data-v="4096"] {
  background: linear-gradient(150deg, #caa6ff, #8f66ff);
  color: #fff;
  box-shadow: 0 0 26px rgba(143, 102, 255, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.g-g2048 .tile[data-v="8192"] {
  background: linear-gradient(150deg, #7ef0d6, #2bb59a);
  color: #06342b;
  box-shadow: 0 0 26px rgba(43, 181, 154, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.g-g2048 .tile.huge {
  background: linear-gradient(150deg, #ff9dcb, #d9529b);
  color: #fff;
  box-shadow: 0 0 26px rgba(217, 82, 155, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

/* 动画 */
.g-g2048 .tile.new { animation: g2048-pop 0.16s cubic-bezier(0.2, 1.35, 0.4, 1) both; }
@keyframes g2048-pop {
  from { transform: scale(0.25); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.g-g2048 .tile.merge { animation: g2048-merge 0.18s ease both; }
@keyframes g2048-merge {
  0% { transform: scale(1); }
  55% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

.g-g2048 .tile.vanish { z-index: 0; }
.g-g2048 .tile.vanish.merge { animation: none; }

/* ---------------- 结束覆盖层 ---------------- */

.g-g2048 .over {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 11, 18, 0.82);
  -webkit-backdrop-filter: blur(7px);
  backdrop-filter: blur(7px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.18s ease, visibility 0.18s;
}

.g-g2048 .over.show { opacity: 1; visibility: visible; }

.g-g2048 .over-card {
  width: 100%;
  max-width: 258px;
  text-align: center;
}

.g-g2048 .over-title { font-size: 19px; font-weight: 800; letter-spacing: 0.01em; }
.g-g2048 .over-sub { margin-top: 4px; font-size: 11.5px; color: var(--dim); line-height: 1.5; }

.g-g2048 .over-stats {
  display: flex;
  gap: 8px;
  margin: 14px 0;
}

.g-g2048 .over-stat {
  flex: 1;
  min-width: 0;
  padding: 8px 4px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
}

.g-g2048 .over-stat span {
  display: block;
  font-size: 10px;
  color: var(--faint);
  margin-bottom: 2px;
}

.g-g2048 .over-stat b {
  display: block;
  font-size: 18px;
  font-weight: 800;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.g-g2048 .over .btn-row { gap: 8px; }

/* ---------------- 操作行 / 数据面板 ---------------- */

.g-g2048 .g-g2048-actions { gap: 9px; }
.g-g2048 .g-g2048-actions .btn { min-height: 44px; }

.g-g2048 .g-g2048-meta { padding: 11px 12px 12px; }

.g-g2048 .g-g2048-stats { gap: 8px; }

.g-g2048 .g-g2048-stats .stat { padding: 7px 6px; }
.g-g2048 .g-g2048-stats .stat-v { font-size: 16px; }
.g-g2048 .g-g2048-meta .hint { font-size: 11px; line-height: 1.55; }

/* ---------------- 窄屏 ---------------- */

@media (max-width: 359px) {
  .g-g2048 .g-g2048-sc { min-width: 68px; padding: 5px 8px; }
  .g-g2048 .g-g2048-sc-v { font-size: 17px; }
  .g-g2048 .g-head-right .btn.sm { padding: 6px 9px; }
}
