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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

html { height: 100%; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  overscroll-behavior: none;
  background: #FFD79A;
  color: #7A3E10;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

:root {
  --orange: #FF8A3D;
  --orange-deep: #E96A1E;
  --cream: #FFF7E8;
  --cream-2: #FFE9C0;
  --brown: #7A3E10;
  --brown-soft: #A5672C;
  --gold: #FFC93C;
  --board-w: min(92vw, 430px);
}

@supports (height: 100dvh) {
  :root {
    --board-w: min(92vw, clamp(250px, calc(100dvh - 320px), 430px));
  }
}

/* ---------------- 卡通花园背景 ---------------- */
.scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: #FFD79A;
}

.scene-svg {
  display: block;
  width: 100%;
  height: 100%;
}

.scene-veil {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(78% 52% at 50% 43%, rgba(255, 255, 255, .22), rgba(255, 255, 255, 0) 62%),
    linear-gradient(180deg, rgba(255, 160, 70, .10) 0%, rgba(255, 255, 255, 0) 30%, rgba(255, 248, 232, .12) 68%, rgba(255, 248, 232, .34) 100%);
}

.cloud-a { animation: cloudDrift 26s ease-in-out infinite alternate; }
.cloud-b { animation: cloudDrift 34s ease-in-out infinite alternate-reverse; }

@keyframes cloudDrift {
  from { transform: translateX(-8px); }
  to { transform: translateX(14px); }
}

/* ---------------- 页面骨架 ---------------- */
.game {
  position: relative;
  z-index: 2;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 10px;
  padding: calc(8px + env(safe-area-inset-top)) 16px calc(10px + env(safe-area-inset-bottom));
}

/* ---------------- 顶部计分 ---------------- */
.hud {
  width: min(94vw, 460px);
  display: grid;
  grid-template-columns: 70px 1fr 48px;
  gap: 9px;
  align-items: center;
}

.level-badge {
  position: relative;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: 3px solid #F2A75C;
  background: radial-gradient(circle at 35% 26%, #FFFEF8 0%, #FFEAC6 68%, #FFDFA9 100%);
  box-shadow: 0 4px 0 rgba(178, 96, 33, .34), 0 9px 18px rgba(150, 75, 20, .17), inset 0 2px 0 #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #8A4A16;
}

.level-badge::before,
.level-badge::after {
  content: "";
  position: absolute;
  bottom: 5px;
  width: 18px;
  height: 9px;
  border-radius: 50%;
  background: linear-gradient(180deg, #8ED155, #5CA635);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .4);
}

.level-badge::before { left: -7px; transform: rotate(-30deg); }
.level-badge::after { right: -7px; transform: rotate(30deg); }

.level-cap {
  position: relative;
  z-index: 1;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .14em;
  line-height: 1;
  color: #B47133;
}

.level-num {
  position: relative;
  z-index: 1;
  margin-top: 2px;
  font-size: 27px;
  line-height: .95;
  font-weight: 900;
  color: #7A3E10;
  text-shadow: 0 1px 0 #fff;
}

.level-star {
  position: absolute;
  bottom: 1px;
  left: 50%;
  transform: translateX(-50%);
  width: 14px;
  height: 14px;
  color: #FFB02E;
  filter: drop-shadow(0 1px 0 #fff);
}

.score-card {
  position: relative;
  height: 74px;
  border-radius: 22px;
  border: 3px solid #F2A75C;
  background: linear-gradient(180deg, #FFFEF6 0%, #FFF0CE 62%, #FFE6B4 100%);
  box-shadow: 0 4px 0 rgba(178, 96, 33, .32), 0 10px 20px rgba(150, 75, 20, .16), inset 0 2px 0 #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.score-card::after {
  content: "";
  position: absolute;
  top: 0;
  left: 6%;
  right: 6%;
  height: 46%;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(255, 255, 255, .9), rgba(255, 255, 255, 0));
  pointer-events: none;
}

.score-head {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
  color: #B47133;
}

.score-head .mp-icon {
  width: 13px;
  height: 13px;
  color: #FFB02E;
}

.score-val {
  position: relative;
  z-index: 1;
  margin-top: 1px;
  font-size: 32px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: -.02em;
  color: #7A3E10;
  text-shadow: 0 2px 0 #fff;
  font-variant-numeric: tabular-nums;
}

.score-val.bump { animation: scoreBump .3s ease; }

@keyframes scoreBump {
  0% { transform: scale(1); }
  38% { transform: scale(1.16); color: #EF6C12; }
  100% { transform: scale(1); }
}

.round-btn {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 50%;
  border: 3px solid #E9964A;
  background: linear-gradient(180deg, #FFFAEC, #FFDFA9);
  box-shadow: 0 4px 0 rgba(178, 96, 33, .34), inset 0 2px 0 #fff;
  color: #8A4A16;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform .1s ease, box-shadow .1s ease;
}

.round-btn:active {
  transform: translateY(2px) scale(.97);
  box-shadow: 0 2px 0 rgba(178, 96, 33, .34), inset 0 1px 0 #fff;
}

.round-btn .mp-icon { width: 22px; height: 22px; }

/* ---------------- 步数 / 目标 ---------------- */
.meta {
  width: var(--board-w);
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.moves-pill {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 2px solid #E9A45F;
  background: linear-gradient(180deg, #FFFDF5, #FFE9C0);
  box-shadow: 0 3px 0 rgba(178, 96, 33, .28), inset 0 1px 0 #fff;
}

.moves-pill span { font-size: 11px; font-weight: 700; color: #B47133; }

.moves-pill b {
  font-size: 21px;
  line-height: 1;
  font-weight: 900;
  color: #7A3E10;
  font-variant-numeric: tabular-nums;
}

.goal-pill {
  flex: 1 1 auto;
  min-width: 0;
  padding: 5px 12px 6px;
  border-radius: 16px;
  border: 2px solid #E9A45F;
  background: linear-gradient(180deg, #FFFDF5, #FFE9C0);
  box-shadow: 0 3px 0 rgba(178, 96, 33, .28), inset 0 1px 0 #fff;
}

.goal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  font-weight: 700;
  color: #B47133;
  line-height: 1.25;
}

.goal-head b { color: #8A4A16; font-weight: 900; }

.goal-track {
  position: relative;
  height: 12px;
  margin-top: 2px;
  border-radius: 99px;
  background: #7E4B22;
  box-shadow: inset 0 2px 4px rgba(40, 18, 4, .4);
}

.goal-fill {
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: linear-gradient(180deg, #FFE36A, #FFA51F);
  box-shadow: 0 0 8px rgba(255, 190, 50, .75);
  transition: width .38s cubic-bezier(.2, .8, .3, 1);
}

.goal-star {
  position: absolute;
  top: 50%;
  width: 16px;
  height: 16px;
  transform: translate(-50%, -50%);
  color: #C79A66;
  filter: drop-shadow(0 1px 0 rgba(60, 30, 8, .25));
  transition: color .2s ease, transform .2s ease, filter .2s ease;
}

.goal-star .mp-icon { width: 16px; height: 16px; }
.goal-star[data-at="800"] { left: 38%; }
.goal-star[data-at="1400"] { left: 68%; }
.goal-star[data-at="2000"] { left: 94%; }

.goal-star.lit {
  color: #FFD84D;
  transform: translate(-50%, -50%) scale(1.16);
  filter: drop-shadow(0 2px 0 #C77D0C) drop-shadow(0 0 7px rgba(255, 205, 70, .9));
}

/* ---------------- 棋盘 ---------------- */
.board-shell {
  position: relative;
  width: var(--board-w);
  aspect-ratio: 1 / 1;
  padding: 7px;
  border-radius: 26px;
  border: 2px solid #E5A25C;
  background: linear-gradient(180deg, #FFEBC4 0%, #F8CC8C 54%, #EFB36B 100%);
  box-shadow:
    0 10px 0 rgba(150, 82, 26, .28),
    0 18px 30px rgba(120, 62, 20, .22),
    inset 0 3px 0 rgba(255, 255, 255, .85),
    inset 0 -4px 0 rgba(190, 115, 50, .35);
}

.board-shell::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 23px;
  border: 1px solid rgba(255, 255, 255, .35);
  pointer-events: none;
}

.board {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 19px;
  overflow: hidden;
  touch-action: none;
  background: radial-gradient(120% 100% at 50% 0%, #7B583D 0%, #64452E 56%, #533723 100%);
  box-shadow: inset 0 3px 10px rgba(40, 20, 5, .55), inset 0 -2px 6px rgba(255, 220, 160, .14);
}

.board::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 26%;
  z-index: 8;
  border-radius: 19px 19px 50% 50%;
  background: linear-gradient(180deg, rgba(255, 255, 255, .10), rgba(255, 255, 255, 0));
  pointer-events: none;
}

.tile {
  position: absolute;
  top: 0;
  left: 0;
  padding: 1.5px;
  transition: transform .2s cubic-bezier(.22, .9, .3, 1);
  will-change: transform;
  touch-action: none;
}

.tile .gem {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 7px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .09);
  transition: transform .14s ease, filter .14s ease, opacity .15s ease;
  -webkit-user-drag: none;
  pointer-events: none;
}

.tile.sel { z-index: 6; }

.tile.sel .gem {
  transform: scale(1.07);
  filter: brightness(1.14) saturate(1.08);
  box-shadow: 0 0 0 3px #FFE58A, 0 0 16px 5px rgba(255, 190, 60, .85);
}

.tile.hint .gem { animation: hintPulse 1.3s ease-in-out infinite; }

@keyframes hintPulse {
  0%, 100% { transform: scale(1); filter: brightness(1); }
  50% { transform: scale(1.07); filter: brightness(1.22); }
}

.tile.matched { z-index: 7; }

.tile.matched .gem { animation: gemPop .3s ease-out forwards; }

@keyframes gemPop {
  0% { transform: scale(1); filter: brightness(1); }
  38% { transform: scale(1.2); filter: brightness(1.7) saturate(1.2); }
  100% { transform: scale(.12) rotate(8deg); opacity: 0; filter: brightness(2); }
}

.tile.gone { pointer-events: none; }

.tile.shuffling .gem {
  opacity: 0;
  transform: scale(.4);
}

.tile.repop .gem { animation: gemIn .3s cubic-bezier(.2, 1.3, .4, 1) both; }

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

.tile.shake .gem { animation: gemShake .32s ease; }

@keyframes gemShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px) rotate(-3deg); }
  50% { transform: translateX(3px) rotate(3deg); }
  75% { transform: translateX(-2px); }
}

/* ---------------- 消除特效 ---------------- */
.fx {
  position: absolute;
  inset: 0;
  z-index: 9;
  overflow: hidden;
  pointer-events: none;
}

.float-score {
  position: absolute;
  left: 50%;
  top: 44%;
  transform: translate(-50%, -50%);
  text-align: center;
  white-space: nowrap;
  animation: floatScore 1.1s ease-out forwards;
}

.fs-main {
  display: block;
  font-size: 46px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -.02em;
  color: #FFE15A;
  -webkit-text-stroke: 2px #B6530E;
  text-shadow: 0 3px 0 #98400A, 0 0 20px rgba(255, 225, 120, .95);
}

.fs-sub {
  display: inline-block;
  margin-bottom: 4px;
  padding: 3px 12px;
  border-radius: 99px;
  background: linear-gradient(180deg, #FF9B3D, #F0641A);
  color: #FFF8E8;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .08em;
  box-shadow: 0 2px 0 #B84A0D, 0 0 14px rgba(255, 150, 60, .8);
}

@keyframes floatScore {
  0% { opacity: 0; transform: translate(-50%, -26%) scale(.55); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  30% { transform: translate(-50%, -50%) scale(1); }
  72% { opacity: 1; transform: translate(-50%, -58%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -94%) scale(.95); }
}

.spark {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: radial-gradient(circle, #FFF 0 18%, #FFE06A 40%, rgba(255, 180, 40, 0) 72%);
  transform: translate(-50%, -50%);
  animation: sparkFly .65s ease-out forwards;
}

@keyframes sparkFly {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(.35); }
  55% { opacity: 1; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.15); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(.15); }
}

.board.combo-glow {
  box-shadow:
    inset 0 3px 10px rgba(40, 20, 5, .55),
    inset 0 0 34px rgba(255, 214, 96, .55),
    inset 0 -2px 6px rgba(255, 220, 160, .14);
}

/* ---------------- 底部说明 ---------------- */
.foot {
  width: var(--board-w);
  margin-top: auto;
  padding-top: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tip,
.best {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 99px;
  border: 1px solid rgba(190, 130, 70, .35);
  background: rgba(255, 248, 230, .74);
  color: #7A4A1E;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.tip .mp-icon { width: 14px; height: 14px; color: #F07A1E; }
.best .mp-icon { width: 14px; height: 14px; color: #D99012; }
.best b { color: #7A3E10; font-weight: 900; font-variant-numeric: tabular-nums; }

/* ---------------- 弹层 ---------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(74, 38, 10, .5);
  -webkit-backdrop-filter: blur(7px);
  backdrop-filter: blur(7px);
}

.modal.show { display: flex; animation: fadeIn .2s ease; }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.sheet {
  position: relative;
  width: min(86vw, 360px);
  padding: 22px 20px 20px;
  border-radius: 28px;
  border: 3px solid #F0B36D;
  background: radial-gradient(120% 100% at 50% 0%, #FFFDF4 0%, #FFF0D0 66%, #FFE5B7 100%);
  box-shadow: 0 18px 40px rgba(70, 32, 5, .4), inset 0 2px 0 #fff;
  text-align: center;
  animation: sheetIn .3s cubic-bezier(.2, 1.2, .35, 1);
}

@keyframes sheetIn {
  0% { opacity: 0; transform: translateY(20px) scale(.92); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.sheet-badge {
  width: 62px;
  height: 62px;
  margin: -52px auto 10px;
  border-radius: 50%;
  border: 3px solid #F0B36D;
  background: linear-gradient(180deg, #FFFBEC, #FFE3AE);
  box-shadow: 0 5px 0 rgba(178, 96, 33, .3), inset 0 2px 0 #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #E9822A;
}

.sheet-badge .mp-icon { width: 30px; height: 30px; }

.sheet h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: .02em;
  color: #7A3E10;
  text-shadow: 0 2px 0 #fff;
}

.sheet-sub {
  margin: 7px 0 12px;
  font-size: 13px;
  font-weight: 600;
  color: #A5672C;
}

.sheet-sub b { color: #E96A1E; font-weight: 900; }

.brand {
  margin-bottom: 6px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .2em;
  color: #C58A4A;
}

.result-stars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 6px 0 2px;
}

.result-stars .mp-icon {
  width: 40px;
  height: 40px;
  color: #DCC7A8;
  filter: drop-shadow(0 2px 0 rgba(120, 70, 30, .18));
}

.result-stars .mp-icon.lit {
  color: #FFC62E;
  filter: drop-shadow(0 3px 0 #D98A10) drop-shadow(0 0 12px rgba(255, 200, 60, .9));
  animation: starPop .45s cubic-bezier(.2, 1.4, .4, 1) both;
}

@keyframes starPop {
  0% { transform: scale(.2) rotate(-30deg); opacity: 0; }
  70% { transform: scale(1.2) rotate(4deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.result-score {
  margin-top: 8px;
  padding: 8px 16px;
  border-radius: 18px;
  border: 2px dashed #EBB877;
  background: #FFF4DA;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.result-score span {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .12em;
  color: #A56A2E;
}

.result-score b {
  font-size: 38px;
  line-height: 1.08;
  font-weight: 900;
  color: #EE6C15;
  text-shadow: 0 2px 0 #fff;
  font-variant-numeric: tabular-nums;
}

.result-best {
  margin-top: 7px;
  font-size: 12px;
  font-weight: 600;
  color: #A56A2E;
}

.result-best b { color: #7A3E10; font-weight: 900; }

.btn {
  width: 100%;
  min-height: 50px;
  margin-top: 10px;
  padding: 0 16px;
  border: 0;
  border-radius: 16px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: .02em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  cursor: pointer;
  transition: transform .1s ease, box-shadow .1s ease;
}

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

.btn.primary {
  background: linear-gradient(180deg, #FFA64D, #F9781F);
  color: #FFF9ED;
  box-shadow: 0 4px 0 #C1520C, 0 8px 18px rgba(220, 110, 30, .32), inset 0 2px 0 rgba(255, 255, 255, .38);
  text-shadow: 0 1px 0 rgba(150, 60, 10, .35);
}

.btn.primary:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #C1520C, 0 3px 8px rgba(220, 110, 30, .3);
}

.btn.ghost {
  min-height: 46px;
  font-size: 14px;
  color: #9A5A22;
  background: #FFF6E2;
  box-shadow: 0 3px 0 rgba(190, 130, 70, .3), inset 0 0 0 2px #F0C48D;
}

.btn.ghost:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(190, 130, 70, .3), inset 0 0 0 2px #F0C48D; }

/* ---------------- 提示气泡 ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 19%;
  z-index: 50;
  max-width: 82vw;
  padding: 9px 16px;
  border-radius: 99px;
  background: rgba(60, 32, 10, .86);
  color: #FFF3D6;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, 10px);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}

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

/* ---------------- 小屏适配 ---------------- */
@media (max-height: 700px) {
  .game { gap: 6px; padding-top: 6px; padding-top: calc(6px + env(safe-area-inset-top)); }
  .hud { grid-template-columns: 62px 1fr 44px; gap: 8px; }
  .level-badge { width: 62px; height: 62px; }
  .level-num { font-size: 23px; }
  .score-card { height: 66px; }
  .score-val { font-size: 28px; }
  .round-btn { width: 44px; height: 44px; }
  .foot { padding-top: 2px; }
}

@media (max-width: 350px) {
  .game { padding-left: 12px; padding-right: 12px; }
  .tip span { display: none; }
  .tip { padding: 5px 8px; }
}
