* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  background: #ffe3bc;
  color: #4a2b14;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

img {
  display: block;
}

/* ---------- illustrated background ---------- */

.bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: linear-gradient(180deg, #ffd9a5 0%, #ffeacd 52%, #f6e5bb 100%);
}

.bg img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ambient {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
}

.petal {
  position: absolute;
  width: 12px;
  height: 8px;
  border-radius: 10px 2px 10px 2px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.85), rgba(255, 208, 150, 0.7));
  opacity: 0.55;
  animation: petalDrift 13s ease-in-out infinite;
}

.p1 { left: 8%; top: 24%; animation-delay: -2s; transform: rotate(24deg); }
.p2 { right: 9%; top: 38%; width: 9px; height: 6px; animation-delay: -6s; animation-duration: 16s; }
.p3 { left: 14%; top: 61%; width: 8px; height: 6px; animation-delay: -9s; animation-duration: 15s; }
.p4 { right: 13%; top: 74%; width: 11px; height: 7px; animation-delay: -4s; animation-duration: 18s; }

/* ---------- page frame ---------- */

.game {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 460px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

/* ---------- top hud ---------- */

.hud {
  display: flex;
  align-items: stretch;
  gap: 9px;
}

.stat-card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.97) 0%, rgba(255, 249, 239, 0.95) 100%);
  border: 1.5px solid rgba(255, 255, 255, 0.92);
  border-radius: 18px;
  box-shadow: 0 6px 16px rgba(150, 72, 14, 0.13), inset 0 1px 0 #ffffff;
}

.score-card {
  flex: 1;
  min-width: 0;
  padding: 9px 13px 10px;
}

.stat-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.stat-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #b07a4c;
}

.stat-target {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #c19161;
  white-space: nowrap;
}

.stat-target.done {
  color: #e96f18;
}

.score-line {
  display: flex;
  align-items: baseline;
  margin-top: 1px;
}

.score-num {
  display: inline-block;
  font-size: 28px;
  line-height: 1.05;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: #5a3417;
  font-variant-numeric: tabular-nums;
}

.score-num.bump {
  animation: scoreBump 0.22s ease-out;
}

.progress {
  height: 8px;
  margin-top: 6px;
  border-radius: 99px;
  background: #ffe1bf;
  box-shadow: inset 0 1px 2px rgba(170, 85, 20, 0.16);
  overflow: hidden;
}

.progress i {
  position: relative;
  display: block;
  width: 0%;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #ffb13d 0%, #ff8a3d 55%, #ff7226 100%);
  box-shadow: 0 0 8px rgba(255, 138, 61, 0.6);
  transition: width 0.38s cubic-bezier(0.2, 0.8, 0.3, 1);
}

.progress i::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 99px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0) 65%);
}

.moves-card {
  width: 92px;
  flex: none;
  padding: 8px 6px 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}

.moves-num {
  display: inline-block;
  font-size: 30px;
  line-height: 1;
  font-weight: 900;
  color: #ff7a2f;
  text-shadow: 0 2px 0 #ffe0c2;
  font-variant-numeric: tabular-nums;
}

.moves-num.bump {
  animation: scoreBump 0.22s ease-out;
}

.moves-hint {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: #c08f66;
}

/* ---------- board ---------- */

.board-wrap {
  margin-top: 10px;
  display: flex;
  justify-content: center;
}

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 28px;
  border: 2px solid rgba(255, 213, 166, 0.96);
  background: radial-gradient(120% 100% at 50% 0%, #fffdf6 0%, #fff5e3 48%, #ffeacb 100%);
  box-shadow:
    0 7px 0 #e6ac6c,
    0 18px 34px -6px rgba(162, 77, 15, 0.38),
    inset 0 2px 0 rgba(255, 255, 255, 0.95),
    inset 0 -10px 20px rgba(255, 178, 99, 0.16);
  touch-action: none;
  overflow: hidden;
  transform: translateZ(0);
}

.board::after {
  content: "";
  position: absolute;
  inset: 5px;
  z-index: 1;
  border-radius: 23px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  pointer-events: none;
}

.board-shine {
  position: absolute;
  left: 9%;
  top: 1.5%;
  z-index: 0;
  width: 82%;
  height: 11%;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0));
  filter: blur(1px);
  pointer-events: none;
}

.slots,
.tiles,
.floats {
  position: absolute;
  inset: 0;
}

.slots { z-index: 0; }
.tiles { z-index: 2; }
.floats { z-index: 12; pointer-events: none; }

.slot {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 12px;
  background: rgba(255, 176, 94, 0.11);
  box-shadow: inset 0 1px 3px rgba(176, 96, 28, 0.08);
  transform: translate3d(var(--x), var(--y), 0);
}

.slot.alt {
  background: rgba(255, 176, 94, 0.055);
}

.tile {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  transform: translate3d(var(--x), var(--y), 0);
  transition: transform 0.19s cubic-bezier(0.2, 0.8, 0.3, 1);
  will-change: transform;
  touch-action: none;
}

.tile-inner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 13px;
  border: 1.5px solid rgba(255, 255, 255, 0.85);
  overflow: hidden;
  transform: scale(1);
  transition: transform 0.14s ease, box-shadow 0.14s ease, filter 0.14s ease;
  box-shadow:
    0 3px 0 var(--shade, #e8a154),
    0 5px 9px rgba(126, 61, 10, 0.18),
    inset 0 2px 2px rgba(255, 255, 255, 0.78);
}

.tile-inner img {
  width: 81%;
  height: 81%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 1px 1px rgba(120, 50, 0, 0.14));
}

.tile-gloss {
  position: absolute;
  left: 9%;
  top: 7%;
  width: 58%;
  height: 24%;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0));
  transform: rotate(-10deg);
  pointer-events: none;
}

.fruit-orange {
  background: linear-gradient(155deg, #fff7e2 0%, #ffe5b8 55%, #ffd29a 100%);
  --shade: #f0a24a;
}

.fruit-strawberry {
  background: linear-gradient(155deg, #fff1f2 0%, #ffd6dc 58%, #ffc0c9 100%);
  --shade: #f08e9d;
}

.fruit-grape {
  background: linear-gradient(155deg, #f7f0ff 0%, #e7daff 58%, #d9c5ff 100%);
  --shade: #b294eb;
}

.fruit-lemon {
  background: linear-gradient(155deg, #fffbea 0%, #fff3b6 58%, #ffe994 100%);
  --shade: #e8c24d;
}

.fruit-blueberry {
  background: linear-gradient(155deg, #eef7ff 0%, #d7eaff 58%, #c2ddff 100%);
  --shade: #86b6ec;
}

.fruit-watermelon {
  background: linear-gradient(155deg, #f2fbea 0%, #def3d0 58%, #cbeab8 100%);
  --shade: #8fcb79;
}

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

.tile.selected .tile-inner {
  transform: scale(1.1);
  box-shadow:
    0 0 0 3px #ff8a3d,
    0 0 0 6px rgba(255, 138, 61, 0.24),
    0 6px 12px rgba(180, 80, 10, 0.3),
    inset 0 2px 2px rgba(255, 255, 255, 0.8);
}

.tile.pressing .tile-inner {
  transform: scale(0.94);
}

.tile.hint .tile-inner {
  animation: hintWiggle 0.9s ease-in-out infinite;
}

.tile.spawn .tile-inner {
  animation: tileIn 0.42s cubic-bezier(0.2, 1.45, 0.4, 1) backwards;
  animation-delay: var(--spawn-delay, 0ms);
}

.tile.clearing {
  z-index: 8;
}

.tile.clearing .tile-inner {
  animation: popOut 0.25s cubic-bezier(0.3, 0, 0.8, 0.3) forwards;
}

.board.resetting .tile {
  transform: translate3d(var(--x), var(--y), 0) scale(0.72);
  opacity: 0;
  transition: transform 0.16s ease, opacity 0.16s ease;
}

.board.no-anim .tile,
.board.no-anim .slot {
  transition: none !important;
}

.float {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 19px;
  font-weight: 900;
  letter-spacing: 0.01em;
  color: #ffffff;
  text-shadow: 0 2px 0 #dd6a12, 0 0 12px rgba(255, 140, 50, 0.85);
  pointer-events: none;
  animation: floatUp 0.82s cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
}

/* ---------- helper + dock ---------- */

.tip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin: 10px 4px 0;
  font-size: 12px;
  font-weight: 700;
  color: #996a42;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.75);
}

.tip-dot {
  width: 6px;
  height: 6px;
  flex: none;
  border-radius: 50%;
  background: #ff8a3d;
  box-shadow: 0 0 0 3px rgba(255, 138, 61, 0.17);
}

.dock {
  margin-top: auto;
  padding-top: 14px;
  display: flex;
  align-items: stretch;
  gap: 10px;
}

.goal-card {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 13px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95) 0%, rgba(255, 249, 239, 0.93) 100%);
  border: 1.5px solid rgba(255, 255, 255, 0.88);
  box-shadow: 0 7px 16px rgba(150, 72, 14, 0.13), inset 0 1px 0 #ffffff;
}

.goal-icon {
  width: 36px;
  height: 36px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  color: #f0781c;
  background: linear-gradient(145deg, #ffe3c4 0%, #ffd0a0 100%);
  box-shadow: inset 0 1px 0 #ffffff, 0 2px 5px rgba(190, 100, 20, 0.14);
}

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

.goal-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.goal-copy strong {
  font-size: 13px;
  font-weight: 900;
  color: #5d3718;
}

.goal-copy span {
  font-size: 11px;
  font-weight: 600;
  color: #a9825e;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 58px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  color: #f0781c;
  background: linear-gradient(180deg, #fffdf8 0%, #fff3e1 100%);
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 7px 16px rgba(150, 72, 14, 0.13), inset 0 1px 0 #ffffff;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

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

.icon-btn:active {
  transform: translateY(2px) scale(0.97);
  box-shadow: 0 3px 8px rgba(150, 72, 14, 0.16), inset 0 1px 0 #ffffff;
}

/* ---------- result overlay ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  background: rgba(80, 42, 12, 0.42);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: fadeIn 0.2s ease-out;
}

.overlay[hidden] {
  display: none !important;
}

.result-card {
  width: 100%;
  max-width: 330px;
  padding: 24px 22px 20px;
  margin-top: 20px;
  text-align: center;
  border-radius: 28px;
  border: 2px solid #ffdfb9;
  background: linear-gradient(180deg, #fffdf8 0%, #fff4e0 100%);
  box-shadow:
    0 24px 60px rgba(80, 40, 10, 0.35),
    0 6px 0 #e9b77d,
    inset 0 2px 0 #ffffff;
  animation: resultIn 0.4s cubic-bezier(0.2, 1.35, 0.4, 1);
}

.result-badge {
  width: 64px;
  height: 64px;
  margin: -52px auto 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 3px solid #fff7e8;
  color: #ffffff;
  background: linear-gradient(145deg, #ffd86f 0%, #ff9c2f 100%);
  box-shadow: 0 8px 18px rgba(230, 120, 20, 0.35);
}

.result-badge.lose {
  background: linear-gradient(145deg, #b9d7f2 0%, #7fa9d6 100%);
  box-shadow: 0 8px 18px rgba(70, 120, 170, 0.3);
}

.result-badge .mp-icon {
  width: 32px;
  height: 32px;
}

.result-card h2 {
  margin: 2px 0 6px;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 0.02em;
  color: #4e2c12;
}

.result-card p {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: #9b7752;
}

.result-score {
  margin: 16px 0 18px;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: 16px;
  border: 1px dashed #f0c192;
  background: #fff2de;
}

.result-score span {
  font-size: 12px;
  font-weight: 700;
  color: #a37b55;
}

.result-score strong {
  font-size: 24px;
  font-weight: 900;
  color: #f0781c;
  font-variant-numeric: tabular-nums;
}

.primary-btn {
  width: 100%;
  height: 50px;
  border-radius: 16px;
  color: #ffffff;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.08em;
  background: linear-gradient(180deg, #ffa34d 0%, #ff7a28 100%);
  box-shadow: 0 4px 0 #d9611a, 0 10px 20px rgba(220, 100, 20, 0.3);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.primary-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #d9611a, 0 4px 10px rgba(220, 100, 20, 0.3);
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 60;
  padding: 10px 18px;
  border-radius: 99px;
  background: rgba(78, 44, 18, 0.92);
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.9);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

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

/* ---------- animations ---------- */

@keyframes tileIn {
  0% { transform: scale(0.2) rotate(-14deg); opacity: 0; }
  62% { transform: scale(1.09) rotate(2deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

@keyframes popOut {
  0% { transform: scale(1); opacity: 1; }
  35% { transform: scale(1.18) rotate(4deg); filter: brightness(1.22); opacity: 1; }
  100% { transform: scale(0) rotate(20deg); filter: brightness(1.4); opacity: 0; }
}

@keyframes hintWiggle {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-3px) rotate(-4deg); }
  75% { transform: translateY(-3px) rotate(4deg); }
}

@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  20% { opacity: 1; transform: translate(-50%, -70%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -155%) scale(0.92); }
}

@keyframes scoreBump {
  0% { transform: scale(1); }
  48% { transform: scale(1.17); }
  100% { transform: scale(1); }
}

@keyframes boardShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

@keyframes petalDrift {
  0%, 100% { transform: translate3d(0, 0, 0) rotate(20deg); }
  35% { transform: translate3d(16px, 22px, 0) rotate(70deg); }
  70% { transform: translate3d(-10px, 48px, 0) rotate(10deg); }
}

@keyframes resultIn {
  0% { transform: scale(0.82) translateY(10px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

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

.board.shake {
  animation: boardShake 0.3s ease-in-out;
}

@media (max-width: 350px) {
  .game { padding-left: 9px; padding-right: 9px; }
  .moves-card { width: 82px; }
  .score-num { font-size: 25px; }
  .goal-copy span { font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .petal { animation: none; }
  .tile, .tile-inner, .progress i { transition-duration: 0.01ms; }
}
