/* ==========================================================================
   奶娃合数 - 2048 游戏样式表
   ========================================================================== */

/* 全局重置与变量定义 */
:root {
  --bg-gradient: linear-gradient(135deg, #fff9f2 0%, #fff1e5 50%, #feddc4 100%);
  --card-bg: #ffffff;
  --card-border: rgba(240, 220, 205, 0.6);
  --card-shadow: 0 8px 24px rgba(165, 115, 80, 0.08), 0 2px 6px rgba(0, 0, 0, 0.03);
  
  --primary-color: #d85d38;
  --primary-dark: #b84320;
  --text-main: #3d2c25;
  --text-muted: #8d786d;
  --text-light: #ab9588;

  --board-bg: #cbbba8;
  --cell-bg: rgba(238, 228, 218, 0.42);
  --tile-shadow: 0 4px 10px rgba(90, 60, 40, 0.12);

  --btn-red: linear-gradient(135deg, #ff5757 0%, #ee3a3a 100%);
  --btn-red-hover: linear-gradient(135deg, #ff6b6b 0%, #f44336 100%);
  --btn-red-shadow: 0 4px 14px rgba(238, 58, 58, 0.35);

  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;

  /* 棋盘尺寸变量（桌面端默认） */
  --board-size: 430px;
  --grid-gap: 12px;
  --tile-size: calc((var(--board-size) - (var(--grid-gap) * 5)) / 4);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg-gradient);
  color: var(--text-main);
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* 主容器：桌面端左右分栏居中 */
.game-wrapper {
  min-height: 100vh;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 36px;
  padding: 24px;
  max-width: 1000px;
  margin: 0 auto;
}

/* ==========================================================================
   左侧面板区
   ========================================================================== */
.control-panel {
  width: 360px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex-shrink: 0;
}

/* 通用卡片外观 */
.header-card,
.score-card,
.card,
.action-card,
.tips-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--card-border);
  box-shadow: var(--card-shadow);
}

/* 标题区 */
.header-card {
  padding: 16px 20px;
  text-align: center;
}

.main-title {
  font-size: 30px;
  font-weight: 800;
  color: var(--primary-color);
  letter-spacing: 1.5px;
  line-height: 1.2;
  text-shadow: 1px 2px 3px rgba(216, 93, 56, 0.15);
}

.sub-title {
  margin-top: 5px;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

/* 计分区 */
.score-container {
  display: flex;
  gap: 12px;
}

.score-card {
  flex: 1;
  padding: 12px 14px;
  text-align: center;
  position: relative;
  overflow: visible;
}

.score-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-light);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.score-value {
  display: block;
  margin-top: 3px;
  font-size: 24px;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

/* 分数增加动画浮层 */
.score-addition {
  position: absolute;
  top: 4px;
  right: 14px;
  font-size: 14px;
  font-weight: 800;
  color: #ff5722;
  opacity: 0;
  transform: translateY(0);
  pointer-events: none;
  transition: none;
}

.score-addition.show {
  animation: float-up 600ms ease-out forwards;
}

@keyframes float-up {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1.1);
  }
  100% {
    opacity: 0;
    transform: translateY(-24px) scale(0.9);
  }
}

/* 卡片通用标题头 */
.card-header {
  padding: 10px 16px 4px;
}

.card-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}

/* 下一个预览区 */
.next-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: 12px;
}

.next-card .card-header {
  align-self: flex-start;
  padding-bottom: 2px;
}

.next-preview-box {
  width: 72px;
  height: 72px;
  background: #fdf6ee;
  border-radius: var(--radius-md);
  border: 2px dashed #eedbc9;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 4px;
  transition: transform 150ms ease;
  overflow: hidden;
}

.next-preview-img {
  width: 58px;
  height: 58px;
  object-fit: contain;
  display: block;
  transition: transform 150ms cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.next-preview-img.pop {
  animation: preview-pop 200ms ease-out;
}

@keyframes preview-pop {
  0% {
    transform: scale(0.6);
    opacity: 0.5;
  }
  70% {
    transform: scale(1.15);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* 合成表（图鉴）卡片 */
.synthesis-card {
  padding-bottom: 10px;
}

.synthesis-list {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px 8px;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: #eedccf transparent;
  -webkit-overflow-scrolling: touch;
}

.synthesis-list::-webkit-scrollbar {
  height: 4px;
}

.synthesis-list::-webkit-scrollbar-thumb {
  background: #eedccf;
  border-radius: 4px;
}

.synthesis-item {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  background: #fdf8f4;
  border-radius: 8px;
  border: 1px solid #f1e2d6;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.synthesis-thumb {
  width: 30px;
  height: 30px;
  object-fit: contain;
  display: block;
}

.synthesis-arrow {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 800;
  color: #cca992;
  user-select: none;
}

/* 操作区：醒目红色圆角重开按钮与音乐开关按钮 */
.action-card {
  border: none;
  background: transparent;
  box-shadow: none;
  display: flex;
  gap: 12px;
}

.btn-restart {
  flex: 1;
  padding: 13px 16px;
  font-size: 15px;
  font-weight: 800;
  color: #ffffff;
  background: var(--btn-red);
  border: none;
  border-radius: var(--radius-md);
  box-shadow: var(--btn-red-shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 180ms cubic-bezier(0.2, 0.8, 0.4, 1);
  outline: none;
  white-space: nowrap;
}

.btn-audio {
  flex: 1;
  padding: 13px 16px;
  font-size: 15px;
  font-weight: 800;
  color: #7a5038;
  background: #ffffff;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  box-shadow: var(--card-shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 180ms cubic-bezier(0.2, 0.8, 0.4, 1);
  outline: none;
  white-space: nowrap;
}

.btn-audio:hover {
  background: #fff8f2;
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(165, 115, 80, 0.15);
}

.btn-audio:active {
  transform: translateY(1px) scale(0.98);
}

.btn-audio.playing {
  border-color: #ffd8bf;
  background: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%);
  color: #c2410c;
  box-shadow: 0 4px 14px rgba(234, 88, 12, 0.18);
}

.btn-audio.muted {
  opacity: 0.75;
  background: #f5f5f4;
  color: #78716c;
  border-color: #e7e5e4;
  box-shadow: none;
}

.audio-icon {
  font-size: 16px;
  line-height: 1;
}

.btn-restart:hover {
  background: var(--btn-red-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(238, 58, 58, 0.45);
}

.btn-restart:active {
  transform: translateY(1px) scale(0.98);
  box-shadow: 0 2px 8px rgba(238, 58, 58, 0.3);
}

.btn-icon {
  font-size: 18px;
  line-height: 1;
}

/* 底部说明区 */
.tips-card {
  padding: 10px 14px;
  text-align: center;
  background: rgba(255, 255, 255, 0.65);
}

.tips-text {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  font-weight: 500;
}

/* ==========================================================================
   右侧游戏区（4x4 棋盘）
   ========================================================================== */
.game-container {
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-wrapper {
  position: relative;
}

.board {
  width: var(--board-size);
  height: var(--board-size);
  background: var(--board-bg);
  border-radius: var(--radius-lg);
  padding: var(--grid-gap);
  position: relative;
  box-shadow: 0 12px 32px rgba(130, 95, 65, 0.16), 0 2px 6px rgba(0, 0, 0, 0.04);
  touch-action: none;
}

/* 4x4 底座背景格子 */
.grid-background {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: var(--grid-gap);
}

.grid-cell {
  background: var(--cell-bg);
  border-radius: var(--radius-md);
  width: 100%;
  height: 100%;
}

/* 动态方块层 */
.tile-container {
  position: absolute;
  inset: var(--grid-gap);
  pointer-events: none;
}

/* 单个方块：绝对定位，根据 --c (列) 和 --r (行) 进行平滑移动 */
.tile {
  position: absolute;
  width: var(--tile-size);
  height: var(--tile-size);
  transform: translate(
    calc(var(--c) * (var(--tile-size) + var(--grid-gap))),
    calc(var(--r) * (var(--tile-size) + var(--grid-gap)))
  );
  transition: transform 120ms ease-in-out;
  will-change: transform;
  z-index: 10;
}

/* 新生成的方块层级 */
.tile.tile-new {
  z-index: 12;
}

/* 合并生成的方块层级更高 */
.tile.tile-merged {
  z-index: 15;
}

/* 方块内胆与视觉容器 */
.tile-inner {
  width: 100%;
  height: 100%;
  background: #ffffff;
  border-radius: var(--radius-md);
  box-shadow: var(--tile-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

/* 方块内的图片：按比例铺满 */
.tile-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
  user-select: none;
}

/* 出现动画 */
.tile-new .tile-inner {
  animation: tile-appear 180ms cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

/* 合并碰撞弹跳动画 */
.tile-merged .tile-inner {
  animation: tile-pop 200ms ease-in-out;
}

@keyframes tile-pop {
  0% {
    transform: scale(0.9);
  }
  50% {
    transform: scale(1.18);
  }
  100% {
    transform: scale(1);
  }
}

/* ==========================================================================
   游戏结束 / 胜利弹窗遮罩
   ========================================================================== */
.game-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 248, 240, 0.88);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: var(--radius-lg);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: overlay-fade-in 240ms ease-out;
}

.game-overlay.active {
  display: flex;
}

@keyframes overlay-fade-in {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.overlay-content {
  text-align: center;
  padding: 24px 30px;
  background: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: 0 16px 40px rgba(120, 80, 50, 0.18);
  border: 1px solid var(--card-border);
  max-width: 82%;
}

.overlay-title {
  font-size: 26px;
  font-weight: 800;
  color: var(--primary-color);
  margin-bottom: 8px;
}

.overlay-msg {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 20px;
  line-height: 1.4;
}

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

.btn-restart-overlay,
.btn-continue {
  padding: 10px 22px;
  font-size: 15px;
  font-weight: 700;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: transform 150ms ease;
}

.btn-restart-overlay {
  background: var(--btn-red);
  color: #fff;
  box-shadow: var(--btn-red-shadow);
}

.btn-continue {
  background: #ff9800;
  color: #fff;
  box-shadow: 0 4px 12px rgba(255, 152, 0, 0.35);
}

.btn-restart-overlay:active,
.btn-continue:active {
  transform: scale(0.96);
}

/* ==========================================================================
   响应式适配：移动端单屏无滚动条排版
   ========================================================================== */
@media (max-width: 859px) {
  html, body {
    overflow: hidden;
    height: 100dvh;
    max-height: 100dvh;
  }

  .game-wrapper {
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
    max-height: 100dvh;
    padding: 8px 10px;
    gap: 8px;
    box-sizing: border-box;
  }

  /* 上方面板区：紧凑网格流式布局 */
  .control-panel {
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  /* 标题缩小 */
  .header-card {
    padding: 6px 12px;
  }

  .main-title {
    font-size: 20px;
  }

  .sub-title {
    font-size: 11px;
    margin-top: 2px;
  }

  /* 计分、下一个、重开按钮压缩进两端布局 */
  .score-container {
    gap: 6px;
  }

  .score-card {
    padding: 6px 8px;
  }

  .score-label {
    font-size: 10px;
  }

  .score-value {
    font-size: 18px;
  }

  /* 中间核心控制行：分数与下一个预览并列 */
  .next-card {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 4px 12px;
  }

  .next-card .card-header {
    padding: 0;
  }

  .next-preview-box {
    width: 44px;
    height: 44px;
    margin-top: 0;
    border-radius: 8px;
  }

  .next-preview-img {
    width: 36px;
    height: 36px;
  }

  /* 合成表缩小高度 */
  .synthesis-card {
    padding-bottom: 4px;
  }

  .synthesis-card .card-header {
    padding: 4px 10px 2px;
  }

  .synthesis-list {
    padding: 2px 10px 4px;
    gap: 4px;
  }

  .synthesis-item {
    width: 28px;
    height: 28px;
    border-radius: 6px;
  }

  .synthesis-thumb {
    width: 24px;
    height: 24px;
  }

  .synthesis-arrow {
    font-size: 10px;
  }

  /* 重开与音乐按钮高度收缩 */
  .btn-restart,
  .btn-audio {
    padding: 8px 10px;
    font-size: 13px;
    border-radius: var(--radius-sm);
  }

  /* 说明文字精简显示 */
  .tips-card {
    padding: 4px 8px;
  }

  .tips-text {
    font-size: 11px;
    line-height: 1.3;
  }

  /* 下方 4x4 棋盘自适应计算，确保一屏完全放下 */
  :root {
    --grid-gap: 8px;
    --board-size: min(90vw, calc(100dvh - 320px), 370px);
  }

  .board {
    border-radius: 14px;
  }

  .grid-cell,
  .tile-inner {
    border-radius: 10px;
  }
}

/* 极小屏幕极限适配 (高度小于 650px) */
@media (max-height: 650px) and (max-width: 859px) {
  :root {
    --grid-gap: 6px;
    --board-size: min(84vw, calc(100dvh - 270px), 320px);
  }

  .header-card .sub-title {
    display: none;
  }

  .tips-card {
    display: none;
  }

  .control-panel {
    gap: 4px;
  }
}
