* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

@font-face {
  font-family: "Peli Emoji";
  src: url("/fonts/NotoColorEmoji.woff2") format("woff2");
  font-display: swap;
}

/* The page itself never scrolls: on a touch screen that only lets a child
   drag the game out of view or rubber-band the whole layout. Anything that
   does not fit is scrolled inside <main> instead. */
html {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: "Comic Sans MS", "Trebuchet MS", Verdana, sans-serif;
  background: linear-gradient(180deg, #bde0fe 0%, #c9ecc0 100%);
  color: #2b2d42;
  display: flex;
  flex-direction: column;
  align-items: center;
  user-select: none;
}

:root.no-emoji-font body {
  font-family: "Comic Sans MS", "Trebuchet MS", Verdana, "Peli Emoji", sans-serif;
}

header {
  width: 100%;
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

#hub-link,
#active-player {
  flex-shrink: 0;
  color: #2b2d42;
  font-weight: bold;
  text-decoration: none;
  background: #ffffff;
  border-radius: 14px;
  padding: 0.5rem 0.9rem;
  box-shadow: 0 4px 0 #6c8ebf;
}

header h1 {
  margin: 0;
  font-size: 2.2rem;
  flex: 1;
  min-width: 0;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  max-width: 980px;
  padding: 0 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hidden {
  display: none !important;
}

/* ---------------- Levels ---------------- */

#category-view h2 {
  text-align: center;
}

#category-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.2rem;
  width: 100%;
  max-width: 620px;
}

.category-button {
  background: #ffffff;
  border: none;
  border-radius: 20px;
  padding: 1.3rem 1rem;
  font-size: 1.3rem;
  font-family: inherit;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 6px 0 #6c8ebf;
  transition: transform 0.1s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}

.category-button:hover { transform: translateY(-4px); }
.category-button:active { transform: translateY(3px); box-shadow: 0 2px 0 #6c8ebf; }

.category-button .icon {
  font-size: 3rem;
}

.category-desc {
  font-size: 0.85rem;
  font-weight: normal;
  color: #5a5f7a;
}

/* ---------------- Task ---------------- */

#game-view {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
}

#back-button {
  background: #ffffff;
  border: none;
  border-radius: 14px;
  padding: 0.6rem 1.1rem;
  font-size: 1rem;
  font-family: inherit;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 0 #6c8ebf;
}

/* The task is written large, like a note pinned up for the animals. */
#task-card {
  width: 100%;
  max-width: 760px;
  /* Clear of the back button, which sits in the row above. */
  margin-top: 1rem;
  background: #fffdf3;
  border: 3px solid #f0dca0;
  border-radius: 20px;
  box-shadow: 0 6px 0 #d4b45c;
  padding: 0.8rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

#task-card.fresh {
  animation: task-in 0.5s cubic-bezier(0.3, 1.5, 0.5, 1);
}

@keyframes task-in {
  from { transform: scale(0.9); opacity: 0.3; }
  to { transform: scale(1); opacity: 1; }
}

#task-card.done {
  background: #f1fff3;
  border-color: #9ad7a0;
  box-shadow: 0 6px 0 #2e7d32;
}

#task-picture {
  font-size: 3rem;
  line-height: 1;
}

#task-text {
  margin: 0;
  flex: 1;
  font-size: 1.9rem;
  font-weight: bold;
  line-height: 1.3;
  letter-spacing: 0.01em;
}

#listen-button {
  border: none;
  border-radius: 16px;
  background: #fff3bf;
  font-size: 1.6rem;
  min-width: 56px;
  min-height: 56px;
  cursor: pointer;
  box-shadow: 0 4px 0 #d4a418;
  flex-shrink: 0;
}

#task-progress {
  flex-shrink: 0;
  font-weight: bold;
  color: #8a7a4a;
  font-size: 0.95rem;
}

/* One dot per piece the animal still wants, filled as it eats. */
#task-dots {
  display: flex;
  gap: 0.4rem;
  min-height: 1.5rem;
}

#task-dots .dot {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  border: 3px solid #d4b45c;
  background: #ffffff;
  transition: background 0.3s ease, transform 0.3s ease;
}

#task-dots .dot.filled {
  background: #2e7d32;
  border-color: #2e7d32;
  transform: scale(1.1);
}

/* ---------------- The yard ---------------- */

#yard {
  position: relative;
  width: 100%;
  max-width: 900px;
  aspect-ratio: 16 / 9;
  border-radius: 24px;
  overflow: hidden;
  touch-action: none;
  background:
    radial-gradient(ellipse 30% 22% at 70% 60%, rgba(255, 255, 255, 0.12), transparent 70%),
    repeating-linear-gradient(115deg, rgba(255, 255, 255, 0.05) 0 14px, transparent 14px 28px),
    linear-gradient(180deg, #9fd67d 0%, #7cc35d 100%);
  box-shadow: 0 0 0 6px #ffffff, 0 10px 0 6px #5f9c49;
}

/* A picket fence along the top edge. */
#yard::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 9%;
  background:
    linear-gradient(180deg, transparent 0 38%, #f5ead6 38% 52%, transparent 52% 72%, #f5ead6 72% 86%, transparent 86%),
    repeating-linear-gradient(90deg, #fff8ea 0 14px, transparent 14px 30px);
  opacity: 0.95;
}

/* The animals' own corner, where each one waits at home. */
#yard::after {
  content: "";
  position: absolute;
  left: 0;
  top: 9%;
  bottom: 0;
  width: 20%;
  background: linear-gradient(90deg, rgba(196, 160, 104, 0.35), rgba(196, 160, 104, 0));
  border-right: 3px dashed rgba(255, 255, 255, 0.45);
}

#yard.narrow::after {
  width: 30%;
}

#yard-decor span {
  position: absolute;
  font-size: clamp(1rem, 2.4vw, 1.6rem);
  transform: translate(-50%, -50%);
  opacity: 0.9;
}

.home,
.food,
.animal {
  position: absolute;
  transform: translate(-50%, -50%);
  line-height: 1;
}

.home {
  font-size: clamp(2rem, 5vw, 3.2rem);
  opacity: 0.95;
}

.food {
  font-size: clamp(1.7rem, 4vw, 2.6rem);
  filter: drop-shadow(0 3px 0 rgba(0, 60, 0, 0.18));
  animation: food-in 0.5s cubic-bezier(0.3, 1.6, 0.5, 1) both;
}

@keyframes food-in {
  from { transform: translate(-50%, -50%) scale(0); }
  to { transform: translate(-50%, -50%) scale(1); }
}

.food.eaten {
  animation: food-eaten 0.4s ease forwards;
}

@keyframes food-eaten {
  to { transform: translate(-50%, -50%) scale(0) rotate(90deg); opacity: 0; }
}

/* "No thanks" from the animal: the food wobbles where it lies. */
.food.refused {
  animation: food-refused 0.4s ease;
}

@keyframes food-refused {
  0%, 100% { transform: translate(-50%, -50%) rotate(0deg); }
  30% { transform: translate(-50%, -50%) rotate(-14deg); }
  70% { transform: translate(-50%, -50%) rotate(14deg); }
}

/* ---------------- Animals ---------------- */

.animal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  cursor: grab;
  touch-action: none;
  z-index: 3;
  transition: left 0.9s ease, top 0.9s ease;
}

/* While a finger or the keys move it, the animal follows at once. */
.animal.moving {
  transition: none;
  cursor: grabbing;
  z-index: 5;
}

.animal-face {
  font-size: clamp(2.6rem, 6.5vw, 4.2rem);
  filter: drop-shadow(0 5px 2px rgba(0, 50, 0, 0.25));
  transition: transform 0.2s ease;
}

.animal.facing-left .animal-face {
  transform: scaleX(-1);
}

.animal.moving .animal-face {
  animation: walk 0.32s ease-in-out infinite alternate;
}

.animal.moving.facing-left .animal-face {
  animation-name: walk-left;
}

@keyframes walk {
  from { transform: translateY(0) rotate(-4deg); }
  to { transform: translateY(-6px) rotate(4deg); }
}

@keyframes walk-left {
  from { transform: scaleX(-1) translateY(0) rotate(-4deg); }
  to { transform: scaleX(-1) translateY(-6px) rotate(4deg); }
}

.animal.chomp .animal-face {
  animation: chomp 0.35s ease;
}

@keyframes chomp {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.18, 0.86); }
  70% { transform: scale(0.94, 1.08); }
}

/* The name under each animal: matching it to the word in the task is part of
   learning to read it. The number is for the keyboard. */
.animal-name {
  font-size: clamp(0.75rem, 1.7vw, 1rem);
  font-weight: bold;
  background: #ffffff;
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  box-shadow: 0 2px 0 rgba(0, 60, 0, 0.25);
  white-space: nowrap;
}

.animal-key {
  color: #6c8ebf;
  margin-right: 0.25rem;
}

.animal.selected .animal-name {
  background: #fff3bf;
  box-shadow: 0 0 0 3px #f6c343;
}

/* The full animal sits back down at home with a happy little hop. */
.animal.full .animal-face {
  animation: happy 0.6s ease 2;
}

@keyframes happy {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-14px); }
}

/* What the animal says when it is offered the wrong thing. */
.bubble {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 0.3rem;
  background: #ffffff;
  border-radius: 14px;
  padding: 0.35rem 0.7rem;
  font-size: clamp(0.85rem, 2vw, 1.15rem);
  font-weight: bold;
  white-space: nowrap;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.18);
  animation: bubble-in 0.3s cubic-bezier(0.3, 1.6, 0.5, 1);
  pointer-events: none;
}

.bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -7px;
  border-width: 7px 7px 0;
  border-style: solid;
  border-color: #ffffff transparent transparent;
}

.bubble.happy {
  background: #d7f7dc;
}

.bubble.happy::after {
  border-top-color: #d7f7dc;
}

@keyframes bubble-in {
  from { transform: translateX(-50%) scale(0.4); opacity: 0; }
  to { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* ---------------- Hints and the end of a round ---------------- */

#controls-hint {
  margin: 0.2rem 0 0;
  font-size: 0.9rem;
  color: #3d5a3a;
  text-align: center;
}

/* An arrow key pressed before any animal is chosen points at how to choose. */
#controls-hint.nudge {
  animation: nudge 0.6s ease;
}

@keyframes nudge {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.08); color: #b06a3b; }
}

#round-done {
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 0 6px 0 #2e7d32;
  padding: 1rem 1.4rem;
  text-align: center;
}

#round-done-title {
  margin: 0 0 0.8rem;
  font-size: 1.5rem;
  font-weight: bold;
}

#round-done-buttons {
  display: flex;
  gap: 0.8rem;
  justify-content: center;
  flex-wrap: wrap;
}

#round-done-buttons button {
  border: none;
  border-radius: 16px;
  font-family: inherit;
  font-weight: bold;
  font-size: 1.05rem;
  padding: 0.7rem 1.3rem;
  cursor: pointer;
  min-height: 48px;
}

#again-button {
  background: #d7f7dc;
  color: #1b5e20;
  box-shadow: 0 4px 0 #2e7d32;
}

#levels-button {
  background: #eef4ff;
  color: #2b2d42;
  box-shadow: 0 4px 0 #6c8ebf;
}

button,
a {
  touch-action: manipulation;
}

@media (hover: none) {
  button:hover,
  a:hover,
  .category-button:hover {
    transform: none;
  }
}

/* Keyboard hints make no sense on a touch screen, and the touch hint is
   noise for anyone holding a mouse. */
@media (hover: none) and (pointer: coarse) {
  .kbd-hint,
  .animal-key {
    display: none;
  }
}

@media (hover: hover) and (pointer: fine) {
  .touch-hint {
    display: none;
  }
}

/* A phone held upright: a taller yard, so there is room to walk. */
@media (max-width: 620px) {
  #yard {
    aspect-ratio: 4 / 5;
  }

  #task-text {
    font-size: 1.3rem;
  }

  #task-picture {
    font-size: 2.2rem;
  }

  #listen-button {
    min-width: 46px;
    min-height: 46px;
    font-size: 1.3rem;
  }

  #category-grid {
    gap: 0.7rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .animal-face,
  .food,
  .bubble {
    animation: none !important;
  }
}
