/* Puppy Pileup */
:root {
  color-scheme: light;
  --bg: #fff3e4;
  --bg-deep: #ffe2c4;
  --ink: #3d2a1f;
  --muted: #8a6f5c;
  --card: rgba(255, 255, 255, 0.78);
  --line: #efd8c1;
  --accent: #ff7a59;
  --accent-deep: #d95a3b;
  --font: "Fredoka", ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(120% 80% at 50% 0%, var(--bg) 40%, var(--bg-deep) 100%) fixed,
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 540px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(10px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Title and buttons */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.logo { margin: 0; font-size: clamp(24px, 7vw, 32px); font-weight: 700; line-height: 1; letter-spacing: -0.01em; }
.logo span { color: var(--accent); }
.intro { margin: 0; font-size: 14px; line-height: 1.35; color: var(--muted); text-wrap: pretty; }
.buttons { display: flex; gap: 8px; }
.icon-btn {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border: 0; border-radius: 14px;
  background: var(--card);
  box-shadow: inset 0 0 0 1.5px var(--line), 0 2px 0 var(--line);
  color: var(--ink);
  cursor: pointer;
}
.icon-btn:active { translate: 0 1px; box-shadow: inset 0 0 0 1.5px var(--line); }
.icon-btn:focus-visible, .btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .no, .icon-btn.off .on { display: none; }
.icon-btn.off .no { display: block; }

/* Score, best and the next pup */
.stats { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
.stat {
  display: flex; flex-direction: column; justify-content: center;
  padding: 6px 14px;
  border-radius: 16px;
  background: var(--card);
  box-shadow: inset 0 0 0 1.5px var(--line);
  min-width: 0;
}
.label { font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.value { font-size: 24px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat.next { flex-direction: row; align-items: center; gap: 10px; }
.next-pup { position: relative; display: grid; }
/* Matches the number tag drawn under each pup's chin in the tub */
.tag {
  position: absolute; left: 50%; bottom: -3px; translate: -50% 0;
  padding: 0 5px;
  border: 1.5px solid var(--line); border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  font-size: 11px; font-weight: 700; line-height: 13px; color: var(--ink);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.tag:empty { display: none; }

/* The board */
.stage { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; }
#game { display: block; touch-action: none; cursor: pointer; }

.toast {
  position: absolute; top: 6px; left: 50%;
  display: flex; align-items: center; gap: 8px;
  max-width: calc(100% - 24px);
  padding: 6px 14px 6px 6px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 6px 20px rgba(61, 42, 31, 0.18);
  font-weight: 600; font-size: 15px; white-space: nowrap;
  opacity: 0; translate: -50% -8px;
  pointer-events: none;
  transition: opacity 0.25s, translate 0.25s;
}
.toast span { overflow: hidden; text-overflow: ellipsis; }
.toast.show { opacity: 1; translate: -50% 0; }

.over {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(61, 42, 31, 0.28);
  border-radius: 20px;
}
.over[hidden] { display: none; }
.card {
  width: min(300px, calc(100% - 32px));
  padding: 22px 22px 24px;
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 16px 48px rgba(61, 42, 31, 0.3);
  text-align: center;
  animation: pop 0.4s cubic-bezier(0.2, 1.5, 0.4, 1) both;
}
.card h2 { margin: 0 0 6px; font-size: 30px; }
.final { margin: 0; font-size: 18px; color: var(--muted); }
.final strong { display: block; font-size: 44px; line-height: 1.1; color: var(--ink); font-variant-numeric: tabular-nums; }
.final-best { margin: 2px 0 14px; color: var(--muted); font-weight: 600; }
.final-best.new { color: var(--accent); }
.top-pup { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 18px; font-weight: 600; }
.top-pup span:first-child { display: contents; }
.btn {
  font: inherit; font-size: 19px; font-weight: 700;
  padding: 12px 30px;
  border: 0; border-radius: 999px;
  background: var(--accent); color: #fff;
  box-shadow: 0 4px 0 var(--accent-deep);
  cursor: pointer;
}
.btn:active { translate: 0 2px; box-shadow: 0 2px 0 var(--accent-deep); }
@keyframes pop { from { scale: 0.7; opacity: 0; } }

/* The ladder of pups */
.ladder { list-style: none; margin: 0; padding: 0; display: flex; justify-content: space-between; gap: 2px; }
.ladder li {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  font-size: 11px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums;
}
.ladder canvas { width: min(30px, 100%) !important; height: auto !important; aspect-ratio: 1; }
.ladder li.locked canvas { filter: brightness(0) opacity(0.16); }
.ladder li.locked span { opacity: 0.5; }
.ladder li.fresh canvas { animation: pop 0.5s cubic-bezier(0.2, 1.5, 0.4, 1) both; }

.help { margin: 0; text-align: center; font-size: 13px; color: var(--muted); }
@media (max-height: 700px) { .help { display: none; } }

@media (prefers-reduced-motion: reduce) {
  .card, .ladder li.fresh canvas { animation: none; }
  .toast { transition: none; }
}
