/* ============================================================
 * 糖果大冒险 · 消消乐 —— 样式
 * ============================================================ */
:root {
  --c0: #ff6b81;  /* 草莓 */
  --c1: #ffa502;  /* 橙子 */
  --c2: #ffd32a;  /* 柠檬 */
  --c3: #9c88ff;  /* 葡萄 */
  --c4: #2ed573;  /* 奇异果 */
  --c5: #ff7f9c;  /* 西瓜 */
  --ink: #5b4a42;
  --ink-soft: #9b8578;
  --card: #fffdf8;
  --accent: #ff5e78;
  --accent-dark: #e0445f;
  --gold: #ffc931;
  --green: #2ec971;
  --tile-size: 48px;
  --radius: 18px;
}

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

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: linear-gradient(160deg, #fff6e9 0%, #ffe9f2 55%, #e8f4ff 100%);
  color: var(--ink);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

#app { height: 100dvh; height: 100vh; position: relative; }

/* ---------- 屏幕切换 ---------- */
.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen.active { display: flex; }

/* ---------- 通用按钮 ---------- */
.btn {
  border: none; cursor: pointer;
  font-family: inherit; font-weight: 700;
  border-radius: 999px;
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
}
.btn:active { transform: scale(.94); }
.btn-primary {
  background: linear-gradient(180deg, #ff7d92, var(--accent));
  color: #fff; font-size: 19px;
  padding: 14px 46px;
  box-shadow: 0 6px 0 var(--accent-dark), 0 10px 18px rgba(255, 94, 120, .35);
}
.btn-primary:active { box-shadow: 0 2px 0 var(--accent-dark); }
.btn-secondary {
  background: #fff; color: var(--ink);
  font-size: 16px; padding: 12px 34px;
  box-shadow: 0 4px 0 #e8ddd2, 0 8px 14px rgba(120, 100, 90, .15);
  border: 2px solid #f3e7da;
}
.btn-secondary:active { box-shadow: 0 1px 0 #e8ddd2; }
.btn-ghost {
  background: transparent; color: var(--ink-soft);
  font-size: 15px; padding: 10px 22px;
  text-decoration: underline;
  text-underline-offset: 4px;
}
.btn-small {
  background: #fff; color: var(--ink);
  font-size: 14px; padding: 9px 18px;
  border: 2px solid #f0e4d6;
  box-shadow: 0 3px 0 #eadfd0;
}
.btn-icon {
  position: absolute; top: 18px; right: 18px;
  width: 44px; height: 44px; border-radius: 50%;
  background: #fff; font-size: 20px;
  border: 2px solid #f0e4d6;
  box-shadow: 0 3px 0 #eadfd0;
}
.btn-back {
  width: 42px; height: 42px; border-radius: 50%;
  background: #fff; border: 2px solid #f0e4d6;
  box-shadow: 0 3px 0 #eadfd0;
  font-size: 19px; color: var(--ink);
  cursor: pointer; flex: none;
  transition: transform .12s ease;
}
.btn-back:active { transform: scale(.9); }

/* ---------- 首页 ---------- */
#screen-home { justify-content: center; }

.home-deco { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.deco { position: absolute; font-size: 42px; opacity: .55; animation: floaty 7s ease-in-out infinite; }
.deco.d1 { left: 8%;  top: 12%; animation-delay: 0s; }
.deco.d2 { right: 10%; top: 18%; animation-delay: 1.2s; font-size: 36px; }
.deco.d3 { left: 14%; bottom: 20%; animation-delay: 2.1s; font-size: 38px; }
.deco.d4 { right: 8%;  bottom: 14%; animation-delay: .6s; }
.deco.d5 { left: 44%; top: 6%;  animation-delay: 3s; font-size: 30px; }
.deco.d6 { right: 20%; bottom: 34%; animation-delay: 1.8s; font-size: 28px; }
@keyframes floaty {
  0%, 100% { transform: translateY(0) rotate(-6deg); }
  50% { transform: translateY(-22px) rotate(8deg); }
}

.home-card {
  position: relative;
  background: var(--card);
  border-radius: 32px;
  padding: 44px 52px 36px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(160, 120, 100, .22), inset 0 0 0 3px #ffe3ec;
  animation: cardIn .5s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes cardIn { from { transform: scale(.7); opacity: 0; } }

.contest-badge {
  display: inline-block;
  background: linear-gradient(90deg, #ffe3ec, #e3f1ff);
  color: #b05c80;
  font-size: 12px; font-weight: 700;
  padding: 5px 14px; border-radius: 999px;
  margin-bottom: 14px;
  letter-spacing: 1px;
}

.game-title {
  font-size: 52px;
  letter-spacing: 4px;
  background: linear-gradient(180deg, #ff8fab 20%, #ff5e78 60%, #f03e63);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 3px 0 rgba(255, 255, 255, .9));
}
.game-sub {
  margin: 6px 0 26px;
  color: var(--ink-soft);
  font-size: 14px;
  letter-spacing: 3px;
}
.home-btns { display: flex; flex-direction: column; gap: 13px; align-items: center; }

/* ---------- 选关 ---------- */
.topbar {
  width: min(92vw, 480px);
  display: flex; align-items: center; gap: 14px;
  padding: 18px 0 12px;
}
.topbar h2 { font-size: 21px; flex: 1; text-align: center; }
.total-stars { font-size: 15px; color: var(--gold); font-weight: 700; min-width: 44px; text-align: right; }

.level-list {
  width: min(92vw, 480px);
  display: flex; flex-direction: column; gap: 12px;
  overflow-y: auto;
  padding: 6px 2px 20px;
  flex: 1;
}
.level-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: 0 4px 0 #f1e5d8, 0 8px 18px rgba(150, 120, 100, .12);
  border: 2px solid #f7ecdf;
  cursor: pointer;
  transition: transform .12s ease;
}
.level-card:active { transform: scale(.97); }
.level-card.locked { opacity: .55; cursor: not-allowed; }
.level-num {
  width: 52px; height: 52px; border-radius: 16px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 800; color: #fff;
  background: linear-gradient(160deg, #ffb3c0, #ff5e78);
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.12);
}
.level-card.locked .level-num { background: linear-gradient(160deg, #cfc4bb, #a99c92); }
.level-meta { flex: 1; min-width: 0; }
.level-meta h4 { font-size: 16px; }
.level-meta p { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.level-right { text-align: right; flex: none; }
.level-stars { color: #e3d5c4; font-size: 17px; letter-spacing: 2px; }
.level-stars .on { color: var(--gold); text-shadow: 0 0 8px rgba(255, 201, 49, .5); }
.level-best { font-size: 11px; color: var(--ink-soft); margin-top: 3px; }

.btn-reset {
  margin: 4px 0 18px;
  background: none; border: none; cursor: pointer;
  color: #c4b3a5; font-size: 12px;
  text-decoration: underline; text-underline-offset: 3px;
  font-family: inherit;
}

/* ---------- 游戏界面 ---------- */
#screen-game { justify-content: flex-start; }

.game-header {
  width: min(94vw, 480px);
  display: flex; align-items: center; gap: 12px;
  padding: 14px 0 10px;
}
.level-info { flex: 1; min-width: 0; }
.level-name { font-size: 17px; font-weight: 800; }
.objectives { display: flex; gap: 6px; margin-top: 5px; flex-wrap: wrap; }
.obj-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: #fff; border: 1.5px solid #f0e4d6;
  border-radius: 999px;
  font-size: 12px; font-weight: 700;
  padding: 3px 10px;
  color: var(--ink);
}
.obj-chip.done { opacity: .45; text-decoration: line-through; }
.obj-chip .obj-num { color: var(--accent); }

.moves-box {
  flex: none; text-align: center;
  background: #fff; border: 2px solid #f0e4d6;
  border-radius: 16px;
  padding: 7px 13px;
  box-shadow: 0 3px 0 #eadfd0;
}
.moves-box span { display: block; font-size: 24px; font-weight: 800; color: var(--accent); line-height: 1.1; }
.moves-box label { font-size: 10px; color: var(--ink-soft); }
.moves-box.low span { color: #ff3b30; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .45; } }

.score-bar {
  width: min(94vw, 480px);
  display: flex; align-items: center; gap: 12px;
  background: #fff; border: 2px solid #f0e4d6;
  border-radius: 16px;
  padding: 9px 14px;
  box-shadow: 0 3px 0 #eadfd0;
}
.score-info { flex: none; }
.score-label { font-size: 11px; color: var(--ink-soft); display: block; }
.score-value { font-size: 21px; font-weight: 800; }
.progress-area { flex: 1; }
.progress-track {
  position: relative; height: 14px;
  background: #f6ead9; border-radius: 999px;
  overflow: visible;
}
.progress-fill {
  height: 100%; width: 0;
  background: linear-gradient(90deg, #ffd32a, #ff9f43);
  border-radius: 999px;
  transition: width .35s ease;
}
.star-mark {
  position: absolute; top: 50%; transform: translate(-50%, -50%);
  font-size: 13px; color: #d8c8b6;
}
.star-mark.s1 { left: 50%; }
.star-mark.s2 { left: 75%; }
.star-mark.s3 { left: 100%; }
.star-mark.on { color: var(--gold); text-shadow: 0 0 6px rgba(255, 201, 49, .7); }
.target-label { font-size: 11px; color: var(--ink-soft); margin-top: 4px; text-align: center; }

/* ---------- 棋盘 ---------- */
#board-wrap {
  position: relative;
  margin-top: 14px;
  width: min(92vw, 430px, calc(100vh - 320px));
  aspect-ratio: 1;
}
#board {
  position: absolute; inset: 0;
  background: rgba(255, 255, 255, .42);
  border-radius: 22px;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .8), 0 10px 26px rgba(150, 120, 100, .16);
  touch-action: none;
  overflow: hidden;
}
#jelly-layer { position: absolute; inset: 0; pointer-events: none; border-radius: 22px; overflow: hidden; }

.jelly-cell {
  position: absolute;
  width: 12.5%; height: 12.5%;
  padding: 4.5%;
}
.jelly-cell i {
  display: block; width: 100%; height: 100%;
  border-radius: 30%;
  background: rgba(46, 213, 115, .30);
  box-shadow: inset 0 0 0 1.5px rgba(46, 213, 115, .35);
  animation: jellyWobble 2.6s ease-in-out infinite;
}
.jelly-cell.l2 i {
  background: rgba(46, 213, 115, .5);
  box-shadow: inset 0 0 0 2.5px rgba(25, 180, 90, .75);
}
@keyframes jellyWobble {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(.94); }
}

/* ---------- 糖果 ---------- */
.tile {
  position: absolute; left: 0; top: 0;
  width: 12.5%; height: 12.5%;
  transition: transform .24s cubic-bezier(.3, 1.2, .4, 1);
  will-change: transform;
  z-index: 2;
}
.tile-inner {
  position: absolute;
  inset: 4%;
  border-radius: 26%;
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--tile-size) * .46);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .13), inset 0 2px 0 rgba(255, 255, 255, .5), 0 2px 4px rgba(120, 90, 70, .18);
  overflow: hidden;
}
.tile-inner[data-t="0"] { background: linear-gradient(160deg, #ff97ab, var(--c0)); }
.tile-inner[data-t="1"] { background: linear-gradient(160deg, #ffc768, var(--c1)); }
.tile-inner[data-t="2"] { background: linear-gradient(160deg, #ffe57a, var(--c2)); }
.tile-inner[data-t="3"] { background: linear-gradient(160deg, #c3b4ff, var(--c3)); }
.tile-inner[data-t="4"] { background: linear-gradient(160deg, #7bed9f, var(--c4)); }
.tile-inner[data-t="5"] { background: linear-gradient(160deg, #ffb3c6, var(--c5)); }

.tile-inner .face { line-height: 1; filter: drop-shadow(0 1px 1px rgba(0,0,0,.18)); }

/* 冰块覆盖层 */
.tile-inner.iced::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,.62), rgba(178,219,255,.5));
  box-shadow: inset 0 0 0 2px rgba(120,190,255,.95), inset 0 0 12px rgba(255,255,255,.7);
  border-radius: inherit;
}
.tile-inner.iced .face { filter: grayscale(.35) brightness(1.08); }

/* 石块 */
.tile-inner.stone {
  background: linear-gradient(160deg, #b8aca0, #8d7f73);
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.2), inset 0 2px 0 rgba(255,255,255,.35);
  font-size: calc(var(--tile-size) * .42);
}

/* 特殊糖果标识 */
.tile-inner.sp-h::before,
.tile-inner.sp-v::before {
  content: ""; position: absolute; inset: 0;
  pointer-events: none;
}
.tile-inner.sp-h::before {
  background: repeating-linear-gradient(0deg, rgba(255,255,255,.65) 0 16%, transparent 16% 34%);
}
.tile-inner.sp-v::before {
  background: repeating-linear-gradient(90deg, rgba(255,255,255,.65) 0 16%, transparent 16% 34%);
}
.tile-inner.sp-bomb::after {
  content: "💣";
  position: absolute; right: -4%; bottom: -8%;
  font-size: calc(var(--tile-size) * .3);
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.3));
}
.tile-inner.sp-rainbow {
  background: conic-gradient(#ff5e78, #ffa502, #ffd32a, #2ed573, #48dbfb, #9c88ff, #ff5e78) !important;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.15), 0 0 10px rgba(255, 120, 160, .55);
  animation: rainbowSpin 3.2s linear infinite;
}
@keyframes rainbowSpin { to { filter: hue-rotate(360deg); } }
.tile-inner.sp-rainbow .face { filter: drop-shadow(0 0 3px #fff); }

/* 选中 / 提示 / 消除动画 */
.tile.selected { z-index: 5; }
.tile.selected .tile-inner {
  box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--accent), 0 4px 10px rgba(255, 94, 120, .4);
  transform: scale(1.08);
}
.tile.hint .tile-inner { animation: hintPulse .9s ease-in-out infinite; }
@keyframes hintPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.13); filter: brightness(1.15); }
}
.tile.popping { z-index: 4; }
.tile.popping .tile-inner { animation: popOut .24s ease-in forwards; }
@keyframes popOut {
  40% { transform: scale(1.18); }
  100% { transform: scale(0); opacity: 0; }
}
.tile.cracking .tile-inner { animation: crackShake .3s ease; }
@keyframes crackShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-9%) rotate(-4deg); }
  75% { transform: translateX(9%) rotate(4deg); }
}
.tile.spawning .tile-inner { animation: spawnInner .32s cubic-bezier(.2, 1.4, .4, 1) backwards; }
@keyframes spawnInner { from { transform: scale(.2); opacity: 0; } }
.tile.through-spawn .tile-inner { animation: throughIn .34s ease; }
@keyframes throughIn { from { opacity: 0; transform: scale(.3); } }

/* 分数飘字 */
.score-pop {
  position: absolute;
  font-size: 17px; font-weight: 800;
  color: #ff5e78;
  text-shadow: 0 1px 0 #fff, 0 0 8px rgba(255, 255, 255, .9);
  pointer-events: none;
  z-index: 30;
  animation: floatUp .85s ease-out forwards;
}
@keyframes floatUp {
  0% { transform: translate(-50%, -50%) scale(.6); opacity: 0; }
  20% { transform: translate(-50%, -70%) scale(1.15); opacity: 1; }
  100% { transform: translate(-50%, -160%) scale(1); opacity: 0; }
}

/* 横幅 */
#banner {
  position: absolute; left: 50%; top: 38%;
  transform: translate(-50%, -50%);
  font-size: 30px; font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 0 #ff5e78, 0 4px 14px rgba(255, 94, 120, .5);
  pointer-events: none;
  opacity: 0;
  z-index: 40;
  white-space: nowrap;
}
#banner.show { animation: bannerIn 1s ease forwards; }
@keyframes bannerIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.4); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); }
  30% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -64%) scale(1); }
}

/* ---------- 游戏底栏 ---------- */
.game-footer {
  display: flex; gap: 10px;
  margin-top: 14px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(90, 70, 60, .45);
  display: none;
  align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
  backdrop-filter: blur(3px);
}
.modal.show { display: flex; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; } }

.modal-card {
  background: var(--card);
  border-radius: 28px;
  padding: 30px 30px 26px;
  width: min(88vw, 380px);
  text-align: center;
  box-shadow: 0 20px 60px rgba(80, 50, 40, .35), inset 0 0 0 3px #ffe3ec;
  animation: cardIn .38s cubic-bezier(.2, 1.4, .4, 1);
}
.modal-card h3 { font-size: 24px; margin-bottom: 10px; }
.modal-card p { font-size: 14px; color: var(--ink-soft); line-height: 1.7; }
.modal-btns { display: flex; gap: 10px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
.modal-btns .btn-primary { font-size: 16px; padding: 12px 30px; }
.modal-btns .btn-secondary { font-size: 14px; padding: 11px 24px; }
.modal-btns .btn-ghost { font-size: 14px; padding: 11px 18px; }

/* 关卡介绍弹窗 */
.intro-level {
  display: inline-block;
  background: linear-gradient(90deg, #ffe3ec, #e3f1ff);
  color: #b05c80;
  font-size: 12px; font-weight: 700;
  padding: 4px 14px; border-radius: 999px;
  margin-bottom: 10px;
}
.intro-goals { display: flex; gap: 8px; justify-content: center; margin: 14px 0 20px; flex-wrap: wrap; }
.intro-goals .obj-chip { font-size: 13px; padding: 5px 12px; }

/* 过关弹窗 */
.win-crown { font-size: 52px; animation: crownBounce 1.2s ease infinite; }
@keyframes crownBounce { 0%,100% { transform: translateY(0) rotate(-5deg); } 50% { transform: translateY(-9px) rotate(5deg); } }
.stars-row { margin: 10px 0 6px; }
.stars-row .star {
  font-size: 44px; color: #e8dccb;
  margin: 0 6px;
  display: inline-block;
}
.stars-row .star.earned {
  color: var(--gold);
  text-shadow: 0 0 16px rgba(255, 201, 49, .65);
  animation: starPop .5s cubic-bezier(.2, 1.6, .4, 1) backwards;
}
.stars-row .star.earned:nth-child(1) { animation-delay: .15s; }
.stars-row .star.earned:nth-child(2) { animation-delay: .35s; }
.stars-row .star.earned:nth-child(3) { animation-delay: .55s; }
@keyframes starPop { from { transform: scale(0) rotate(-180deg); opacity: 0; } }
.win-score { font-size: 16px; margin-top: 8px; }
.win-score b { font-size: 24px; color: var(--accent); }
.win-bonus { display: block; font-size: 12px; color: var(--green); margin-top: 3px; }

.lose-face { font-size: 52px; }

/* 玩法说明 */
.help-card { text-align: left; }
.help-card h3 { text-align: center; }
.help-list { list-style: none; margin: 6px 0 18px; }
.help-list li {
  font-size: 13px; line-height: 1.55;
  padding: 7px 0 7px 20px;
  position: relative;
  color: #6b5a50;
  border-bottom: 1px dashed #f0e4d6;
}
.help-list li:last-child { border-bottom: none; }
.help-list li::before { content: "🍬"; position: absolute; left: 0; top: 7px; font-size: 12px; }
.help-list b { color: var(--ink); }
.tag { display: inline-block; padding: 0 6px; border-radius: 6px; font-size: 12px; font-weight: 700; }
.tag-rocket { background: #e8f4ff; color: #2e86de; }
.tag-bomb { background: #fdeef0; color: #e0445f; }
.tag-rainbow { background: linear-gradient(90deg, #ffe3ec, #e3f1ff, #e8ffe8); color: #b05c80; }
.help-card .btn-primary { width: 100%; font-size: 16px; padding: 12px; }

/* ---------- 小屏适配 ---------- */
@media (max-height: 700px) {
  .home-card { padding: 32px 40px 28px; }
  .game-title { font-size: 42px; }
  .game-header { padding: 10px 0 8px; }
  #board-wrap { margin-top: 10px; }
  .game-footer { margin-top: 10px; }
}
@media (max-width: 360px) {
  .game-title { font-size: 40px; }
  .btn-primary { font-size: 17px; padding: 13px 36px; }
}
