/* ============================================================
 * 硬币堆叠合成 · 样式
 * 布局仿微信小游戏：绿色渐变背景 / 顶部数字目标进度条 / 中央白色
 * 圆角面板（4×3 槽位）/ 底部「派发」「合成」两个大按钮。
 * 彩虹元素 + 低饱和：标题与进度条渐变、硬币 pastel rainbow。
 * 动画时长与 js/config.js 的 ANIM 保持一致。
 * ============================================================ */

:root {
  --green-1: #d8f3dc;
  --green-2: #95d5b9;
  --green-3: #52b788;
  --panel: rgba(255, 255, 255, 0.94);
  --gold: #f2c94c;
  --ink: #40514a;
  /* 低饱和彩虹渐变（标题 / 进度条 / 当前关 pill 共用） */
  --rainbow: linear-gradient(90deg, #e07a7a, #e6b357, #74a874, #6a8eae, #9b7ed9);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;          /* 禁双击缩放 */
  user-select: none;
  -webkit-user-select: none;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;
}

body {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  background: linear-gradient(165deg, var(--green-1) 0%, var(--green-2) 45%, var(--green-3) 100%);
  color: var(--ink);
}

#app {
  width: min(100%, 430px);
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0 12px;
}

/* ---------------- 顶栏：齿轮 / 彩虹标题 / 静音 ---------------- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 2px 6px;
}
#title {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 2px;
  color: #1b4332;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}
.icon-btn {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.88);
  font-size: 19px;
  line-height: 1;
  box-shadow: 0 2px 6px rgba(30, 70, 50, 0.18);
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.92); }

/* ---------------- 顶部数字目标进度：5 个圆点 = 本关 5 个数字目标 ----------------
   已达成绿底 ✓ / 下一个目标高亮环 + 数字 / 未达成浅色数字 / 最后一个目标带 👑 */
#progressWrap { padding: 8px 4px 4px; }
#badges {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 13px;
}
.lv-dot {
  position: relative;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
}
/* 徽章间的白色连接段 */
.lv-dot + .lv-dot::after {
  content: '';
  position: absolute;
  right: 100%;
  top: 50%;
  width: 13px;
  height: 5px;
  border-radius: 3px;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.9);
}
.lv-dot.done {
  background: #7cb87c;
  color: #fff;
  font-size: 14px;
  box-shadow: 0 2px 5px rgba(30, 70, 50, 0.25);
}
/* 下一个目标：彩虹描边环 + 白底数字，放大高亮 */
.lv-dot.current {
  width: 35px;
  height: 35px;
  font-size: 16px;
  color: var(--ink);
  border: 3.5px solid transparent;
  background: linear-gradient(#fff, #fff) padding-box, var(--rainbow) border-box;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85), 0 3px 9px rgba(30, 70, 50, 0.3);
}
/* 未达成目标：半透白底灰字 */
.lv-dot.todo {
  background: rgba(255, 255, 255, 0.75);
  color: #8b9a91;
  border: 2px solid rgba(255, 255, 255, 0.9);
}
/* 最后一个目标带小皇冠 */
.lv-dot.crown::before {
  content: '👑';
  position: absolute;
  left: 50%;
  top: -18px;
  transform: translateX(-50%) rotate(-8deg);
  font-size: 13px;
}

/* ---------------- 中央白色圆角面板 + 4×3 槽位 ---------------- */
#panelWrap {
  flex: 1;
  display: flex;
  align-items: center;
  min-height: 0;
}
#panel {
  width: 100%;
  background: var(--panel);
  border-radius: 22px;
  padding: 12px;
  box-shadow: 0 10px 26px rgba(30, 70, 50, 0.22);
}
#board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

/* 槽位为竖高圆角矩形（仿原作：10 枚圆片柱占满整格），矮屏自动压缩 */
.slot {
  position: relative;
  overflow: hidden;
  height: 150px;
  height: min(150px, calc((100vh - 300px) / 3));
  height: min(150px, calc((100dvh - 300px) / 3));
  min-height: 118px;
  border-radius: 12px;
  background: #e6eee9;
  box-shadow: inset 0 2px 6px rgba(60, 90, 75, 0.1);
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s;
}
.slot.type-temp { background: #d3ebdb; }
.slot.type-locked,
.slot.type-locked-temp {
  background: #dde4df;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: not-allowed;
}
/* 槽位解锁：弹跳 + 金光一闪（时长与 config.ANIM.unlock 一致） */
.slot.anim-unlock { animation: unlockPop 0.6s cubic-bezier(0.3, 1.4, 0.5, 1); }
@keyframes unlockPop {
  0%   { transform: scale(0.55); box-shadow: 0 0 0 0 rgba(242, 201, 76, 0.9); }
  60%  { transform: scale(1.07); }
  100% { transform: scale(1); box-shadow: 0 0 22px 6px rgba(242, 201, 76, 0); }
}
.lock-info { text-align: center; }
.lock-emoji { font-size: 22px; }
.lock-text { font-size: 9px; color: #8b9a91; margin-top: 3px; }
.temp-ghost {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #7fa18b;
}
/* 临时槽位机会用尽：置灰 */
.slot.temp-out { opacity: 0.5; }
.slot.selected { border-color: #6a8eae; }
/* 就绪列：金色描边 + 微闪 */
.slot.ready {
  border-color: var(--gold);
  animation: readyPulse 1.3s ease-in-out infinite;
}
@keyframes readyPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(242, 201, 76, 0); }
  50%      { box-shadow: 0 0 14px 3px rgba(242, 201, 76, 0.8); }
}

/* ---------------- 硬币：正圆盘面 + 圆柱侧壁 ----------------
   硬币本体是正圆。堆叠中间只露出圆柱侧壁和很浅的上沿弧线；只有最前一枚
   显示完整的正圆投影。这样不会把每一层都误画成一个完整椭圆。 */
.coin {
  position: absolute;
  left: 4%;
  width: 92%;
  height: 14px;                       /* 兜底值，实际由 JS 按层距覆盖 */
  border: none;
  border-left: 1px solid rgba(55, 50, 85, 0.1);
  border-right: 1px solid rgba(55, 50, 85, 0.1);
  border-radius: 0;
  background:
    linear-gradient(to right,
      rgba(35, 35, 60, 0.12) 0%, rgba(255, 255, 255, 0.08) 18%,
      rgba(255, 255, 255, 0.2) 48%, rgba(255, 255, 255, 0.04) 80%,
      rgba(35, 35, 60, 0.13) 100%),
    linear-gradient(to bottom,
      rgba(255, 255, 255, 0.16) 0%, rgba(255, 255, 255, 0.03) 35%,
      rgba(0, 0, 0, 0.13) 100%),
    var(--side);
  box-shadow:
    inset 0 -1px 0 rgba(35, 35, 65, 0.14),
    1px 2px 2px rgba(70, 72, 115, 0.14);
  --coin-tilt: 0deg;
  line-height: 1;
}
/* 每层之间只画一条浅浅向下弯的分隔弧。弧线属于更靠前的一层，避免被遮住。 */
.coin::before {
  content: '';
  position: absolute;
  left: -1px;
  right: -1px;
  top: -4px;
  height: 7px;
  border-radius: 50%;
  border-bottom: 1px solid var(--edge, rgba(100, 104, 145, 0.2));
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.13);
}
/* 整摞最后方只保留一个圆顶，与竖直侧壁连成同一根柱子。 */
.coin.col-top {
  border-radius: 50% 50% 0 0 / 9px 9px 0 0;
}
.coin.col-top::before {
  content: '';
  position: absolute;
  left: -1px;
  right: -1px;
  top: -1px;
  height: 10px;
  border-radius: 50%;
  background:
    radial-gradient(ellipse at 44% 32%, rgba(255, 255, 255, 0.34), rgba(0, 0, 0, 0.08)),
    var(--side, #eef0f7);
  border: 1px solid var(--edge, rgba(100, 104, 145, 0.18));
}
.coin.col-bottom {
  border-radius: 0 0 50% 50% / 0 0 5px 5px;
}
/* 最前一枚：明亮外圈向外凸，内盘通过内阴影向下凹，数字落在内盘中央。 */
.coin-face {
  position: absolute;
  left: 4%;
  width: 92%;
  height: 70px;                       /* 兜底值，实际由 JS 设为与宽度相同 */
  border-radius: 50%;
  border: 1px solid var(--edge);
  background:
    radial-gradient(circle at 42% 30%,
      rgba(255, 255, 255, 0.34) 0%, rgba(255, 255, 255, 0.08) 52%,
      rgba(0, 0, 0, 0.1) 100%),
    var(--side);
  box-shadow: inset 0 7px 8px rgba(255, 255, 255, 0.24);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Arial Black", "PingFang SC", "Helvetica Neue", sans-serif;
  font-weight: 900;
  letter-spacing: -0.5px;
  line-height: 1;
  transform: rotateX(75deg);
  transform-style: preserve-3d;
  transform-origin: center;
  backface-visibility: hidden;
  --coin-tilt: 75deg;
}
.coin-face::before {
  content: '';
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 48% 58%,
      rgba(255, 255, 255, 0.18) 0%, rgba(255, 255, 255, 0.03) 48%,
      rgba(0, 0, 0, 0.08) 100%),
    var(--face);
  box-shadow:
    inset 0 9px 12px rgba(45, 35, 70, 0.24),
    inset 0 -4px 7px rgba(255, 255, 255, 0.28);
}
.coin-face::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  transform: translateZ(-6px);
  background: var(--edge);
  box-shadow: 0 6px 12px rgba(70, 72, 115, 0.24);
  z-index: -1;
}
.coin-value {
  position: relative;
  z-index: 1;
  transform: translateZ(2px) scaleY(3.05);
}
/* 白色垫片也从正圆投影而来，只替换成浅蓝灰材质。 */
.coin.spacer {
  background:
    linear-gradient(to right,
      rgba(90, 96, 140, 0.08), rgba(255, 255, 255, 0.18) 28%,
      rgba(255, 255, 255, 0.24) 52%, rgba(90, 96, 140, 0.08)),
    linear-gradient(to bottom, #fafbff, #e1e4ef);
  border-color: rgba(123, 128, 166, 0.16);
  box-shadow:
    inset 0 -1px 0 rgba(105, 110, 153, 0.12),
    1px 2px 2px rgba(87, 91, 134, 0.08);
}
.coin.spacer.col-top::before {
  background: radial-gradient(ellipse at 46% 34%, #ffffff, #e5e8f1 78%);
  border-color: rgba(123, 128, 166, 0.14);
}
/* 数字硬币正下方的承接槽：外圈仍是白色圆片，但内侧挖空并把阴影翻到上方，
   形成与向外凸起的硬币相反的凹口。 */
.coin.spacer.socket {
  border-color: rgba(114, 120, 164, 0.2);
  background: linear-gradient(to bottom, #d9ddea 0%, #f5f7fc 72%, #ffffff 100%);
  box-shadow:
    inset 0 4px 5px rgba(93, 99, 145, 0.22),
    inset 0 -2px 3px rgba(255, 255, 255, 0.9);
}
.coin.spacer.socket::before {
  content: '';
  position: absolute;
  left: 5px;
  right: 5px;
  top: -1px;
  height: 7px;
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 38%, #d4d8e7 0%, #edf0f7 68%, #fafbff 100%);
  box-shadow:
    inset 0 3px 4px rgba(83, 90, 137, 0.24),
    0 1px 0 rgba(255, 255, 255, 0.86);
}
/* 选中槽位的栈顶整串：整体上浮，保留原有材质与厚度。 */
.coin.in-run, .coin-face.in-run {
  transform: translateY(-3px) rotateX(var(--coin-tilt, 0deg));
  filter: drop-shadow(0 0 5px rgba(106, 142, 174, 0.85));
}

/* 派发飞入 / 移动落位 / 合成弹跳 */
.coin.anim-deal, .coin-face.anim-deal   { animation: dealDrop 0.38s cubic-bezier(0.2, 0.9, 0.3, 1.15) backwards; }
.coin.anim-move, .coin-face.anim-move   { animation: moveIn 0.24s ease-out backwards; }
.coin.anim-merge, .coin-face.anim-merge { animation: mergePop 0.52s cubic-bezier(0.3, 1.4, 0.5, 1) backwards; }
@keyframes dealDrop {
  from { transform: translateY(-90px) rotateX(var(--coin-tilt, 0deg)); opacity: 0; }
  to   { transform: translateY(0) rotateX(var(--coin-tilt, 0deg));     opacity: 1; }
}
@keyframes moveIn {
  from { transform: translateY(-26px) rotateX(var(--coin-tilt, 0deg)); opacity: 0.4; }
  to   { transform: translateY(0) rotateX(var(--coin-tilt, 0deg));     opacity: 1; }
}
@keyframes mergePop {
  0%   { transform: rotateX(var(--coin-tilt, 0deg)) scale(0.3); }
  60%  { transform: rotateX(var(--coin-tilt, 0deg)) scale(1.25); }
  100% { transform: rotateX(var(--coin-tilt, 0deg)) scale(1); }
}

/* 单一矢量硬币柱：整根柱子共享同一坐标系。 */
.stack-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(2px 2px 1.5px rgba(78, 82, 132, 0.16));
}
.stack-svg.selected-stack {
  transform: translateY(-3px);
  filter: drop-shadow(0 0 5px rgba(106, 142, 174, 0.85));
}
.stack-svg.anim-deal { animation: stackDeal 0.38s cubic-bezier(0.2, 0.9, 0.3, 1.15) backwards; }
.stack-svg.anim-move { animation: stackMove 0.24s ease-out backwards; }
.stack-svg.anim-merge { animation: stackMerge 0.52s cubic-bezier(0.3, 1.4, 0.5, 1) backwards; }
@keyframes stackDeal {
  from { transform: translateY(-50px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes stackMove {
  from { transform: translateY(-18px); opacity: 0.45; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes stackMerge {
  0% { transform: scale(0.6); }
  60% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* 非法目标 / 空按钮抖动 */
.shake { animation: shake 0.3s; }
@keyframes shake {
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-3px); }
}

/* ---------------- 底部两个大按钮 ---------------- */
#actions {
  display: flex;
  gap: 12px;
  padding: 8px 2px calc(14px + env(safe-area-inset-bottom));
}
.big-btn {
  flex: 1;
  height: 56px;
  border: none;
  border-radius: 16px;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 4px;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
  box-shadow: 0 4px 0 rgba(30, 70, 50, 0.25);
  cursor: pointer;
  position: relative;
}
.big-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(30, 70, 50, 0.25); }
.big-btn.deal  { background: linear-gradient(160deg, #74c69d, #40916c); }
.big-btn.merge { background: linear-gradient(160deg, #f6d198, #e0a43c); }
.big-btn.disabled {
  background: #c6d1ca;
  color: #eef4f0;
  text-shadow: none;
  box-shadow: none;
}
.badge {
  position: absolute;
  top: -7px;
  right: -5px;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  background: #e07a7a;
  font-size: 11px;
  letter-spacing: 0;
  line-height: 20px;
  padding: 0 5px;
}

/* ---------------- 浮层 ---------------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 60, 45, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.overlay.hidden { display: none; }
.card {
  width: min(84vw, 330px);
  background: #fff;
  border-radius: 20px;
  padding: 26px 22px;
  text-align: center;
  box-shadow: 0 14px 40px rgba(20, 50, 35, 0.3);
  animation: cardIn 0.3s cubic-bezier(0.3, 1.3, 0.5, 1);
}
@keyframes cardIn {
  from { transform: scale(0.8) translateY(20px); opacity: 0; }
  to   { transform: scale(1) translateY(0);      opacity: 1; }
}
.card h2 { font-size: 19px; margin: 10px 0 6px; }
.card p { font-size: 14px; color: #6b7d72; line-height: 1.7; margin-bottom: 14px; }
.big-emoji { font-size: 52px; line-height: 1.2; }
.crown-anim { animation: crownFloat 1.6s ease-in-out infinite; }
@keyframes crownFloat {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50%      { transform: translateY(-8px) rotate(4deg); }
}
.ending-line { font-size: 14px; color: #6b7d72; line-height: 1.9; }

/* 成绩统计 */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 0;
}
.stat-cell { background: #eef4f0; border-radius: 12px; padding: 12px 6px; }
.stat-num { font-size: 22px; font-weight: 800; color: var(--ink); }
.stat-label { font-size: 11px; color: #85958b; margin-top: 3px; }
.about { font-size: 12px; color: #a3b3a9; margin-bottom: 14px; }

/* 死局浮层：两个按钮并排 */
.overlay-actions { display: flex; gap: 10px; }
.overlay-actions .big-btn { height: 50px; font-size: 16px; letter-spacing: 2px; }

/* 设置浮层：重开本关 + 选关数字网格（可滚动） */
.settings-restart { height: 46px; font-size: 16px; letter-spacing: 2px; margin-bottom: 14px; }
.level-title { font-size: 14px; color: #6b7d72; margin-bottom: 8px; }
.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  max-height: 172px;
  overflow-y: auto;
  padding: 2px;
  margin-bottom: 14px;
}
.level-cell {
  height: 34px;
  border: none;
  border-radius: 9px;
  background: #eef4f0;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
}
.level-cell:active { transform: scale(0.94); }
.level-cell.current {
  background: linear-gradient(160deg, #74c69d, #40916c);
  color: #fff;
}

/* ---------------- 特效层 ---------------- */
#fxLayer, #confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 98;
}
#fxLayer { z-index: 99; }
.confetti-piece {
  position: absolute;
  top: -14px;
  width: 9px;
  height: 14px;
  animation: confettiFall linear forwards;
}
@keyframes confettiFall {
  to { transform: translateY(112vh) rotate(720deg); }
}
.spark {
  position: absolute;
  width: 7px;
  height: 7px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: radial-gradient(circle, #ffe89a, var(--gold));
  animation: sparkFly 0.65s ease-out forwards;
}
@keyframes sparkFly {
  to { transform: translate(var(--dx), var(--dy)) scale(0.2); opacity: 0; }
}
