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

:root {
  --red: #e84d4d; --blue: #4d7de8; --green: #4dc26b;
  --bg: #2a2438; --panel: #3a3350; --panel-2: #463d63;
  --text: #f5f0ff; --dim: #a99fc4;
}

html, body { height: 100%; }
body {
  background: radial-gradient(1200px 600px at 50% -10%, #4a3f6b, var(--bg));
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  display: flex; justify-content: center;
  overflow: hidden;
  user-select: none;
}

#app {
  width: 100%; max-width: 430px; height: 100dvh;
  display: flex; flex-direction: column;
  padding: 10px 12px;
  position: relative;
}

/* ---------- HUD ---------- */
#hud { display: flex; align-items: center; gap: 8px; padding: 4px 2px 10px; }
#level-label { font-size: 18px; font-weight: 700; flex: 1; }
#parts-label { font-size: 14px; color: var(--dim); margin-right: 4px; }
.icon-btn {
  background: var(--panel); color: var(--text); border: none;
  width: 38px; height: 38px; border-radius: 12px; font-size: 18px;
  cursor: pointer; position: relative;
}
.icon-btn:active { transform: scale(0.92); }
#undo-count {
  position: absolute; top: -4px; right: -4px;
  background: var(--green); color: #fff; font-size: 10px; font-weight: 700;
  width: 16px; height: 16px; border-radius: 8px; line-height: 16px;
}

/* ---------- 收集板 ---------- */
#collect-area { display: flex; align-items: center; gap: 12px; padding: 2px 4px 10px; }
.bar {
  display: flex; gap: 10px; padding: 10px 16px;
  border-radius: 14px; background: var(--panel-2);
  border: 2px solid rgba(255,255,255,.15);
  box-shadow: 0 4px 14px rgba(0,0,0,.35);
  transition: background .25s;
}
.bar .hole {
  width: 30px; height: 30px; border-radius: 50%;
  background: rgba(0,0,0,.35);
  border: 2px dashed rgba(255,255,255,.35);
  transition: all .15s;
}
.bar .hole.filled { border-style: solid; border-color: rgba(255,255,255,.8); box-shadow: inset 0 -3px 5px rgba(0,0,0,.3); }
#next-bars { display: flex; gap: 6px; align-items: center; }
.next-chip {
  width: 22px; height: 22px; border-radius: 7px;
  opacity: .8; border: 1.5px solid rgba(255,255,255,.3);
}
.next-label { font-size: 11px; color: var(--dim); margin-right: 2px; }

/* ---------- 缓冲槽 ---------- */
#slot-area { display: flex; gap: 8px; justify-content: center; padding-bottom: 10px; }
.slot {
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(0,0,0,.3);
  border: 2px dashed rgba(255,255,255,.25);
  display: flex; align-items: center; justify-content: center;
}
.slot.bonus { border-color: var(--green); }
.slot .screw-dot { width: 30px; height: 30px; }
.slot-area-danger .slot:not(:has(.screw-dot)) { border-color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 10px var(--red); } }

.screw-dot { border-radius: 50%; box-shadow: inset 0 -4px 6px rgba(0,0,0,.35), inset 0 3px 4px rgba(255,255,255,.45); position: relative; }
.screw-dot::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 60%; height: 3px; background: rgba(0,0,0,.4); border-radius: 2px;
}

/* ---------- 棋盘 ---------- */
#board-wrap { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; }
#board { width: 100%; height: 100%; max-height: 100%; }

.piece-rect { stroke-width: 2.5; rx: 10; }
.screw-g { cursor: pointer; }
.screw-g.blocked { opacity: .55; cursor: default; }
.screw-g.dimmed { opacity: .4; }
.halo {
  transform-box: fill-box; transform-origin: center;
  animation: haloPulse 1.1s ease-in-out infinite;
  pointer-events: none;
}
@keyframes haloPulse {
  0%, 100% { transform: scale(1); opacity: .95; }
  50% { transform: scale(1.25); opacity: .35; }
}
.screw-g.shake { animation: shake .3s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-3px); } 75% { transform: translateX(3px); }
}

/* ---------- 提示气泡 ---------- */
#toast {
  position: absolute; left: 50%; top: 33%;
  transform: translateX(-50%) translateY(8px);
  background: rgba(22, 15, 42, .94);
  border: 1px solid rgba(255, 255, 255, .22);
  color: var(--text); font-size: 14px; line-height: 1.4;
  padding: 10px 18px; border-radius: 999px;
  max-width: 86%; text-align: center;
  z-index: 60; opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 飞行动画层 ---------- */
#fly-layer { position: absolute; inset: 0; pointer-events: none; z-index: 50; }
.fly-dot { position: absolute; width: 28px; height: 28px; }

/* ---------- 弹窗 ---------- */
#overlay {
  position: absolute; inset: 0; z-index: 100;
  background: rgba(15,10,30,.75); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
}
#overlay.hidden { display: none; }
#overlay-card {
  background: var(--panel); border-radius: 20px;
  padding: 28px 24px; width: 86%; max-width: 340px;
  text-align: center; box-shadow: 0 12px 40px rgba(0,0,0,.5);
  animation: pop .25s;
}
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
#overlay-card .big-emoji { font-size: 64px; line-height: 1.3; }
#overlay-card h2 { font-size: 22px; margin: 8px 0 6px; }
#overlay-card p { color: var(--dim); font-size: 14px; margin-bottom: 18px; }
.btn {
  display: block; width: 100%; padding: 13px; margin-top: 10px;
  border: none; border-radius: 14px; font-size: 16px; font-weight: 700;
  cursor: pointer; color: #fff;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: linear-gradient(180deg, #5dd87e, #38a85c); }
.btn-ad { background: linear-gradient(180deg, #f7b733, #e88b1a); }
.btn-plain { background: var(--panel-2); color: var(--dim); }

/* ---------- 选关 ---------- */
#level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin: 14px 0 4px; }
.level-cell {
  aspect-ratio: 1; border-radius: 12px; border: none; cursor: pointer;
  background: var(--panel-2); color: var(--text); font-size: 15px; font-weight: 700;
}
.level-cell.locked { opacity: .35; cursor: default; }
.level-cell.done { background: linear-gradient(180deg, #5dd87e, #38a85c); }
