:root {
  --board: #26232d;
  --board-edge: #15131a;
  --hole: #34303d;
  --H: min(calc(100vw - 32px), 520px);
  /* Board = lane (1.15 cells) + pen (10 cells + padding). Sized from height first. */
  --W: min(calc(100vw - 32px), 400px, calc((100dvh - 186px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) / 1.88));
}
body {
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}

.app {
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 14px) 16px calc(env(safe-area-inset-bottom) + 16px);
}

/* Header */
.top { width: var(--H); display: flex; align-items: center; gap: 8px; }
.brand { display: flex; flex-direction: column; margin-right: auto; line-height: 1.05; min-width: 0; }
.brand > a { font-weight: 800; font-size: 22px; letter-spacing: -0.03em; color: inherit; text-decoration: none; white-space: nowrap; }
.brand span a { font-size: 13px; font-weight: 600; color: var(--muted); }

.scores { margin-top: auto; width: var(--H); display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; }
.score label { display: block; font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.score output { display: block; font-size: 40px; font-weight: 800; line-height: 1; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.score.best { text-align: right; }
.score.best output { font-size: 26px; color: var(--muted); }
.mid { display: flex; flex-direction: column; align-items: center; gap: 3px; padding-bottom: 2px; }
.next { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.next-slot { width: 34px; height: 34px; }
.next-slot > svg, .next-slot > .pet { width: 100%; height: 100%; }
.hay { font-size: 13px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.hay.warn { color: var(--c1); }

/* Board */
.board-wrap { position: relative; width: var(--W); flex: none; margin-bottom: auto; touch-action: none; cursor: pointer; }
.lane { height: calc((var(--W) - 16px) / 6 * 1.15); }
.pen {
  position: relative; padding: 8px;
  background: var(--board); border-radius: 18px;
  box-shadow: 0 6px 0 var(--board-edge), 0 18px 30px rgba(31, 29, 36, 0.18);
}
.holes {
  position: relative; width: 100%; aspect-ratio: 6 / 10;
  display: grid; grid-template-columns: repeat(6, 1fr); grid-template-rows: repeat(10, 1fr); gap: 4px;
}
.hole { border-radius: 50%; background: var(--hole); }
.aim {
  position: absolute; left: 0; top: -4px; bottom: -4px; border-radius: 14px;
  background: rgba(255, 255, 255, 0.07); pointer-events: none;
}
.aim.full { background: rgba(255, 107, 74, 0.2); }
.ring { position: absolute; left: 0; top: 0; border-radius: 50%; border: 2px dashed rgba(255, 255, 255, 0.5); pointer-events: none; }
.layer { position: absolute; inset: 0; pointer-events: none; }
.help {
  position: absolute; left: 8%; right: 8%; top: 22%; margin: 0; pointer-events: none;
  text-align: center; font-weight: 700; font-size: 16px; line-height: 1.35; color: rgba(255, 255, 255, 0.72);
}

/* Animals */
.animal { position: absolute; left: 0; top: 0; will-change: transform; }
.animal .bob { width: 100%; height: 100%; transform-origin: 50% 90%; }
.animal svg { display: block; width: 100%; height: 100%; overflow: visible; }
.pet {
  width: 86%; height: 86%; margin: 7%; border-radius: 50%; overflow: hidden; background: #fff;
  box-shadow: 0 0 0 3px #fff, 0 3px 0 3px rgba(0, 0, 0, 0.35);
}
.pet img { display: block; width: 100%; height: 100%; object-fit: cover; }
.pet.star { width: 100%; height: 100%; margin: 0; overflow: visible; background: none; box-shadow: none; border-radius: 0; }
.next-slot .pet { margin: 0; }

.animal.hovering .bob { animation: float 1.8s ease-in-out infinite; }
.animal.spawn .bob { animation: spawn 0.34s cubic-bezier(0.3, 1.5, 0.5, 1) both; }
.animal.hovering.spawn .bob { animation: spawn 0.34s cubic-bezier(0.3, 1.5, 0.5, 1) both, float 1.8s ease-in-out 0.34s infinite; }
.animal.land .bob { animation: squash 0.32s cubic-bezier(0.3, 1.5, 0.5, 1); }
.animal.pop .bob { animation: pop 0.32s ease-in forwards; }
.animal.bump .bob { animation: bump 0.32s ease-out; }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7%); } }
@keyframes spawn { 0% { transform: scale(0.2); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes squash {
  0% { transform: scale(1.2, 0.76); }
  45% { transform: scale(0.93, 1.09); }
  100% { transform: scale(1, 1); }
}
@keyframes pop {
  0% { transform: scale(1); filter: brightness(1); }
  35% { transform: scale(1.25); filter: brightness(1.35); }
  100% { transform: scale(0) rotate(25deg); opacity: 0; }
}
@keyframes bump { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-12%); } 60% { transform: translateX(10%); } }

.pen.hay-flash::after {
  content: ''; position: absolute; left: 8px; right: 8px; bottom: 2px; height: 22%;
  border-radius: 0 0 14px 14px; pointer-events: none;
  background: linear-gradient(to top, rgba(255, 210, 63, 0.55), rgba(255, 210, 63, 0));
  animation: hay 0.6s ease-out forwards;
}
@keyframes hay { 0% { opacity: 0; } 30% { opacity: 1; } 100% { opacity: 0; } }

.float-pts {
  position: fixed; z-index: 40; pointer-events: none; transform: translate(-50%, -50%);
  font-weight: 800; font-size: 26px; color: #fff;
  text-shadow: 0 2px 0 var(--ink), 0 0 10px rgba(0, 0, 0, 0.4);
  animation: rise 0.9s ease-out forwards;
}
@keyframes rise { 0% { opacity: 0; margin-top: 8px; } 20% { opacity: 1; } 100% { opacity: 0; margin-top: -40px; } }

.chain-pop {
  position: absolute; left: 0; right: 0; top: 34%; z-index: 15; pointer-events: none; text-align: center;
  font-weight: 800; font-size: clamp(28px, 8vw, 42px); letter-spacing: -0.03em; color: #fff;
  text-shadow: 0 3px 0 var(--ink), 0 0 16px rgba(0, 0, 0, 0.45);
}
.chain-pop.show { animation: chainIn 0.9s ease-out both; }
@keyframes chainIn {
  0% { transform: scale(0.4); opacity: 0; }
  20% { transform: scale(1.12); opacity: 1; }
  32% { transform: scale(1); }
  80% { opacity: 1; }
  100% { transform: translateY(-16px); opacity: 0; }
}

/* Cheer */
.cheer { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; pointer-events: none; }
.cheer-inner { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 82%; }
.cheer.show .cheer-inner { animation: cheer var(--cheer-ms, 2000ms) ease-out both; }
@keyframes cheer {
  0% { transform: scale(0.5) rotate(-6deg); opacity: 0; }
  10% { transform: scale(1.06) rotate(1deg); opacity: 1; }
  16% { transform: scale(1) rotate(0); }
  84% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.96) translateY(-14px); opacity: 0; }
}
.cheer-title {
  font-weight: 800; font-size: clamp(30px, 9vw, 46px); letter-spacing: -0.03em; line-height: 1;
  color: #fff; text-align: center;
  text-shadow: 0 3px 0 var(--ink), 0 0 18px rgba(0, 0, 0, 0.45);
}
.cheer-card {
  margin: 0; background: #fff; padding: 8px 8px 10px; border-radius: 12px; transform: rotate(-2.5deg);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.4); max-width: 100%;
}
.cheer-card img { display: block; width: 100%; max-height: calc(var(--W) * 0.8); object-fit: cover; border-radius: 6px; }
.cheer-card figcaption { margin-top: 8px; text-align: center; font-weight: 700; font-size: 17px; color: var(--ink); }

#confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 60; }

.over-photo { margin: 14px auto 0; background: #fff; padding: 8px 8px 10px; border-radius: 12px; transform: rotate(-2deg); max-width: 78%; box-shadow: 0 10px 24px rgba(0, 0, 0, 0.2); }
.over-photo img { display: block; width: 100%; max-height: 40dvh; object-fit: cover; border-radius: 6px; }
.over-photo figcaption { margin-top: 8px; font-weight: 700; }
.over-scores { display: grid; grid-template-columns: 1fr 1fr; margin: 18px 0; }
.over-scores label { display: block; font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.over-scores b { font-size: 36px; font-weight: 800; }

@media (prefers-reduced-motion: reduce) {
  .animal .bob, .chain-pop.show, .float-pts, .pen.hay-flash::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
