* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
html, body { height: 100%; }
body {
  margin: 0;
  background: #f4b8c8;
  display: flex;
  justify-content: center;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: #5c4638;
}
button, input { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

#app {
  width: min(100vw, 430px);
  height: 100dvh;
  background: #fff6f8;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#home, #play {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: max(14px, env(safe-area-inset-top)) 14px max(16px, env(safe-area-inset-bottom));
  gap: 12px;
}

#home {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
}
.banner-logo {
  width: 100%;
  background: #b7e7fb;
  color: #fff;
  border-radius: 28px;
  padding: 18px 12px 14px;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-shadow: 0 3px 0 #7ec4ea;
}
.mascot { width: min(52vw, 210px); margin: 8px 0 0; }
.mascot svg { width: 100%; height: auto; }
.tag { margin: 0 0 8px; font-size: 18px; color: #c47d93; font-weight: 700; }
.play-btn {
  width: min(100%, 280px);
  height: 64px;
  border: none;
  border-radius: 32px;
  background: #ff9bb8;
  color: white;
  font-size: 28px;
  font-weight: 800;
  box-shadow: 0 6px 0 #f07aa0;
}
.play-btn:active { transform: translateY(2px); box-shadow: 0 4px 0 #f07aa0; }
.text-btn {
  margin-top: 10px;
  border: none;
  background: transparent;
  color: #6aaed4;
  font-weight: 800;
  font-size: 16px;
}

.topbar {
  display: grid;
  grid-template-columns: 58px 1fr 58px 58px;
  gap: 8px;
  align-items: center;
  background: #b7e7fb;
  border-radius: 30px;
  padding: 10px;
  min-height: 78px;
}
.round {
  width: 58px;
  height: 58px;
  border: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  padding: 0;
  position: relative;
}
.round svg, .tool svg { width: 34px; height: 34px; }
.menu { background: #8fd4f5; }
.bars { display: grid; gap: 5px; }
.bars i { display: block; width: 22px; height: 3px; border-radius: 3px; background: #fff; }
.heart { background: #ffb7c8; }
.star { background: #ffe08a; }
.meter { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.bones { display: flex; justify-content: center; align-items: center; gap: 4px; }
.pup-count { margin: 0; font-size: 13px; font-weight: 800; color: #2f6d8a; line-height: 1; }
.bone { width: 42px; height: 22px; }
.bone.spent { filter: grayscale(1); opacity: 0.38; }
.level-label {
  margin: 0;
  text-align: center;
  font-weight: 800;
  color: #d18aa0;
  font-size: 14px;
}

.stage {
  flex: 1 1 auto;
  height: 0;
  min-height: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.board {
  width: 100%;
  height: auto;
  max-height: 100%;
  aspect-ratio: 1;
  display: grid;
  touch-action: none;
}
.cell {
  position: relative;
  border: none;
  border-radius: 16px;
  padding: 0;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}
.cell:focus { outline: none; }
.fence { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.cell .paw, .cell .cross {
  position: absolute;
  inset: 12%;
  width: 76%;
  height: 76%;
  margin: auto;
  pointer-events: none;
}
.cell:has(.born) { z-index: 3; overflow: visible; }
.pup3d {
  position: absolute;
  inset: 8%;
  z-index: 2;
  pointer-events: none;
  transform-origin: 50% 82%;
}
.pup3d.born { animation: pup-pop 0.62s cubic-bezier(0.18, 1.45, 0.36, 1) both; }
.pup-bob {
  position: absolute;
  inset: 0;
  transform-origin: 50% 82%;
  animation: pup-idle 3.2s ease-in-out infinite;
  animation-delay: var(--lag, 0s);
}
.pup3d .pup {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform-origin: 50% 78%;
  animation: head-look 4.6s ease-in-out infinite;
  animation-delay: var(--lag, 0s);
}
.pup3d .bit {
  position: absolute;
  left: 46%;
  top: 36%;
  width: 8px;
  height: 8px;
  background: var(--c);
  animation: pup-burst 0.72s ease-out forwards;
  pointer-events: none;
}
.mascot .pup3d, .sheet .mascot .pup3d {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 390 / 440;
  inset: auto;
}
@keyframes pup-pop {
  0% { transform: translateY(22%) scale(0.12); }
  58% { transform: translateY(-8%) scale(1.16); }
  100% { transform: translateY(0) scale(1); }
}
@keyframes pup-idle {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-7%) scale(1.035); }
}
@keyframes head-look {
  0%, 100% { transform: rotate(0deg); }
  32% { transform: rotate(-8deg); }
  68% { transform: rotate(7deg); }
}
@keyframes pup-blink {
  0%, 38%, 46%, 100% { transform: scaleY(1); }
  42% { transform: scaleY(0.12); }
}
@keyframes pup-burst {
  to { transform: translate(var(--dx), var(--dy)) scale(0.35) rotate(50deg); opacity: 0; }
}
.cell.coached { box-shadow: inset 0 0 0 3px #7ec8f0; }
.cell.hinted { box-shadow: inset 0 0 0 3px #f0b429; }
.cell.flash::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 70, 90, 0.42);
  animation: fade 420ms ease forwards;
}
.cell.shake .cross {
  transform-origin: 50% 42%;
  animation: headshake 560ms ease;
}
@keyframes fade { to { opacity: 0; } }
@keyframes headshake {
  0% { transform: rotate(0); }
  18% { transform: rotate(-18deg); }
  36% { transform: rotate(16deg); }
  54% { transform: rotate(-12deg); }
  72% { transform: rotate(8deg); }
  100% { transform: rotate(0); }
}

.coach {
  background: #fff;
  border-radius: 18px;
  padding: 10px 12px;
  text-align: center;
  box-shadow: 0 8px 20px rgba(120, 70, 90, 0.08);
  font-weight: 700;
}
.coach p { margin: 0; }
.coach button, .primary, .secondary {
  border: none;
  border-radius: 22px;
  font-weight: 800;
}
.coach button, .primary {
  margin-top: 8px;
  background: #ff9bb8;
  color: white;
  height: 42px;
  padding: 0 18px;
}
.banner {
  min-height: 22px;
  margin: 0;
  text-align: center;
  font-weight: 800;
  color: #e07a9a;
}
.banner.hint { color: #d39a1e; }
.banner.info { color: #6aaed4; }

.tools {
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  background: #f6efe6;
  border-radius: 34px;
  min-height: 96px;
  padding: 10px;
}
.tool {
  width: 68px;
  height: 68px;
  border: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  position: relative;
}
.tool:active, .round:active { transform: scale(0.94); }
.undo { background: #ffc29a; }
.hint { background: #ffe56b; }
.tool.hint.show-hint { box-shadow: 0 0 0 4px #f0b429; }
.restart { background: #8fd0c8; }
.badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border-radius: 99px;
  background: #ff8fab;
  color: white;
  font-size: 12px;
  font-weight: 800;
  display: grid;
  place-items: center;
}

.float {
  position: absolute;
  left: 50%;
  top: 8%;
  transform: translateX(-50%);
  color: white;
  font-weight: 800;
  font-size: 16px;
  text-shadow: 0 2px 0 #e07a9a;
  animation: rise 720ms ease forwards;
  pointer-events: none;
  z-index: 4;
  white-space: nowrap;
}
@keyframes rise {
  to { transform: translate(-50%, -26px); opacity: 0; }
}

#modal {
  position: absolute;
  inset: 0;
  background: rgba(255, 246, 248, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 5;
}
.sheet {
  width: min(100%, 360px);
  background: white;
  border-radius: 28px;
  padding: 18px 16px 16px;
  text-align: center;
  box-shadow: 0 16px 40px rgba(120, 60, 80, 0.16);
}
.sheet h2 { margin: 6px 0; font-size: 32px; color: #e07a9a; }
.sheet p { margin: 6px 0 12px; font-weight: 700; }
.sheet .mascot { width: 140px; margin: 0 auto; }
.stack { display: grid; gap: 8px; }
.primary.big { height: 54px; font-size: 18px; width: 100%; }
.secondary {
  height: 46px;
  background: #f6efe6;
  color: #8a6a58;
  width: 100%;
}
.menu-list { display: grid; gap: 8px; text-align: left; }
.menu-list button, .toggle {
  border: none;
  background: #fff6f8;
  border-radius: 16px;
  min-height: 46px;
  padding: 8px 12px;
  font-weight: 800;
  color: #5c4638;
  text-align: left;
}
.toggle { display: flex; justify-content: space-between; align-items: center; }
.rules { text-align: left; display: grid; gap: 6px; font-weight: 700; }
.loading { width: 100%; text-align: center; font-weight: 800; color: #d18aa0; }
.confetti {
  position: absolute;
  top: 0;
  width: 8px;
  height: 12px;
  border-radius: 3px;
  animation: fall 900ms ease-in forwards;
}
@keyframes fall {
  to { transform: translateY(90px) rotate(180deg); opacity: 0; }
}
