:root {
  --cream: #fff8ef;
  --pink: #ffd7e8;
  --pink-strong: #ff8fc3;
  --mint: #c7f7e8;
  --lemon: #fff1a8;
  --sky: #dcecff;
  --ink: #352033;
  --muted: rgba(53,32,51,.66);
  --card: rgba(255, 255, 255, .72);
  --line: rgba(255, 143, 195, .28);
  --shadow: 0 18px 42px rgba(119, 62, 104, .16);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { min-height: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: 'DM Sans', ui-rounded, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 14% 8%, rgba(255, 143, 195, .45), transparent 28%),
    radial-gradient(circle at 88% 18%, rgba(199, 247, 232, .72), transparent 26%),
    radial-gradient(circle at 55% 92%, rgba(255, 241, 168, .72), transparent 30%),
    linear-gradient(180deg, #fff4f8 0%, var(--cream) 58%, #f7fbff 100%);
  overflow-x: hidden;
  touch-action: manipulation;
}

body::before, body::after {
  content: '✦';
  position: fixed;
  z-index: 0;
  color: rgba(255, 143, 195, .55);
  font-size: 32px;
  animation: floaty 5.4s ease-in-out infinite;
  pointer-events: none;
}
body::before { left: 18px; top: 88px; }
body::after { right: 22px; bottom: 96px; animation-delay: -2.2s; color: rgba(108, 181, 255, .45); }

.phone-shell {
  position: relative;
  z-index: 1;
  width: min(100%, 480px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 14px max(16px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
}

.top-card, .board-card {
  background: var(--card);
  border: 1px solid rgba(255,255,255,.76);
  border-radius: 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.top-card { padding: 16px; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.eyebrow {
  margin: 0 0 2px;
  color: var(--pink-strong);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .14em;
  text-transform: uppercase;
}
h1 { margin: 0; font-size: clamp(26px, 8vw, 38px); line-height: .98; letter-spacing: -.9px; }
.restart {
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 18px;
  background: linear-gradient(145deg, #fff, var(--pink));
  color: var(--ink);
  font-size: 24px;
  font-weight: 900;
  box-shadow: inset 0 1px rgba(255,255,255,.9), 0 8px 18px rgba(255,143,195,.26);
  cursor: pointer;
  touch-action: manipulation;
}
.restart:active { transform: scale(.94) rotate(-12deg); }

.stats { display: grid; grid-template-columns: 1fr 1.18fr 1fr; gap: 8px; margin: 14px 0 10px; }
.stat {
  min-height: 62px;
  display: grid;
  place-items: center;
  padding: 8px 6px;
  border-radius: 20px;
  background: rgba(255,255,255,.64);
  border: 1px solid var(--line);
}
.stat.big { background: linear-gradient(145deg, #fff6c8, #ffddec); }
.stat strong { font-size: 24px; line-height: 1; }
.stat span { font-size: 12px; color: var(--muted); font-weight: 700; }
.message {
  margin: 0;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  border-radius: 18px;
  background: rgba(255,255,255,.56);
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  padding: 9px 12px;
}

.board-card {
  position: relative;
  align-self: start;
  padding: 14px;
  overflow: hidden;
}
.board-card::before {
  content: '';
  position: absolute;
  inset: 8px;
  border-radius: 24px;
  background: linear-gradient(145deg, rgba(255,255,255,.42), rgba(255,215,232,.22));
  pointer-events: none;
}
.mascot {
  position: absolute;
  top: -5px;
  right: 18px;
  font-size: 36px;
  filter: drop-shadow(0 8px 12px rgba(53,32,51,.12));
  animation: floaty 3.8s ease-in-out infinite;
  pointer-events: none;
}
.combo-text {
  position: absolute;
  z-index: 5;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%) scale(.85);
  opacity: 0;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .9);
  color: #ff5ba8;
  font-weight: 900;
  font-size: 22px;
  box-shadow: 0 12px 28px rgba(255,91,168,.2);
  pointer-events: none;
}
.combo-text.show { animation: comboPop .9s ease forwards; }

.board {
  position: relative;
  z-index: 2;
  width: min(100%, 430px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: clamp(4px, 1.2vw, 7px);
  justify-content: center;
  padding: 14px 2px 6px;
}
.gem {
  border: 0;
  width: 100%;
  aspect-ratio: 1;
  min-width: 0;
  border-radius: clamp(11px, 3.6vw, 17px);
  font-size: clamp(22px, 6.8vw, 34px);
  display: grid;
  place-items: center;
  cursor: pointer;
  background: linear-gradient(145deg, rgba(255,255,255,.96), rgba(255,255,255,.5));
  box-shadow: inset 0 2px 4px rgba(255,255,255,.9), inset 0 -5px 10px rgba(255,143,195,.08), 0 7px 14px rgba(53,32,51,.12);
  transition: transform .14s ease, filter .14s ease, box-shadow .14s ease;
  touch-action: manipulation;
  user-select: none;
}
.gem:active { transform: scale(.9); }
.gem:hover { filter: brightness(1.04); }
.gem.selected {
  transform: translateY(-4px) scale(1.08);
  box-shadow: 0 0 0 4px rgba(255,241,168,.95), 0 14px 24px rgba(255,143,195,.32);
  animation: wiggle .5s ease infinite alternate;
}
.gem.pop { animation: sparkle .34s ease; }

.tip { margin: 2px 0 0; text-align: center; color: var(--muted); font-size: 13px; font-weight: 700; }

@keyframes floaty {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-10px) rotate(5deg); }
}
@keyframes sparkle {
  0% { transform: scale(1); filter: brightness(1); }
  45% { transform: scale(.58) rotate(12deg); filter: brightness(1.35); opacity: .52; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes comboPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.72); }
  18% { opacity: 1; transform: translate(-50%, -56%) scale(1.08); }
  75% { opacity: 1; transform: translate(-50%, -76%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -90%) scale(.92); }
}
@keyframes wiggle {
  from { rotate: -2deg; }
  to { rotate: 2deg; }
}

@media (max-width: 700px) {
  .phone-shell { width: 100%; padding-left: 10px; padding-right: 10px; gap: 10px; }
  .top-card { padding: 14px; border-radius: 24px; }
  .board-card { padding: 10px 6px 12px; border-radius: 24px; }
  .board { gap: 5px; padding-top: 18px; }
  .gem { border-radius: 14px; }
  .message { font-size: 13px; }
}

@media (max-width: 360px) {
  .stats { gap: 6px; }
  .stat { min-height: 56px; border-radius: 16px; }
  .stat strong { font-size: 21px; }
  .board { gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
