:root {
  --cream: #fff6f9;
  --blush: #ffd6e7;
  --rose: #ff8fb8;
  --rose-deep: #f45d9a;
  --peach: #ffc9a8;
  --mint: #b8f0d8;
  --sky: #b8e4ff;
  --lavender: #e4d4ff;
  --ink: #5a3d4f;
  --ink-soft: #8a6578;
  --tile-2: #fff0f5;
  --tile-4: #ffe4ee;
  --tile-8: #ffc2d8;
  --tile-16: #ff9fc4;
  --tile-32: #ff7ab0;
  --tile-64: #f55d9a;
  --tile-128: #e4b8ff;
  --tile-256: #b8e4ff;
  --tile-512: #b8f0d8;
  --tile-1024: #ffd6a8;
  --tile-2048: #ffb3c6;
  --shadow: 0 12px 30px rgba(244, 93, 154, 0.18);
  --radius: 22px;
  --font-display: "ZCOOL KuaiLe", "Nunito", cursive;
  --font-body: "Nunito", "ZCOOL KuaiLe", sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  min-height: 100%;
  height: 100%;
  overscroll-behavior: none;
  overscroll-behavior-x: none;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(ellipse at 20% 10%, #ffe8f2 0%, transparent 45%),
    radial-gradient(ellipse at 85% 20%, #e8f7ff 0%, transparent 40%),
    radial-gradient(ellipse at 50% 90%, #fff0e0 0%, transparent 45%),
    linear-gradient(160deg, #fff8fb 0%, #f3fbff 50%, #fff5f0 100%);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-tap-highlight-color: transparent;
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
}

body.game-lock {
  overscroll-behavior-x: none;
}

.bg-hearts {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(circle at 12% 28%, rgba(255, 143, 184, 0.22) 0 8px, transparent 9px),
    radial-gradient(circle at 78% 18%, rgba(184, 228, 255, 0.35) 0 10px, transparent 11px),
    radial-gradient(circle at 88% 72%, rgba(184, 240, 216, 0.35) 0 9px, transparent 10px),
    radial-gradient(circle at 18% 78%, rgba(228, 212, 255, 0.3) 0 11px, transparent 12px),
    radial-gradient(circle at 50% 48%, rgba(255, 201, 168, 0.2) 0 7px, transparent 8px);
  animation: drift 16s ease-in-out infinite alternate;
}

@keyframes drift {
  from { transform: translateY(0); }
  to { transform: translateY(-18px); }
}

.app {
  position: relative;
  z-index: 1;
  width: min(440px, 100% - 28px);
  margin: 0 auto;
  padding: 16px 0;
  flex: 0 0 auto;
}

.btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 800;
  border-radius: 999px;
  padding: 10px 18px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn:active {
  transform: scale(0.96);
}

.btn.soft {
  background: #fff;
  color: var(--rose-deep);
  border: 2px solid #ffc2d8;
  box-shadow: 0 6px 14px rgba(244, 93, 154, 0.12);
}

.btn.primary {
  background: linear-gradient(135deg, #ff9fc4, #f45d9a);
  color: white;
  box-shadow: 0 10px 20px rgba(244, 93, 154, 0.28);
  font-size: 1rem;
  padding: 12px 28px;
}

.quest {
  background: rgba(255, 255, 255, 0.78);
  border: 2px solid #ffd6e7;
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

.char-slots {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.char-slot {
  aspect-ratio: 1;
  border-radius: 18px;
  background: linear-gradient(180deg, #fff8fb, #ffeaf2);
  border: 2px dashed #ffb3c9;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}

.char-slot.filled {
  border-style: solid;
  background: linear-gradient(160deg, #ff9fc4, #f45d9a);
  box-shadow: 0 8px 16px rgba(244, 93, 154, 0.28);
  animation: slotPop 0.55s cubic-bezier(0.18, 1.2, 0.35, 1);
}

@keyframes slotPop {
  0% { transform: scale(0.6) rotate(-8deg); }
  60% { transform: scale(1.12) rotate(3deg); }
  100% { transform: scale(1) rotate(0); }
}

.slot-char {
  font-family: var(--font-display);
  font-size: 1.55rem;
  color: #ff9ebf;
}

.char-slot.filled .slot-char {
  color: white;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.08);
}

.slot-hint {
  position: absolute;
  bottom: 4px;
  font-size: 0.65rem;
  color: #e89ab8;
  opacity: 0.7;
}

.char-slot.filled .slot-hint {
  display: none;
}

.quest-tip {
  margin-top: 10px;
  font-size: 0.82rem;
  color: var(--ink-soft);
  text-align: center;
}

.quest-tip strong {
  color: var(--rose-deep);
}

.board-wrap {
  position: relative;
  touch-action: none;
  overscroll-behavior: none;
}

.board {
  background: linear-gradient(160deg, #ffc2d8, #ff9fc4 40%, #f7b6d2);
  border-radius: 28px;
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 10px;
  aspect-ratio: 1;
  box-shadow: var(--shadow), inset 0 0 0 3px rgba(255, 255, 255, 0.35);
  position: relative;
  user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

.cell {
  background: rgba(255, 255, 255, 0.28);
  border-radius: 16px;
}

.tile {
  position: absolute;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 6vw, 1.85rem);
  color: var(--ink);
  transition: top 120ms ease-in-out, left 120ms ease-in-out;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.06);
  z-index: 2;
}

.tile.new {
  animation: appear 180ms ease-out;
}

.tile.merged {
  animation: mergePop 180ms ease-out;
}

@keyframes appear {
  from { transform: scale(0); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes mergePop {
  0% { transform: scale(1); }
  50% { transform: scale(1.16); }
  100% { transform: scale(1); }
}

.tile[data-v="2"] { background: var(--tile-2); }
.tile[data-v="4"] { background: var(--tile-4); }
.tile[data-v="8"] { background: var(--tile-8); color: #fff; }
.tile[data-v="16"] { background: var(--tile-16); color: #fff; }
.tile[data-v="32"] { background: var(--tile-32); color: #fff; }
.tile[data-v="64"] { background: var(--tile-64); color: #fff; }
.tile[data-v="128"] { background: var(--tile-128); }
.tile[data-v="256"] { background: var(--tile-256); }
.tile[data-v="512"] { background: var(--tile-512); }
.tile[data-v="1024"] { background: var(--tile-1024); font-size: clamp(1.05rem, 4.5vw, 1.35rem); }
.tile[data-v="2048"] { background: var(--tile-2048); color: #fff; font-size: clamp(1.05rem, 4.5vw, 1.35rem); }

.hint {
  text-align: center;
  margin-top: 12px;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(90, 61, 79, 0.35);
  backdrop-filter: blur(5px);
  padding: 20px;
}

.modal[hidden] {
  display: none !important;
}

.modal-card {
  width: min(340px, 100%);
  background: linear-gradient(180deg, #fff, #fff4f8);
  border-radius: 28px;
  padding: 28px 22px 22px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(90, 61, 79, 0.25);
  border: 3px solid #ffd0e2;
  position: relative;
  overflow: hidden;
}

.char-pop {
  animation: cardBounce 0.55s cubic-bezier(0.18, 1.35, 0.35, 1);
}

@keyframes cardBounce {
  0% { transform: scale(0.5) translateY(40px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.sparkle-ring {
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(circle at 20% 30%, #ffd6e7 0 6px, transparent 7px),
    radial-gradient(circle at 80% 25%, #b8e4ff 0 5px, transparent 6px),
    radial-gradient(circle at 75% 75%, #b8f0d8 0 6px, transparent 7px),
    radial-gradient(circle at 25% 80%, #e4d4ff 0 5px, transparent 6px);
  animation: spinSlow 8s linear infinite;
  opacity: 0.7;
  pointer-events: none;
}

@keyframes spinSlow {
  to { transform: rotate(360deg); }
}

.modal-eyebrow {
  position: relative;
  color: var(--ink-soft);
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.modal-title {
  font-family: var(--font-display);
  font-size: 1.8rem;
  color: var(--rose-deep);
  margin-bottom: 8px;
}

.modal-sub {
  position: relative;
  color: var(--ink-soft);
  margin: 8px 0 18px;
}

.char-reveal {
  position: relative;
  width: 110px;
  height: 110px;
  margin: 10px auto;
  border-radius: 28px;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 3.4rem;
  color: white;
  background: linear-gradient(145deg, #ff9fc4, #f45d9a);
  box-shadow: 0 14px 28px rgba(244, 93, 154, 0.35);
  animation: charPop 0.7s cubic-bezier(0.18, 1.5, 0.35, 1);
}

@keyframes charPop {
  0% { transform: scale(0) rotate(-20deg); opacity: 0; }
  60% { transform: scale(1.2) rotate(6deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* 胜利结算 */
.win-modal {
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 182, 210, 0.55), transparent 40%),
    radial-gradient(circle at 70% 30%, rgba(184, 228, 255, 0.5), transparent 35%),
    rgba(255, 246, 249, 0.92);
  align-content: center;
}

.fx-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.win-stage {
  position: relative;
  z-index: 2;
  text-align: center;
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.win-text {
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 12vw, 3.8rem);
  color: var(--rose-deep);
  letter-spacing: 0.12em;
  display: flex;
  gap: 0.08em;
  text-shadow: 0 6px 0 #ffd6e7;
}

.win-text span {
  display: inline-block;
  opacity: 0;
  transform: translateY(30px) scale(0.6);
}

.win-text.show span {
  animation: letterIn 0.55s cubic-bezier(0.18, 1.4, 0.35, 1) forwards;
}

.win-text.show span:nth-child(1) { animation-delay: 0.05s; }
.win-text.show span:nth-child(2) { animation-delay: 0.2s; }
.win-text.show span:nth-child(3) { animation-delay: 0.35s; }
.win-text.show span:nth-child(4) { animation-delay: 0.5s; }

@keyframes letterIn {
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.win-lyrics {
  font-size: 1.1rem;
  color: var(--ink-soft);
  min-height: 1.4em;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.win-lyrics.show {
  opacity: 1;
}

.photo-frame {
  width: min(300px, 86vw);
  background: white;
  padding: 12px 12px 18px;
  border-radius: 24px;
  box-shadow: 0 18px 40px rgba(244, 93, 154, 0.25);
  border: 3px solid #ffd0e2;
  transform: scale(0.7) rotate(-4deg);
  opacity: 0;
  transition: transform 0.7s cubic-bezier(0.18, 1.3, 0.35, 1), opacity 0.5s ease;
}

.photo-frame.show {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

.photo-frame img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 16px;
  background:
    linear-gradient(135deg, #ffe4ee, #e8f7ff),
    repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(255,255,255,0.3) 10px, rgba(255,255,255,0.3) 20px);
  display: block;
}

.photo-caption {
  margin-top: 10px;
  font-family: var(--font-display);
  color: var(--rose-deep);
  font-size: 1.15rem;
}

.floating-heart {
  position: fixed;
  pointer-events: none;
  z-index: 30;
  color: #ff8fb8;
  font-size: 1.4rem;
  animation: floatUp 2.8s ease-out forwards;
}

@keyframes floatUp {
  0% { transform: translateY(0) scale(0.6); opacity: 0; }
  15% { opacity: 1; }
  100% { transform: translateY(-120px) scale(1.2); opacity: 0; }
}

@media (max-width: 380px) {
  .board { gap: 8px; padding: 10px; }
  .tile, .cell { border-radius: 12px; }
}
