/* ---------- 深夜糖果风设计语言 ---------- */
:root {
  --glass-bg: rgba(255, 255, 255, 0.10);
  --glass-bg-strong: rgba(255, 255, 255, 0.22);
  --glass-border: rgba(255, 255, 255, 0.26);
  --text: #ffffff;
  --shadow: 0 10px 30px rgba(15, 8, 45, 0.35);
  --accent: #8f7bff;
}
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 600px at 88% -12%, rgba(255, 140, 220, 0.40), transparent 62%),
    radial-gradient(900px 700px at -12% 112%, rgba(90, 190, 255, 0.32), transparent 62%),
    linear-gradient(160deg, #241a5e 0%, #45297f 45%, #71389b 72%, #a0458d 100%);
  background-attachment: fixed;
  overscroll-behavior: none;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
#app {
  position: relative;
  height: 100vh;
  height: 100dvh;
}

/* ---------- 屏幕容器 ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 12px calc(env(safe-area-inset-bottom, 0px) + 12px);
}
.screen.active {
  display: flex;
}
.screen.overlay {
  background: rgba(20, 10, 50, 0.45);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  justify-content: center;
  align-items: center;
  z-index: 50;
}

/* ---------- 顶栏 ---------- */
.hud {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.07));
}
.hud-mid {
  flex: 1;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 15px;
  min-width: 0;
}
.hud-mid #hud-level {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pill {
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 13px;
  white-space: nowrap;
}

/* ---------- 按钮 ---------- */
.btn {
  font: inherit;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: #fff;
  border-radius: 999px;
  padding: 12px 28px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  touch-action: manipulation;
  transition: transform 0.15s, background 0.15s;
}
.btn:active {
  transform: scale(0.96);
}
.btn.primary {
  background: linear-gradient(135deg, #8f7bff 0%, #d96dfb 60%, #ff8ec7 100%);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.4);
  box-shadow: 0 8px 22px rgba(150, 90, 255, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}
.btn.ghost {
  padding: 6px 12px;
  font-size: 15px;
}

/* ---------- 开始 / 结算卡片 ---------- */
.card-start {
  width: min(88vw, 420px);
  margin: auto;
  padding: 36px 28px;
  text-align: center;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.20), rgba(255, 255, 255, 0.08));
}
.card-start .logo {
  font-size: 64px;
  line-height: 1.2;
  filter: drop-shadow(0 6px 14px rgba(255, 140, 220, 0.5));
}
.card-start h1 {
  margin: 8px 0 4px;
  font-size: 30px;
  letter-spacing: 2px;
}
.sub {
  opacity: 0.85;
  margin: 4px 0 18px;
}
.tip {
  opacity: 0.65;
  font-size: 12px;
  margin: 14px 0 0;
}
.card-win {
  width: min(86vw, 380px);
  padding: 30px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.20), rgba(255, 255, 255, 0.08));
}
.card-win h2 {
  margin: 0;
}
.win-emoji {
  font-size: 56px;
  line-height: 1.2;
  animation: pop 0.5s;
}
.stars {
  font-size: 40px;
  letter-spacing: 6px;
  min-height: 48px;
}
.stars span {
  display: inline-block;
  animation: starIn 0.4s backwards;
}
.stars span:nth-child(2) {
  animation-delay: 0.15s;
}
.stars span:nth-child(3) {
  animation-delay: 0.3s;
}
.stars .on {
  color: #ffd84d;
  text-shadow: 0 2px 10px rgba(255, 216, 77, 0.6);
}
.stars .off {
  color: rgba(255, 255, 255, 0.3);
}

/* ---------- 盒子区 ---------- */
.box-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 2px 0;
}
.boxes {
  display: flex;
  gap: 10px;
  flex: 1;
  justify-content: center;
  min-width: 0;
}
.box {
  flex: 0 1 150px;
  min-width: 106px;
  max-width: 180px;
  padding: 9px 10px 10px;
  text-align: center;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.08));
  box-shadow: 0 8px 24px rgba(15, 8, 45, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.box-icon {
  font-size: 22px;
  line-height: 1;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 4px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.06) 58%), var(--tint, rgba(255, 255, 255, 0.25));
  box-shadow: 0 3px 8px rgba(15, 8, 45, 0.35), inset 0 0 0 2px rgba(255, 255, 255, 0.65);
}
.box-label {
  font-size: 13px;
  font-weight: 600;
}
.box-bar {
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  overflow: hidden;
  margin-top: 6px;
}
.box-bar i {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.55));
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.5);
  transition: width 0.3s;
}
.box-count {
  font-size: 11px;
  opacity: 0.85;
  margin-top: 4px;
}
.box.done {
  background: linear-gradient(180deg, rgba(255, 216, 77, 0.55), rgba(255, 190, 60, 0.26));
  border-color: rgba(255, 226, 130, 0.95);
  animation: doneflash 0.5s;
}
.box.done .box-bar i {
  background: linear-gradient(90deg, #ffffff, #ffe082);
}

/* ---------- 场景化关卡背景（body.scene-0..6） ---------- */
/* 0 衣帽间：粉紫霓虹更衣室 */
body.scene-0 {
  background:
    radial-gradient(900px 600px at 85% -10%, rgba(255, 150, 220, 0.42), transparent 62%),
    linear-gradient(160deg, #3a1c5e 0%, #7c2f8f 50%, #c04a9a 100%);
}
/* 1 玩具房：活力橙黄 */
body.scene-1 {
  background:
    radial-gradient(900px 600px at 12% -10%, rgba(255, 200, 90, 0.40), transparent 62%),
    linear-gradient(160deg, #4a2350 0%, #a3426e 45%, #e8734a 100%);
}
/* 2 厨房：暖橙红烟火气 */
body.scene-2 {
  background:
    radial-gradient(900px 600px at 88% -8%, rgba(255, 160, 90, 0.45), transparent 62%),
    linear-gradient(160deg, #4d1f3a 0%, #94385a 45%, #d96a3e 100%);
}
/* 3 工作室：静谧蓝青 */
body.scene-3 {
  background:
    radial-gradient(900px 600px at 10% -10%, rgba(110, 210, 255, 0.38), transparent 62%),
    linear-gradient(160deg, #1b2a5e 0%, #2f5a9e 50%, #4a8fb5 100%);
}
/* 4 药店：薄荷青绿 */
body.scene-4 {
  background:
    radial-gradient(900px 600px at 88% -10%, rgba(120, 240, 190, 0.35), transparent 62%),
    linear-gradient(160deg, #14384f 0%, #1f7a6e 50%, #4aa88c 100%);
}
/* 5 电影院：暗夜红丝绒 */
body.scene-5 {
  background:
    radial-gradient(900px 600px at 50% -12%, rgba(255, 90, 110, 0.35), transparent 62%),
    linear-gradient(160deg, #20122e 0%, #4a1a3e 50%, #7a2545 100%);
}
/* 6 全屋总动员：彩虹大杂烩 */
body.scene-6 {
  background:
    radial-gradient(800px 560px at 15% -10%, rgba(255, 140, 220, 0.38), transparent 60%),
    radial-gradient(800px 560px at 85% 0%, rgba(120, 220, 255, 0.35), transparent 60%),
    radial-gradient(900px 700px at -10% 115%, rgba(255, 200, 90, 0.32), transparent 62%),
    linear-gradient(160deg, #241a5e 0%, #45297f 40%, #71389b 70%, #a0458d 100%);
}

/* ---------- 暂存位 ---------- */
.stash-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 2px 0;
}
.stash-label {
  font-size: 12px;
  font-weight: 600;
  opacity: 0.7;
  white-space: nowrap;
}
.stash {
  display: flex;
  gap: 8px;
  flex: 1;
}
.slot {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  border: 2px dashed rgba(255, 255, 255, 0.38);
  background: rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  line-height: 1;
}
.slot.filled {
  border-style: solid;
  border-color: rgba(255, 255, 255, 0.65);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.1)),
    rgba(255, 255, 255, 0.22);
  box-shadow: 0 4px 12px rgba(15, 8, 45, 0.35);
}
.shake {
  animation: shake 0.35s;
}

/* ---------- 场地与物品（点按制：物品不接收事件，命中判定在 game.js） ---------- */
.field {
  position: relative;
  flex: 1;
  margin-top: 12px;
  background:
    radial-gradient(rgba(255, 255, 255, 0.07) 1.2px, transparent 1.3px) 0 0 / 22px 22px,
    rgba(255, 255, 255, 0.05);
  box-shadow: inset 0 2px 14px rgba(15, 8, 45, 0.28);
  touch-action: none;
}
/* 物品 = 品类糖果卡片：釉面渐变 + 白描边 + 高光 */
.item {
  position: absolute;
  transform: translate(-50%, -50%) rotate(var(--rot, 0deg));
  font-size: clamp(36px, 9.5vmin, 62px);
  line-height: 1;
  padding: 0.24em;
  border-radius: 0.34em;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0.08) 45%, rgba(0, 0, 0, 0.06) 100%),
    var(--tint, rgba(255, 255, 255, 0.85));
  border: 2px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 6px 14px rgba(15, 8, 45, 0.38), inset 0 2px 4px rgba(255, 255, 255, 0.6);
  pointer-events: none;
}
.item.drop {
  animation: drop-in 0.42s cubic-bezier(0.22, 0.9, 0.35, 1.25) backwards;
}
.wiggle {
  animation: wiggle 0.3s;
}

/* ---------- 飞行层 ---------- */
.flyer {
  position: fixed;
  z-index: 500;
  pointer-events: none;
  line-height: 1;
  filter: drop-shadow(0 10px 12px rgba(0, 0, 0, 0.3));
  transition: transform 0.34s cubic-bezier(0.5, 0, 0.7, 0.4), opacity 0.34s;
}

/* ---------- 彩带 ---------- */
.confetti-piece {
  position: fixed;
  top: -6vh;
  pointer-events: none;
  z-index: 999;
  animation: fall linear forwards;
}

/* ---------- 动画 ---------- */
.pop-in {
  animation: pop 0.35s;
}
@keyframes pop {
  0% { transform: scale(0.4); }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); }
}
@keyframes starIn {
  from { transform: scale(0) rotate(-90deg); }
}
@keyframes drop-in {
  0% {
    transform: translate(-50%, -150%) rotate(var(--rot, 0deg)) scale(0.4);
    opacity: 0;
  }
  100% {
    transform: translate(-50%, -50%) rotate(var(--rot, 0deg)) scale(1);
    opacity: 1;
  }
}
@keyframes wiggle {
  0%, 100% { transform: translate(-50%, -50%) rotate(var(--rot, 0deg)); }
  25% { transform: translate(-50%, -50%) rotate(calc(var(--rot, 0deg) - 9deg)); }
  75% { transform: translate(-50%, -50%) rotate(calc(var(--rot, 0deg) + 9deg)); }
}
@keyframes doneflash {
  0% { transform: scale(1); }
  50% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
@keyframes fall {
  to { transform: translateY(115vh) rotate(360deg); opacity: 0.6; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}
