:root {
  --sky-top: #dff3ff;
  --sky-bottom: #fff7df;
  --frame: #fff3da;
  --panel: rgba(255, 249, 236, 0.94);
  --panel-border: rgba(130, 89, 45, 0.16);
  --text: #3c2b1e;
  --muted: #81654e;
  --gold: #f8c86b;
  --wood: #9a6a3a;
  --wood-dark: #6e4825;
  --grass: #73c95d;
  --barn: #f36a77;
  --target: #ffce64;
  --shadow: rgba(106, 73, 38, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.72), transparent 30%),
    linear-gradient(180deg, var(--sky-top), var(--sky-bottom));
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
}

button {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: center;
}

.game-frame {
  width: min(430px, 100%);
  min-height: calc(100vh - 24px);
  padding: 16px;
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(255, 249, 236, 0.88)),
    var(--frame);
  box-shadow: 0 18px 40px var(--shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  overflow: hidden;
}

.game-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(140deg, rgba(255, 255, 255, 0.32), transparent 26%, transparent 70%, rgba(255, 255, 255, 0.18));
  opacity: 0.5;
}

.game-frame.celebrate {
  box-shadow:
    0 0 0 4px rgba(255, 206, 100, 0.12),
    0 22px 46px rgba(106, 73, 38, 0.18);
}

.hero-bar,
.hud,
.stage {
  display: grid;
  gap: 14px;
}

.hero-bar {
  grid-template-columns: 1fr;
  margin-bottom: 12px;
}

.eyebrow,
.promo-kicker,
.overlay-label {
  margin: 0 0 6px;
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #c27b2c;
}

h1,
h2,
.hud strong {
  margin: 0;
  font-weight: 900;
  letter-spacing: -0.04em;
}

h1 {
  font-size: clamp(2rem, 8vw, 2.9rem);
  line-height: 0.9;
}

h2 {
  font-size: clamp(1.5rem, 5vw, 2.2rem);
}

.subtitle,
#status-text,
#overlay-message {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.42;
}

.hud {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 12px;
}

.hud-card,
.promo-card,
.board-panel,
.side-panel {
  border: 1px solid var(--panel-border);
  background: var(--panel);
  border-radius: 20px;
}

.hud-card {
  padding: 12px 10px;
  text-align: center;
}

.hud-label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.stage {
  grid-template-columns: 1fr;
}

.board-panel {
  padding: 14px;
  background:
    linear-gradient(180deg, rgba(192, 236, 165, 0.22), transparent 24%),
    var(--panel);
}

.tutorial-callout {
  margin-bottom: 10px;
  padding: 9px 11px;
  border-radius: 14px;
  background: rgba(248, 200, 107, 0.2);
  border: 1px solid rgba(194, 123, 44, 0.24);
  color: #744a25;
  font-size: 0.84rem;
  line-height: 1.35;
}

.tutorial-callout.hidden {
  display: none;
}

.board-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.legend {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.6);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

.legend-wide {
  flex: 0 0 auto;
}

.legend-chip {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--target);
  color: #6c4216;
  font-size: 0.72rem;
  font-weight: 900;
}

.math-pill {
  min-width: 118px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(130, 89, 45, 0.14);
  color: #6c4216;
  font-size: 0.96rem;
  font-weight: 900;
  text-align: center;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.math-pill.bump {
  transform: scale(1.06);
  box-shadow:
    0 0 0 3px rgba(255, 206, 100, 0.16),
    inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.math-pill.success {
  animation: prompt-success 0.36s ease;
}

.pen {
  position: relative;
  width: min(100%, 330px);
  aspect-ratio: 1;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 24px;
  border: 6px solid var(--wood);
  background:
    radial-gradient(circle at 50% 15%, rgba(255, 255, 255, 0.22), transparent 25%),
    linear-gradient(180deg, #8ee06e, #63bc54);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.18),
    0 10px 22px rgba(106, 73, 38, 0.12);
  transition: box-shadow 0.22s ease, transform 0.22s ease;
}

.pen::before,
.pen::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.pen::before {
  background:
    linear-gradient(90deg, transparent 0 8%, rgba(88, 133, 51, 0.18) 8% 10%, transparent 10% 30%, rgba(88, 133, 51, 0.18) 30% 32%, transparent 32% 58%, rgba(88, 133, 51, 0.18) 58% 60%, transparent 60% 100%);
}

.pen::after {
  inset: 8px;
  border-radius: 18px;
  border: 2px dashed rgba(255, 255, 255, 0.16);
}

.pen-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 16% 22%, rgba(255, 255, 255, 0.16), transparent 10%),
    radial-gradient(circle at 72% 28%, rgba(255, 255, 255, 0.13), transparent 9%),
    radial-gradient(circle at 38% 78%, rgba(255, 255, 255, 0.12), transparent 8%);
  animation: pen-glow 6s ease-in-out infinite alternate;
}

.pen.flash {
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.22),
    0 0 0 4px rgba(255, 206, 100, 0.12),
    0 14px 30px rgba(106, 73, 38, 0.2);
}

.animal {
  position: absolute;
  width: 58px;
  height: 58px;
  border: 0;
  padding: 0;
  border-radius: 18px;
  background:
    radial-gradient(circle at 35% 25%, rgba(255, 255, 255, 0.35), transparent 28%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(255, 244, 228, 0.94));
  box-shadow:
    0 8px 16px rgba(106, 73, 38, 0.12),
    inset 0 0 0 1px rgba(255, 255, 255, 0.7);
  cursor: pointer;
  touch-action: manipulation;
  transform: translate(var(--x, 0px), var(--y, 0px)) rotate(var(--tilt, 0deg)) scale(var(--scale, 1));
  transition:
    transform 0.14s ease,
    box-shadow 0.14s ease,
    opacity 0.14s ease,
    filter 0.14s ease;
  will-change: transform;
}

.animal:active {
  --scale: 0.94;
}

.animal.target {
  box-shadow:
    0 0 0 3px rgba(255, 206, 100, 0.22),
    0 12px 22px rgba(106, 73, 38, 0.18),
    inset 0 0 0 1px rgba(255, 255, 255, 0.7);
  filter: saturate(1.06);
}

.animal.done {
  opacity: 0.6;
  --scale: 0.9;
}

.animal.exiting {
  pointer-events: none;
  animation: animal-exit 0.46s ease forwards;
}

.animal.spawn-in {
  animation: animal-spawn 0.4s ease;
}

.animal.wrong {
  animation: animal-shake 0.28s ease;
}

.animal.tap-pop {
  animation: animal-pop 0.24s ease;
}

.animal.correct-hit {
  animation: animal-correct 0.42s ease;
}

.animal.score-pop .animal-tag {
  animation: score-tag 0.4s ease;
}

.animal-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 2rem;
  user-select: none;
  transition: transform 0.16s ease, filter 0.16s ease;
}

.animal.target .animal-face {
  animation: target-bob 1.2s ease-in-out infinite;
}

.animal.tap-pop .animal-face,
.animal.correct-hit .animal-face {
  transform: scale(1.08);
}

.animal-tag {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 28px;
  height: 28px;
  padding: 0 7px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--target);
  color: #6c4216;
  font-size: 0.84rem;
  font-weight: 900;
  box-shadow: 0 4px 8px rgba(106, 73, 38, 0.18);
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.animal.target .animal-tag {
  animation: tag-pulse 1s ease-in-out infinite;
}

.animal-burst {
  position: absolute;
  inset: -8px;
  pointer-events: none;
}

.animal-burst::before,
.animal-burst::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 22px;
  border: 2px solid rgba(255, 206, 100, 0.65);
  opacity: 0;
}

.animal-burst::before {
  animation: burst-ring 0.45s ease-out;
}

.animal-burst::after {
  animation: burst-ring 0.45s ease-out 0.08s;
}

.dust-puff {
  position: absolute;
  left: 50%;
  bottom: -2px;
  width: 12px;
  height: 12px;
  margin-left: -6px;
  border-radius: 999px;
  background: rgba(255, 241, 213, 0.9);
  box-shadow:
    -12px -2px 0 2px rgba(255, 241, 213, 0.68),
    12px 1px 0 1px rgba(255, 241, 213, 0.56);
  pointer-events: none;
  animation: dust-puff 0.5s ease-out forwards;
}

.score-float {
  position: absolute;
  z-index: 6;
  left: 0;
  top: 0;
  font-size: 1rem;
  font-weight: 900;
  color: #fff6d3;
  text-shadow: 0 2px 6px rgba(95, 56, 23, 0.26);
  pointer-events: none;
  animation: score-float 0.7s ease-out forwards;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px;
}

.promo-card {
  padding: 16px;
}

.feature-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.feature-pill {
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid rgba(130, 89, 45, 0.12);
  color: var(--text);
  font-size: 0.82rem;
}

.cta-button,
.secondary-button {
  border: 0;
  cursor: pointer;
}

.cta-button {
  min-height: 50px;
  padding: 13px 20px;
  border-radius: 16px;
  font-weight: 800;
  color: #5f3817;
  background: linear-gradient(135deg, #ffd977, #ffb869 50%, #ff8c7f);
  box-shadow: 0 10px 22px rgba(201, 121, 71, 0.2);
}

.cta-button-main {
  width: 100%;
}

.secondary-button {
  min-height: 48px;
  padding: 12px 18px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.54);
  color: var(--text);
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(80, 54, 28, 0.22);
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  width: min(360px, 100%);
  padding: 24px;
  border-radius: 22px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 249, 236, 0.98);
  box-shadow: 0 18px 34px rgba(106, 73, 38, 0.16);
  text-align: center;
}

@keyframes animal-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-4px);
  }
  75% {
    transform: translateX(4px);
  }
}

@keyframes animal-pop {
  0% {
    transform: translate(var(--x, 0px), var(--y, 0px)) rotate(var(--tilt, 0deg)) scale(1);
  }
  50% {
    transform: translate(var(--x, 0px), var(--y, 0px)) rotate(var(--tilt, 0deg)) scale(1.12);
  }
  100% {
    transform: translate(var(--x, 0px), var(--y, 0px)) rotate(var(--tilt, 0deg)) scale(1);
  }
}

@keyframes animal-correct {
  0% {
    transform: translate(var(--x, 0px), var(--y, 0px)) rotate(var(--tilt, 0deg)) scale(1);
  }
  35% {
    transform: translate(var(--x, 0px), calc(var(--y, 0px) - 8px)) rotate(var(--tilt, 0deg)) scale(1.14);
  }
  100% {
    transform: translate(var(--x, 0px), var(--y, 0px)) rotate(var(--tilt, 0deg)) scale(0.9);
  }
}

@keyframes target-bob {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-2px);
  }
}

@keyframes tag-pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}

@keyframes burst-ring {
  0% {
    transform: scale(0.72);
    opacity: 0.8;
  }
  100% {
    transform: scale(1.26);
    opacity: 0;
  }
}

@keyframes pen-glow {
  0% {
    transform: translateY(0);
    opacity: 0.6;
  }
  100% {
    transform: translateY(-6px);
    opacity: 0.95;
  }
}

@keyframes prompt-success {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes score-float {
  0% {
    transform: translate(0, 0) scale(0.8);
    opacity: 0;
  }
  20% {
    opacity: 1;
  }
  100% {
    transform: translate(0, -26px) scale(1.08);
    opacity: 0;
  }
}

@keyframes score-tag {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.18);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes animal-exit {
  0% {
    opacity: 1;
    transform: translate(var(--x, 0px), var(--y, 0px)) rotate(var(--tilt, 0deg)) scale(1.02);
  }
  100% {
    opacity: 0;
    transform: translate(var(--x, 0px), calc(var(--y, 0px) - 18px)) rotate(calc(var(--tilt, 0deg) + 6deg)) scale(0.72);
  }
}

@keyframes animal-spawn {
  0% {
    opacity: 0;
    transform: translate(var(--x, 0px), calc(var(--y, 0px) + 16px)) rotate(var(--tilt, 0deg)) scale(0.76);
  }
  100% {
    opacity: 1;
    transform: translate(var(--x, 0px), var(--y, 0px)) rotate(var(--tilt, 0deg)) scale(1);
  }
}

@keyframes dust-puff {
  0% {
    opacity: 0.8;
    transform: translateY(0) scale(0.8);
  }
  100% {
    opacity: 0;
    transform: translateY(-10px) scale(1.4);
  }
}

@media (max-width: 480px) {
  .game-frame {
    padding: 14px;
  }

  .cta-button {
    width: 100%;
  }

  .legend {
    font-size: 0.74rem;
    padding: 5px 8px;
  }

  .hud {
    gap: 8px;
  }

  .hud-card {
    padding: 10px 8px;
  }

  .animal {
    width: 54px;
    height: 54px;
  }
}
