* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { user-select: none; -webkit-user-select: none; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(1100px 550px at 75% -10%, rgba(74, 127, 214, .09), transparent 60%),
    radial-gradient(850px 480px at -10% 110%, rgba(52, 211, 153, .08), transparent 60%),
    linear-gradient(135deg, #eef2f8 0%, #e7ecf4 100%);
  min-height: 100vh;
  color: #2d3748;
  padding: 20px 18px 44px;
}

/* ================= 顶栏：品牌 + 统计 ================= */
.topbar {
  max-width: 1020px;
  margin: 0 auto 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-icon {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  font-size: 20px;
  background: linear-gradient(135deg, #4a7fd6, #6aa5ff);
  border-radius: 11px;
  box-shadow: 0 4px 14px rgba(74, 127, 214, .35);
}
.brand-name { font-size: 20px; font-weight: 700; letter-spacing: .3px; }

.stats { display: flex; gap: 10px; flex-wrap: wrap; }
.stat {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid rgba(160, 174, 192, .35);
  border-radius: 999px;
  padding: 7px 15px;
  font-size: 13px;
  box-shadow: 0 2px 10px rgba(30, 50, 90, .06);
}
.stat-label { color: #718096; }
.stat b { color: #2b6cb0; font-variant-numeric: tabular-nums; }

/* ================= 左右布局 ================= */
.layout {
  max-width: 1020px;
  margin: 0 auto;
  display: flex;
  gap: 18px;
  align-items: flex-start;
}

/* ---------- 左侧边栏 ---------- */
.sidebar {
  flex: 0 0 292px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.card {
  background: #fff;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 8px 30px rgba(30, 50, 90, .10), inset 0 0 0 1px rgba(160, 174, 192, .22);
}
.card-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: #94a3b8;
  margin-bottom: 12px;
}
.origin-frame {
  border-radius: 10px;
  overflow: hidden;
  background: #edf1f7;
  box-shadow: inset 0 0 0 1px rgba(160, 174, 192, .3);
}
.origin-frame img { display: block; width: 100%; }

/* ---------- 表单控件 ---------- */
select {
  width: 100%;
  border: 1px solid #cbd5e0;
  background-color: #fff;
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='12'%20height='8'%20viewBox='0%200%2012%208'%3E%3Cpath%20d='M1%201l5%205%205-5'%20fill='none'%20stroke='%2394a3b8'%20stroke-width='2'%20stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  border-radius: 10px;
  padding: 9px 34px 9px 12px;
  font-size: 13px;
  color: #2d3748;
  cursor: pointer;
  font-family: inherit;
  transition: border-color .15s ease;
}
select:hover { border-color: #4a7fd6; }

.btn, .upload {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid #cbd5e0;
  background: #fff;
  color: #2d3748;
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s ease;
  font-family: inherit;
}
.btn:hover, .upload:hover { border-color: #4a7fd6; color: #2b6cb0; }
.btn.primary { background: #4a7fd6; border-color: #4a7fd6; color: #fff; }
.btn.primary:hover { background: #3a68b8; color: #fff; }
.btn:active { transform: scale(.98); }
#fileInput { display: none; }
.btn-stack { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.btn-block { display: block; width: 100%; text-align: center; }

/* ================= 右侧舞台 ================= */
.stage {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 16px 16px;
  border-radius: 20px;
  background-color: rgba(255, 255, 255, .55);
  background-image: radial-gradient(rgba(100, 116, 139, .09) 1px, transparent 1px);
  background-size: 20px 20px;
  box-shadow: inset 0 0 0 1px rgba(160, 174, 192, .22);
}
.play { position: relative; }

#board {
  position: relative;
  border-radius: 12px;
  background-color: #f7fafc;
  background-image: linear-gradient(rgba(120, 140, 170, .10) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(120, 140, 170, .10) 1px, transparent 1px);
  box-shadow: 0 10px 34px rgba(30, 50, 90, .16), inset 0 0 0 1px rgba(160, 174, 192, .25);
  touch-action: none;
}

/* ---------- 拼图块（DOM 引擎） ---------- */
.piece {
  position: absolute;
  left: 0;
  top: 0;
  cursor: grab;
  touch-action: none;
  filter: drop-shadow(0 2px 3px rgba(15, 25, 55, .35));
  will-change: transform;
}
.piece:active { cursor: grabbing; }
.piece.locked { cursor: default; filter: none; }
.piece canvas { display: block; width: 100%; height: 100%; pointer-events: none; }
/* 块数多时关闭投影，保性能 */
.many .piece { filter: none; }

/* 贴合动效（归位瞬间）：绿色光环 + 亮度闪烁 */
.piece.snapping::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 12px;
  border: 2.5px solid #34d399;
  animation: snap-ring .5s ease-out forwards;
  pointer-events: none;
}
.piece.snapping canvas { animation: snap-flash .45s ease-out; }
@keyframes snap-ring {
  0% { transform: scale(1.3); opacity: 0.95; }
  100% { transform: scale(1); opacity: 0; }
}
@keyframes snap-flash {
  0% { filter: brightness(1.45) saturate(1.25); }
  100% { filter: brightness(1); }
}

/* ---------- Canvas 引擎视口 ---------- */
#board canvas.viewport {
  display: block;
  border-radius: 12px;
  cursor: grab;
  touch-action: none;
}
#board canvas.viewport:active { cursor: grabbing; }

/* ---------- 底部拼图块区 ---------- */
#tray {
  margin-top: 14px;
  border: 2px dashed #cbd5e0;
  border-radius: 14px;
  background: rgba(255, 255, 255, .5);
  position: relative;
}
#tray .tag {
  position: absolute;
  top: 7px;
  left: 12px;
  font-size: 12px;
  color: #a0aec0;
  pointer-events: none;
}

/* ---------- 加载中浮层 ---------- */
#loading {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  background: rgba(247, 250, 252, .92);
  z-index: 900;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
#loading.hidden { display: none; }
.loading-text { font-size: 13px; color: #718096; }
.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3.5px solid rgba(74, 127, 214, .18);
  border-top-color: #4a7fd6;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 缩放工具条（Canvas 引擎） ---------- */
#zoomBar {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 500;
  display: none;
  gap: 6px;
}
#zoomBar .btn { padding: 6px 11px; }

/* ---------- 胜利浮层 ---------- */
#win {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, .88);
  z-index: 999;
  text-align: center;
  overflow: hidden;
}
#win.show { display: flex; }
#win h2 { font-size: 28px; color: #2b6cb0; margin-bottom: 10px; }
#win p { font-size: 14px; color: #4a5568; line-height: 1.9; margin-bottom: 16px; }

/* ---------- 彩带 ---------- */
.confetti {
  position: absolute;
  top: -12px;
  width: 8px;
  height: 14px;
  z-index: 997;
  animation: fall linear forwards;
  pointer-events: none;
}
@keyframes fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  80% { opacity: 1; }
  100% { transform: translateY(600px) rotate(680deg); opacity: 0; }
}

.tip {
  margin-top: 14px;
  font-size: 12px;
  color: #a0aec0;
  text-align: center;
  line-height: 1.8;
  max-width: 470px;
}
.tip.warn { color: #e53e3e; }

/* ================= 窄屏：上下堆叠 ================= */
@media (max-width: 880px) {
  .layout { flex-direction: column; align-items: center; }
  .sidebar { flex: 0 0 auto; width: 100%; max-width: 470px; }
  .origin-frame { max-width: 300px; margin: 0 auto; }
  .stage { width: 100%; padding: 16px 10px 12px; }
}

/* ---------- AdSense 广告位（侧边栏底部，与拖拽区隔离） ---------- */
.ad-card {
  padding: 10px;
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.ad-card .adsbygoogle {
  width: 100%;
}
.privacy-link {
  display: block;
  margin-top: 10px;
  font-size: 12px;
  color: #8a94a6;
  text-align: center;
  text-decoration: none;
}
.privacy-link:hover { color: #2f6fed; text-decoration: underline; }
.ad-ph { font-size: 12px; color: #b3bcc9; letter-spacing: 1px; }
