/* 豆格拾光 · 治愈像素拼豆 */
:root {
  --orange: #FF8A3D;
  --orange-deep: #F0731F;
  --orange-soft: #FFE4CF;
  --ink: #4A342A;
  --ink-2: #856957;
  --ink-3: #B0927C;
  --paper: #FFFCF6;
  --cream: #FFF4E4;
  --cream-2: #F6E5CF;
  --line: rgba(126, 88, 58, .12);
  --shadow: 0 14px 30px -18px rgba(126, 80, 42, .45);
  --shadow-soft: 0 8px 20px -14px rgba(126, 80, 42, .4);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: #FFF1DD;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  min-height: 100svh;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

button {
  font-family: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled { cursor: default; }

/* 背景 */
.bg-decor {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(120% 65% at 50% -8%, #FFF9EF 0%, #FFF0DB 46%, #FFE8D2 100%);
}

.bg-decor .blob {
  position: absolute;
  display: block;
  border-radius: 50%;
  filter: blur(2px);
  opacity: .55;
}

.blob-a {
  width: 240px; height: 240px;
  left: -90px; top: 18%;
  background: radial-gradient(circle at 40% 40%, #FFD8B8, rgba(255, 216, 184, 0));
}

.blob-b {
  width: 280px; height: 280px;
  right: -120px; top: 4%;
  background: radial-gradient(circle at 50% 50%, #FFE2C2, rgba(255, 226, 194, 0));
}

.blob-c {
  width: 300px; height: 300px;
  left: 20%; bottom: -160px;
  background: radial-gradient(circle at 50% 50%, #E5F2DF, rgba(229, 242, 223, 0));
}

.dot-grid {
  position: absolute;
  inset: 0;
  display: block;
  background-image: radial-gradient(rgba(255, 138, 61, .13) 1px, transparent 1.2px);
  background-size: 18px 18px;
  mask-image: linear-gradient(180deg, rgba(0,0,0,.55), transparent 78%);
  -webkit-mask-image: linear-gradient(180deg, rgba(0,0,0,.55), transparent 78%);
}

/* 主容器：竖屏铺满，从顶部开始 */
.app {
  --board: clamp(248px, min(calc(100vw - 52px), calc(100vh - 350px)), 420px);
  --board: clamp(248px, min(calc(100vw - 52px), calc(100svh - 350px)), 420px);
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 470px;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  padding: max(8px, var(--safe-top)) 16px max(10px, var(--safe-bottom));
  display: flex;
  flex-direction: column;
}

/* 顶部游戏信息（不是标题栏） */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 42px;
}

.level-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 42px;
  padding: 4px 8px 4px 5px;
  border-radius: 15px;
  background: rgba(255, 253, 248, .88);
  border: 1px solid rgba(255, 255, 255, .9);
  box-shadow: var(--shadow-soft);
  transition: transform .14s ease, box-shadow .14s ease;
}

.level-chip:active { transform: scale(.97); }

.level-mini {
  width: 32px;
  height: 32px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: #FFE8D4;
  color: var(--orange-deep);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .8), 0 2px 5px rgba(240, 115, 31, .1);
}

.level-mini .mp-icon { width: 19px; height: 19px; }

.level-chip-text {
  display: flex;
  flex-direction: column;
  line-height: 1.12;
  min-width: 54px;
}

.level-chip-text b {
  font-size: 12px;
  letter-spacing: .02em;
  font-weight: 800;
  color: var(--ink);
}

.level-chip-text small {
  margin-top: 2px;
  font-size: 10px;
  color: var(--ink-3);
  font-weight: 600;
  letter-spacing: .03em;
}

.chip-caret {
  width: 16px !important;
  height: 16px !important;
  color: #C9A98D;
  margin-left: 1px;
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.round-btn {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: rgba(255, 253, 248, .9);
  border: 1px solid rgba(255, 255, 255, .95);
  box-shadow: var(--shadow-soft);
  color: #A58066;
  transition: transform .14s ease, background .14s ease;
}

.round-btn:active { transform: scale(.94); background: #FFF1E1; }
.round-btn .mp-icon { width: 20px; height: 20px; }

.timer {
  height: 40px;
  min-width: 92px;
  padding: 0 11px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: rgba(255, 253, 248, .92);
  border: 1px solid rgba(255, 255, 255, .95);
  box-shadow: var(--shadow-soft);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: .04em;
  transition: background .25s ease, color .25s ease;
}

.timer .mp-icon { width: 17px; height: 17px; color: var(--orange); }
.timer.warn {
  color: #DD4E39;
  background: #FFF1EC;
  border-color: #FFD3C7;
  animation: timer-pulse 1s ease-in-out infinite;
}
.timer.warn .mp-icon { color: #DD4E39; }

@keyframes timer-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.035); }
}

/* 进度 */
.progress {
  margin: 9px 3px 7px;
}

.progress-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 5px;
  font-size: 10.5px;
  color: var(--ink-3);
  letter-spacing: .05em;
}

.progress-top b {
  font-size: 10.5px;
  color: var(--ink-2);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}

.progress-track {
  height: 7px;
  border-radius: 99px;
  background: rgba(255, 255, 255, .72);
  box-shadow: inset 0 1px 3px rgba(140, 95, 60, .12);
  overflow: hidden;
  position: relative;
}

.progress-fill,
#progressFill {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #FFC16F, #FF8A3D 58%, #FF7432);
  box-shadow: 0 0 8px rgba(255, 138, 61, .5);
  transition: width .35s cubic-bezier(.3, .9, .3, 1);
  position: relative;
}

#progressFill::after {
  content: "";
  position: absolute;
  right: 0;
  top: 50%;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  transform: translate(0, -50%);
  background: #FFDEC4;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .85);
  opacity: 0;
  transition: opacity .3s;
}

#progressFill[style*="width:"]::after { opacity: .95; }

/* 棋盘卡片 */
.board-card {
  position: relative;
  margin-top: 3px;
  padding: 8px 9px 10px;
  border-radius: 25px;
  background: linear-gradient(180deg, #FFFDF8 0%, #FFF8EE 100%);
  border: 1px solid rgba(255, 255, 255, .95);
  box-shadow:
    0 18px 34px -22px rgba(126, 80, 42, .55),
    0 4px 10px -6px rgba(126, 80, 42, .15),
    inset 0 1px 0 rgba(255, 255, 255, .9);
}

.board-hint {
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 10.5px;
  color: #AD8C73;
  letter-spacing: .02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.board-hint .mp-icon {
  width: 13px;
  height: 13px;
  color: #D0A98B;
  flex: 0 0 auto;
}

.board-stage {
  position: relative;
  width: var(--board, 340px);
  height: var(--board, 340px);
  max-width: 100%;
  margin: 0 auto;
}

.board {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 7px;
  border-radius: 18px;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  gap: 3px;
  background:
    radial-gradient(rgba(255, 255, 255, .38) 1px, transparent 1.2px) 0 0 / 9px 9px,
    linear-gradient(180deg, #F0DCC2, #F6E6D1);
  box-shadow:
    inset 0 3px 8px rgba(122, 78, 40, .2),
    inset 0 -1px 0 rgba(255, 255, 255, .7);
  overflow: hidden;
}

/* 格子 */
.cell {
  position: relative;
  appearance: none;
  -webkit-appearance: none;
  border-radius: 25%;
  background: #F8EAD8;
  box-shadow:
    inset 0 1px 2px rgba(123, 80, 44, .13),
    inset 0 -1px 1px rgba(255, 255, 255, .55);
  overflow: hidden;
  transition: transform .14s ease, box-shadow .18s ease;
  padding: 0;
  border: 0;
}

.cell::before {
  content: "";
  position: absolute;
  inset: 1px;
  border-radius: 24%;
  background: var(--t, #F0DEC6);
  opacity: .2;
  transition: opacity .2s ease;
}

.cell::after {
  content: "";
  position: absolute;
  inset: 13%;
  border-radius: 28%;
  border: 1.5px dashed rgba(255, 255, 255, .68);
  opacity: 0;
  transition: opacity .2s ease;
}

.cell.empty::after { opacity: 1; }
.cell.empty::before { opacity: .46; }

.cell .bead {
  position: absolute;
  inset: 11%;
  border-radius: 31%;
  background:
    radial-gradient(circle at 31% 23%, rgba(255, 255, 255, .62) 0%, rgba(255, 255, 255, 0) 38%),
    linear-gradient(152deg, rgba(255, 255, 255, .22) 0%, rgba(255, 255, 255, 0) 42%, rgba(0, 0, 0, .1) 100%),
    var(--c, #E7C7A9);
  box-shadow:
    inset 0 -2px 3px rgba(70, 38, 20, .18),
    inset 0 1px 1px rgba(255, 255, 255, .5),
    0 2px 4px rgba(100, 62, 32, .18);
  transition: inset .18s ease, transform .18s cubic-bezier(.2, .8, .3, 1.3), opacity .12s;
  z-index: 1;
}

.cell .bead::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 23%;
  height: 23%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(76, 47, 27, .17);
  box-shadow:
    inset 0 1px 2px rgba(40, 20, 10, .28),
    0 1px 0 rgba(255, 255, 255, .26);
}

.cell.empty .bead { opacity: 0; transform: scale(.55); }

/* 目标颜色小点：错位豆子的方向提示 */
.target-dot {
  position: absolute;
  right: 7%;
  bottom: 7%;
  width: 17%;
  height: 17%;
  border-radius: 50%;
  background: var(--t, #E9D3B8);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .85), 0 1px 2px rgba(80, 45, 20, .18);
  z-index: 2;
  opacity: .92;
  transition: opacity .2s ease, transform .2s ease;
}

.cell.empty .target-dot {
  right: auto;
  bottom: auto;
  left: 50%;
  top: 50%;
  width: 22%;
  height: 22%;
  transform: translate(-50%, -50%);
  opacity: .8;
}

.cell.locked::before { opacity: .82; }
.cell.locked::after { opacity: 0; }
.cell.locked .target-dot { opacity: 0; }
.cell.locked .bead {
  inset: 5%;
  border-radius: 27%;
  box-shadow:
    inset 0 -1px 2px rgba(70, 38, 20, .13),
    inset 0 1px 1px rgba(255, 255, 255, .55),
    0 0 0 1px rgba(255, 255, 255, .35),
    0 1px 3px rgba(90, 55, 30, .14);
}
.cell.locked .bead::after { opacity: .32; }

.cell.locked .bead::before {
  content: "";
  position: absolute;
  left: 16%;
  top: 13%;
  width: 30%;
  height: 18%;
  border-radius: 50%;
  background: rgba(255, 255, 255, .42);
  transform: rotate(-25deg);
  filter: blur(.4px);
}

.cell:active:not(.locked):not(.empty) .bead { transform: scale(.9); }

.cell.placeable::after {
  border-color: rgba(255, 138, 61, .6);
  animation: dash-glow 1.4s ease-in-out infinite;
}

@keyframes dash-glow {
  0%, 100% { opacity: .35; }
  50% { opacity: 1; }
}

.cell.just-locked .bead { animation: bead-lock .42s cubic-bezier(.2, .9, .3, 1.25); }
@keyframes bead-lock {
  0% { transform: scale(1); }
  40% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

.cell.picked .bead { animation: bead-out .18s ease forwards; }
@keyframes bead-out {
  to { transform: scale(.2) rotate(8deg); opacity: 0; }
}

.cell.bad-drop { animation: cell-shake .3s ease; }
@keyframes cell-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  60% { transform: translateX(3px); }
}

.cell.flash::before { animation: target-flash .5s ease; }
@keyframes target-flash {
  0% { opacity: .2; }
  40% { opacity: 1; }
  100% { opacity: .2; }
}

/* 开始浮层 */
.start-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  border-radius: 18px;
  display: block;
  text-align: center;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(255, 255, 255, .96), rgba(255, 246, 234, .95) 62%, rgba(255, 239, 221, .97));
  transition: opacity .24s ease, visibility .24s ease;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.start-overlay::-webkit-scrollbar { display: none; }

.start-overlay::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255, 138, 61, .12) 1px, transparent 1.2px);
  background-size: 14px 14px;
  mask-image: radial-gradient(circle at 50% 40%, #000 0%, transparent 72%);
  -webkit-mask-image: radial-gradient(circle at 50% 40%, #000 0%, transparent 72%);
  pointer-events: none;
}

.start-overlay.hide {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.start-inner {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 100%;
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.logo-beads {
  display: grid;
  grid-template-columns: repeat(5, 9px);
  grid-template-rows: repeat(5, 9px);
  gap: 2px;
  transform: rotate(-4deg);
  filter: drop-shadow(0 5px 6px rgba(214, 122, 55, .22));
  animation: logo-float 3.4s ease-in-out infinite;
}

.logo-beads i {
  display: block;
  border-radius: 3px;
  box-shadow: inset 0 -1px 1px rgba(0, 0, 0, .14), inset 0 1px 0 rgba(255, 255, 255, .4);
}

@keyframes logo-float {
  0%, 100% { transform: rotate(-4deg) translateY(0); }
  50% { transform: rotate(-2deg) translateY(-4px); }
}

.start-kicker {
  margin-top: 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .14em;
  color: #B48D70;
}

.start-title {
  margin: 4px 0 3px;
  font-size: 30px;
  line-height: 1.1;
  font-weight: 900;
  letter-spacing: .06em;
  color: #493126;
  text-shadow: 0 2px 0 rgba(255, 255, 255, .85);
}

.start-desc {
  margin: 0;
  font-size: 12px;
  color: #8E6C55;
  letter-spacing: .02em;
}

.start-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 10px 0 6px;
  font-size: 10px;
  color: #A9866C;
  font-weight: 600;
}

.start-legend {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 0 0 11px;
  font-size: 9.5px;
  color: #B08D73;
  font-weight: 600;
  letter-spacing: .02em;
}

.legend-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #FF9B62;
  box-shadow: 0 0 0 1.5px #fff, 0 1px 2px rgba(120, 70, 30, .22);
  flex: 0 0 auto;
}

.step-line {
  width: 9px;
  height: 1.5px;
  border-radius: 2px;
  background: #DFC4AB;
  display: block;
}

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 999px;
  font-weight: 800;
  transition: transform .13s ease, box-shadow .13s ease, filter .13s ease;
}

.btn:active { transform: translateY(1px) scale(.975); }

.btn-primary {
  color: #fff;
  background: linear-gradient(180deg, #FFAA6B 0%, #FF8A3D 46%, #FB7525 100%);
  box-shadow:
    0 10px 20px -8px rgba(238, 108, 28, .65),
    inset 0 1px 0 rgba(255, 255, 255, .4);
}

.btn-primary:active { box-shadow: 0 5px 12px -6px rgba(238, 108, 28, .6); }

.btn-start {
  width: 172px;
  height: 46px;
  font-size: 15px;
  letter-spacing: .06em;
}

.btn-start .mp-icon { width: 19px; height: 19px; }

.btn-text {
  margin-top: 8px;
  padding: 6px 10px;
  font-size: 11px;
  color: #B57F58;
  font-weight: 700;
  border-radius: 99px;
  transition: background .15s ease, transform .13s ease;
}

.btn-text:active { background: rgba(255, 138, 61, .08); transform: scale(.97); }

.start-best {
  margin-top: 7px;
  padding: 4px 10px;
  border-radius: 99px;
  background: rgba(255, 229, 205, .72);
  color: #B08260;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: .03em;
}

/* 区域消除提示 */
.region-hint {
  display: inline-flex;
  align-items: center;
  position: absolute;
  left: 50%;
  bottom: 9px;
  transform: translateX(-50%) translateY(8px);
  z-index: 6;
  padding: 6px 13px;
  border-radius: 99px;
  background: rgba(74, 52, 42, .9);
  color: #FFF7ED;
  font-size: 10.5px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}

.region-hint.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.region-hint .mp-icon { width: 13px; height: 13px; margin-right: 4px; color: #FFC590; }

/* 暂存槽 */
.tray-card {
  position: relative;
  margin-top: 8px;
  transition: opacity .22s ease, filter .22s ease;
  padding: 9px 12px 11px;
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(255, 253, 248, .97), rgba(255, 249, 240, .97));
  border: 1px solid rgba(255, 255, 255, .95);
  box-shadow: var(--shadow);
}

.tray-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 22px;
}

.tray-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: .03em;
}

.tray-title b.full {
  background: #FFE1D7;
  color: #D94E36;
}

.tray-title b {
  font-size: 9.5px;
  font-weight: 800;
  color: var(--orange-deep);
  background: var(--orange-soft);
  border-radius: 99px;
  padding: 3px 8px;
  font-variant-numeric: tabular-nums;
}

.expand-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 27px;
  padding: 0 9px;
  border-radius: 99px;
  background: #FFF1E3;
  color: #D96E24;
  font-size: 10px;
  font-weight: 800;
  border: 1px solid #FFE0C7;
  transition: transform .13s ease, background .15s ease;
}

.expand-btn .mp-icon { width: 13px; height: 13px; }
.expand-btn:active { transform: scale(.95); background: #FFE8D4; }
.expand-btn:disabled { color: #C3AA95; background: #F8EEE3; border-color: #F0E2D3; }

.tray {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  align-content: center;
  gap: 6px;
  margin-top: 8px;
  min-height: 42px;
}

.tray.many { gap: 4px; }

.slot {
  position: relative;
  flex: 1 1 0;
  width: auto;
  max-width: 42px;
  min-width: 0;
  aspect-ratio: 1 / 1;
  height: auto;
  border-radius: 14px;
  background: #F6E6D1;
  box-shadow:
    inset 0 2px 4px rgba(124, 80, 44, .16),
    inset 0 -1px 0 rgba(255, 255, 255, .55);
  transition: transform .15s ease, box-shadow .18s ease;
  overflow: hidden;
}

.slot::before {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 10px;
  border: 1.5px dashed rgba(255, 255, 255, .72);
  opacity: .85;
}

.slot:active { transform: scale(.94); }

.slot .bead {
  position: absolute;
  inset: 4px;
  border-radius: 11px;
  background:
    radial-gradient(circle at 31% 23%, rgba(255, 255, 255, .62) 0%, rgba(255, 255, 255, 0) 38%),
    linear-gradient(152deg, rgba(255, 255, 255, .22), rgba(0, 0, 0, .1)),
    var(--c, #E7C7A9);
  box-shadow:
    inset 0 -2px 3px rgba(70, 38, 20, .18),
    inset 0 1px 1px rgba(255, 255, 255, .5),
    0 2px 4px rgba(100, 62, 32, .16);
  z-index: 1;
  animation: slot-pop .22s cubic-bezier(.2, .9, .3, 1.25);
}

.slot .bead::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 24%;
  height: 24%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(76, 47, 27, .17);
  box-shadow: inset 0 1px 2px rgba(40, 20, 10, .28), 0 1px 0 rgba(255, 255, 255, .25);
}

@keyframes slot-pop {
  0% { transform: scale(.4); }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.slot.active {
  transform: translateY(-2px);
  box-shadow:
    0 0 0 2px #FF8A3D,
    0 0 0 5px rgba(255, 138, 61, .16),
    0 6px 12px -6px rgba(200, 100, 30, .5);
}

.slot.active .bead { inset: 3px; border-radius: 12px; }
.slot.empty { opacity: .72; }

.slot.slot-shake { animation: slot-shake .35s ease; }
@keyframes slot-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  45% { transform: translateX(4px); }
  70% { transform: translateX(-2px); }
}

.tray-full {
  animation: tray-alert .4s ease;
}

@keyframes tray-alert {
  0%, 100% { box-shadow: var(--shadow); }
  40% { box-shadow: 0 0 0 2px rgba(221, 78, 57, .45), var(--shadow); }
}

/* 三个广告道具 */
.tray-card.dim { opacity: .62; filter: saturate(.82); }

.tools {
  display: grid;
  transition: opacity .22s ease, filter .22s ease;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.tool {
  position: relative;
  height: 68px;
  border-radius: 18px;
  background: linear-gradient(180deg, #FFFDF8 0%, #FFF8EE 100%);
  border: 1px solid rgba(255, 255, 255, .95);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: transform .14s ease, box-shadow .18s ease, border-color .18s ease;
  overflow: hidden;
}

.tool::after {
  content: "AD";
  position: absolute;
  right: 7px;
  top: 6px;
  font-size: 7px;
  font-weight: 900;
  letter-spacing: .04em;
  color: #C49B7D;
  background: #F8EADB;
  border-radius: 4px;
  padding: 1px 3px;
  line-height: 1.2;
}

.tool:active { transform: scale(.955); }

.tool-ico {
  width: 27px;
  height: 27px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  margin-bottom: 1px;
}

.tool-ico .mp-icon { width: 17px; height: 17px; }

.tool-area .tool-ico { background: #FFE7D3; color: #E97A2E; }
.tool-clear .tool-ico { background: #DFF3E7; color: #3F9B6D; }
.tool-random .tool-ico { background: #E9E9FF; color: #6D6ADB; }

.tool-name {
  font-size: 11.5px;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: .02em;
  line-height: 1.2;
}

.tool-sub {
  font-size: 8.5px;
  color: #B59880;
  font-weight: 600;
  letter-spacing: .04em;
  line-height: 1.2;
}

.tool.armed {
  border-color: #FFB07B;
  box-shadow:
    0 0 0 2px rgba(255, 138, 61, .18),
    0 10px 20px -12px rgba(240, 110, 30, .6);
  background: linear-gradient(180deg, #FFF9F2, #FFF1E2);
}

.tool.armed .tool-sub { color: var(--orange-deep); }
.tool.armed .tool-ico { animation: tool-pulse 1.3s ease-in-out infinite; }
@keyframes tool-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.tool.locked { opacity: .55; }
.tools.dim { opacity: .7; filter: saturate(.85); }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + var(--safe-bottom));
  transform: translateX(-50%) translateY(10px);
  z-index: 130;
  max-width: 82vw;
  padding: 9px 16px;
  border-radius: 99px;
  background: rgba(63, 42, 31, .93);
  color: #FFF9F1;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 10px 24px -8px rgba(50, 30, 20, .5);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* 弹层 */
.layer {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 18px calc(20px + var(--safe-bottom));
  opacity: 0;
  transition: opacity .22s ease;
}

.layer[hidden] { display: none; }
.layer.show { opacity: 1; }

.layer-bg {
  position: absolute;
  inset: 0;
  background: rgba(54, 34, 22, .42);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.layer-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 352px;
  transform: translateY(14px) scale(.985);
  transition: transform .24s cubic-bezier(.2, .9, .3, 1.1);
}

.layer.show .layer-card { transform: translateY(0) scale(1); }

.layer.sheet-mode {
  align-items: flex-end;
  padding: 0;
}

.layer-card.sheet {
  max-width: 500px;
  max-height: 88svh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 26px 26px 0 0;
  padding: 18px 16px calc(18px + var(--safe-bottom));
  background: #FFF9F0;
  box-shadow: 0 -20px 50px -20px rgba(60, 35, 20, .4);
}

.layer-card.sheet .sheet-grab {
  width: 38px;
  height: 4px;
  border-radius: 99px;
  background: #E7D4BF;
  margin: -7px auto 12px;
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 13px;
}

.sheet-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 900;
  color: var(--ink);
  letter-spacing: .03em;
}

.sheet-head p {
  margin: 3px 0 0;
  font-size: 10.5px;
  color: var(--ink-3);
}

.close-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #F6E9DA;
  color: #A78368;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
.close-btn .mp-icon { width: 16px; height: 16px; }
.close-btn:active { transform: scale(.93); }

/* 选关 */
.level-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.level-item {
  position: relative;
  padding: 5px 5px 7px;
  border-radius: 14px;
  background: #FFFDF8;
  border: 1.5px solid #F3E3D0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: transform .14s ease, border-color .18s ease, box-shadow .18s ease;
}

.level-item:active { transform: scale(.96); }

.level-item.current {
  border-color: #FFB37D;
  box-shadow: 0 0 0 2px rgba(255, 138, 61, .13);
}

.level-item.locked { opacity: .72; }
.level-item.locked .mini-frame { filter: grayscale(.55) blur(.6px); opacity: .55; }

.mini-frame {
  position: relative;
  width: 100%;
  height: 0;
  padding-bottom: 100%;
  border-radius: 9px;
  overflow: hidden;
  background: #F6E8D7;
}

.mini-frame .mini {
  position: absolute;
  inset: 0;
}

.mini {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  width: 100%;
  height: 100%;
}

.mini i { display: block; width: 100%; height: 100%; }

.level-item .level-name {
  font-size: 9.5px;
  font-weight: 800;
  color: #745644;
  line-height: 1.2;
  white-space: nowrap;
}

.level-item .level-stars {
  display: flex;
  gap: 0;
  height: 9px;
  align-items: center;
}

.level-item .level-stars .mp-icon {
  width: 9px;
  height: 9px;
  color: #FFB13B;
}

.level-item .level-stars .mp-icon.off { color: #EADBC9; }

.level-item .lock-badge {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -62%);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(74, 52, 42, .78);
  color: #FFF6EA;
  display: grid;
  place-items: center;
  z-index: 2;
}

.level-item .lock-badge .mp-icon { width: 13px; height: 13px; }

.level-item .current-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #FF8A3D;
  box-shadow: 0 0 0 2px #FFFDF8;
}

/* 通用对话框 */
.dialog {
  background: linear-gradient(180deg, #FFFCF7, #FFF6EA);
  border-radius: 27px;
  max-height: calc(100svh - 34px);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 22px 20px 18px;
  box-shadow: 0 26px 60px -24px rgba(50, 28, 16, .55), inset 0 1px 0 rgba(255, 255, 255, .9);
  border: 1px solid rgba(255, 255, 255, .9);
  text-align: center;
  position: relative;
}

.dialog::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background-image: radial-gradient(rgba(255, 138, 61, .1) 1px, transparent 1.2px);
  background-size: 15px 15px;
  mask-image: radial-gradient(circle at 50% 0%, #000, transparent 70%);
  -webkit-mask-image: radial-gradient(circle at 50% 0%, #000, transparent 70%);
  pointer-events: none;
}

.dialog > * { position: relative; z-index: 1; }

.dialog-badge {
  width: 54px;
  height: 54px;
  margin: 0 auto 10px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #FFE8D5, #FFD9BC);
  color: #E9772B;
  box-shadow: 0 8px 16px -8px rgba(233, 119, 43, .55), inset 0 1px 0 rgba(255, 255, 255, .7);
}

.dialog-badge .mp-icon { width: 27px; height: 27px; }
.dialog-badge.green { background: linear-gradient(180deg, #E2F4E9, #CBEBD9); color: #3F9B6D; box-shadow: 0 8px 16px -8px rgba(63, 155, 109, .45); }
.dialog-badge.purple { background: linear-gradient(180deg, #EBEBFF, #DCDBFF); color: #6D6ADB; box-shadow: 0 8px 16px -8px rgba(109, 106, 219, .45); }

.dialog h2 {
  margin: 0 0 6px;
  font-size: 21px;
  font-weight: 900;
  color: var(--ink);
  letter-spacing: .03em;
}

.dialog .dialog-sub {
  margin: 0 auto;
  max-width: 260px;
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--ink-2);
}

.dialog .btn-main {
  width: 100%;
  height: 46px;
  margin-top: 15px;
  font-size: 14px;
  letter-spacing: .04em;
}

.dialog .btn-main .mp-icon { width: 18px; height: 18px; }

.dialog .btn-ghost {
  width: 100%;
  height: 42px;
  margin-top: 8px;
  border-radius: 99px;
  background: #F7EADB;
  color: #9A7255;
  font-size: 12px;
  font-weight: 800;
  transition: transform .13s ease, background .15s ease;
}

.dialog .btn-ghost:active { transform: scale(.975); background: #F2E0CC; }

.dialog .btn-text { margin-top: 7px; }

.dialog .close-x {
  position: absolute;
  right: 12px;
  top: 12px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #F7EADC;
  color: #A98569;
  display: grid;
  place-items: center;
}

.dialog .close-x .mp-icon { width: 16px; height: 16px; }

/* 胜利 / 失败 */
.result-preview {
  width: 116px;
  height: 116px;
  margin: 0 auto 10px;
  border-radius: 20px;
  padding: 7px;
  background: #F6E6D2;
  box-shadow: inset 0 2px 6px rgba(120, 78, 40, .18), 0 8px 18px -10px rgba(120, 78, 40, .4);
}

.result-preview .mini { border-radius: 12px; overflow: hidden; box-shadow: 0 2px 6px rgba(90, 55, 30, .12); }

.result-kicker {
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: .16em;
  color: #C39A79;
  margin-bottom: 3px;
}

.stars {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 5px;
  margin: 9px 0 4px;
  min-height: 30px;
}

.stars .mp-icon {
  width: 27px;
  height: 27px;
  color: #FFB13B;
  filter: drop-shadow(0 3px 4px rgba(230, 150, 30, .3));
  animation: star-in .4s cubic-bezier(.2, .9, .3, 1.3) both;
}

.stars .mp-icon.off { color: #EADBC9; filter: none; }
.stars .mp-icon:nth-child(2) { animation-delay: .08s; }
.stars .mp-icon:nth-child(3) { animation-delay: .16s; }

@keyframes star-in {
  0% { transform: scale(.3) rotate(-20deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.stat-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
}

.stat-pill {
  min-width: 88px;
  padding: 7px 10px;
  border-radius: 12px;
  background: #FFF8EF;
  border: 1px solid #F3E2CF;
}

.stat-pill small {
  display: block;
  font-size: 8.5px;
  color: #B3957C;
  letter-spacing: .08em;
  margin-bottom: 2px;
}

.stat-pill b {
  font-size: 14px;
  color: #5B3E2C;
  font-variant-numeric: tabular-nums;
  letter-spacing: .03em;
}

.record-pill {
  display: inline-block;
  vertical-align: middle;
  margin-left: 5px;
  padding: 3px 7px;
  border-radius: 99px;
  background: #FFE5D0;
  color: #D96E24;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .06em;
}

.result-tip {
  margin: 9px 0 0;
  font-size: 10.5px;
  color: #A9866B;
  line-height: 1.6;
}

/* 3 步规则 */
.howto {
  margin: 12px 0 2px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  text-align: left;
}

.howto-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 13px;
  background: #FFF8EF;
  border: 1px solid #F5E6D5;
}

.howto-row b {
  flex: 0 0 auto;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #FFE6D1;
  color: #E9772B;
  font-size: 9.5px;
  font-weight: 900;
}

.howto-row span {
  font-size: 10.5px;
  line-height: 1.45;
  color: #80624E;
}

/* 广告 */
.ad-screen {
  position: relative;
  height: 92px;
  border-radius: 18px;
  margin-bottom: 12px;
  overflow: hidden;
  background:
    radial-gradient(circle at 22% 28%, rgba(255, 255, 255, .18), transparent 40%),
    linear-gradient(135deg, #3D2E55 0%, #5B4280 52%, #7B568F 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  color: #FDF8FF;
}

.ad-screen .mp-icon { width: 26px; height: 26px; opacity: .92; }

.ad-screen span {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .12em;
  opacity: .92;
}

.ad-screen::after {
  content: "";
  position: absolute;
  top: -40%;
  left: -35%;
  width: 36%;
  height: 180%;
  transform: rotate(20deg);
  background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, .22), rgba(255, 255, 255, 0));
  animation: ad-shine 2.4s ease-in-out infinite;
}

@keyframes ad-shine {
  0% { left: -40%; }
  55%, 100% { left: 130%; }
}

.ad-progress {
  height: 7px;
  border-radius: 99px;
  background: #F2E2CF;
  overflow: hidden;
  margin: 0 2px;
}

.ad-progress i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #FFC16F, #FF8A3D);
  transition: width 2.6s linear;
}

.ad-tip {
  margin: 10px 0 0;
  font-size: 10px;
  color: #B08E74;
}

.spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .32);
  border-top-color: #fff;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* 撒花 & 飞豆 */
.fx {
  position: fixed;
  inset: 0;
  z-index: 110;
  pointer-events: none;
  overflow: hidden;
}

.confetti {
  position: absolute;
  top: -24px;
  width: 9px;
  height: 9px;
  border-radius: 2.5px;
  animation: confetti-fall linear forwards;
  box-shadow: inset 0 -1px 1px rgba(0, 0, 0, .12), inset 0 1px 0 rgba(255, 255, 255, .35);
}

@keyframes confetti-fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(112vh) rotate(620deg); opacity: .9; }
}

.fly-bead {
  position: fixed;
  z-index: 120;
  pointer-events: none;
  border-radius: 30%;
  box-shadow:
    inset 0 -2px 3px rgba(70, 38, 20, .18),
    inset 0 1px 1px rgba(255, 255, 255, .5),
    0 4px 10px rgba(90, 55, 30, .25);
  background:
    radial-gradient(circle at 31% 23%, rgba(255, 255, 255, .62), rgba(255, 255, 255, 0) 38%),
    var(--c, #E7C7A9);
}

/* 底部安全 */
@supports (padding: max(0px)) {
  .app { padding-top: max(8px, env(safe-area-inset-top)); }
}

/* 小屏适配 */
@media (max-height: 720px) {
  .start-inner { padding: 4px 14px; }
  .logo-beads { grid-template-columns: repeat(5, 8px); grid-template-rows: repeat(5, 8px); }
  .start-title { font-size: 26px; }
  .start-desc { font-size: 11px; }
  .start-steps { margin: 7px 0 9px; }
  .btn-start { height: 42px; width: 160px; font-size: 14px; }
  .start-best { margin-top: 4px; }
  .board-hint { height: 20px; }
  .tool { height: 64px; }
}

@media (max-height: 640px) {
  .start-inner { padding: 6px 12px; }
  .start-kicker { display: none; }
  .start-desc { display: none; }
  .start-title { font-size: 23px; margin: 3px 0 4px; }
  .logo-beads { grid-template-columns: repeat(5, 7px); grid-template-rows: repeat(5, 7px); gap: 1.5px; }
  .start-steps { margin: 5px 0 3px; font-size: 9px; }
  .start-legend { display: none; }
  .btn-start { height: 38px; width: 150px; font-size: 13px; }
  .start-best { margin-top: 3px; }
  .board-hint { display: none; }
}

@media (max-width: 360px) {
  .app { padding-left: 12px; padding-right: 12px; }
  .timer { min-width: 84px; font-size: 14.5px; padding: 0 8px; }
  .round-btn { width: 38px; height: 38px; }
  .level-chip { height: 40px; }
  .level-mini { width: 30px; height: 30px; }
  .tool-name { font-size: 10.5px; }
  .tool-sub { font-size: 8px; }
}

@media (min-width: 430px) {
  .start-title { font-size: 33px; }
  .tool { height: 72px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
