* {
  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%, #a2d2ff 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.7rem;
}

#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;
}

#task-card {
  width: 100%;
  max-width: 760px;
  margin-top: 1rem;
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 0 6px 0 #f0a33a;
  border: 3px solid #ffd48a;
  padding: 0.7rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

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

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

#task-worker {
  font-size: 2.8rem;
  line-height: 1;
  flex-shrink: 0;
}

#task-body {
  flex: 1;
  min-width: 0;
}

#task-text {
  margin: 0;
  font-size: 1.9rem;
  font-weight: bold;
  line-height: 1.25;
}

/* "Tämä on 6." after a wrong star, or "Oikein!" after the right one. */
#task-feedback {
  margin: 0.15rem 0 0;
  min-height: 1.4rem;
  font-size: 1.1rem;
  font-weight: bold;
  color: #b06a3b;
}

#task-feedback.ok {
  color: #2e7d32;
}

#hint-button,
#listen-button {
  border: none;
  border-radius: 16px;
  font-size: 1.6rem;
  min-width: 56px;
  min-height: 56px;
  cursor: pointer;
  flex-shrink: 0;
}

#listen-button {
  background: #fff3bf;
  box-shadow: 0 4px 0 #d4a418;
}

#hint-button {
  background: #eef4ff;
  box-shadow: 0 4px 0 #6c8ebf;
}

/* The sum laid out as dots: "●●● + ●●●●", or for a take-away, the dots that
   are taken away crossed out. Counting them gives the answer. */
#hint {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.4rem;
  font-size: 1.2rem;
  font-weight: bold;
}

.hint-dot {
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 50%;
  background: #f0a33a;
}

.hint-dot.b {
  background: #6c8ebf;
}

.hint-dot.away {
  background: #ffffff;
  border: 2px dashed #b06a3b;
  position: relative;
}

.hint-dot.away::after {
  content: "✕";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: #b06a3b;
}

.hint-sign {
  margin: 0 0.2rem;
}

#status-row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  font-weight: bold;
}

#status-row > span {
  background: rgba(255, 255, 255, 0.8);
  border-radius: 12px;
  padding: 0.3rem 0.8rem;
}

#hearts b {
  color: #d63c5e;
}

#hearts.bump {
  animation: bump 0.5s ease;
}

@keyframes bump {
  40% { transform: scale(1.25); }
}

/* ---------------- The scene ---------------- */

#scene {
  --frame-light: #6fb7ff;
  --frame-dark: #2f6fb5;
  position: relative;
  width: 100%;
  max-width: 900px;
  aspect-ratio: 16 / 10;
  /* The trampoline must stay in sight below the task, also on a tablet held
     sideways: the sky gives up height rather than the ground disappearing.
     The stars are placed in percentages, so they simply sit closer. */
  max-height: max(300px, calc(100vh - 310px));
  max-height: max(300px, calc(100dvh - 310px));
  border-radius: 24px;
  overflow: hidden;
  touch-action: manipulation;
  background: linear-gradient(180deg, #2c3e8f 0%, #5b6fc8 38%, #a7b9f0 72%, #ffd9a8 100%);
  box-shadow: 0 0 0 6px #ffffff, 0 10px 0 6px #6c8ebf;
}

/* Each level the worker builds the trampoline anew, in its own colours. */
#scene[data-taso="1"] { --frame-light: #7bd88f; --frame-dark: #2e7d32; }
#scene[data-taso="2"] { --frame-light: #ffb562; --frame-dark: #e0702a; }
#scene[data-taso="3"] { --frame-light: #d89bf0; --frame-dark: #8e24aa; }

.cloud {
  position: absolute;
  width: 16%;
  height: 5%;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.35);
  animation: drift 60s linear infinite;
}

.cloud::before {
  content: "";
  position: absolute;
  left: 18%;
  bottom: 35%;
  width: 40%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: inherit;
}

.cloud-a { top: 22%; animation-delay: -20s; }
.cloud-b { top: 52%; animation-duration: 85s; animation-delay: -55s; width: 11%; }

@keyframes drift {
  from { left: -20%; }
  to { left: 110%; }
}

#ground {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 12%;
  background: linear-gradient(180deg, #8fd16b 0%, #5fa846 100%);
  border-top: 3px solid #a7e083;
}

/* ---------------- Stars ---------------- */

.star {
  position: absolute;
  width: var(--star-size, 56px);
  height: var(--star-size, 56px);
  transform: translate(-50%, -50%);
  border: none;
  padding: 0;
  background: none;
  cursor: pointer;
  z-index: 2;
}

/* A five-pointed star drawn with a clip path, so the number sits in a plain
   yellow middle and stays easy to read. */
.star::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 45%, #fff6b0 0%, #ffd84d 55%, #f0a33a 100%);
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  filter: drop-shadow(0 0 6px rgba(255, 230, 120, 0.7));
  transition: transform 0.2s ease;
}

.star-number {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding-top: 8%;
  font-family: inherit;
  font-size: calc(var(--star-size, 56px) * 0.36);
  font-weight: bold;
  color: #2b2d42;
}

.star:hover::before {
  transform: scale(1.12);
}

.star.lit::before {
  background: radial-gradient(circle at 50% 45%, #ffffff 0%, #fff27a 45%, #ffcf2e 100%);
  filter: drop-shadow(0 0 14px rgba(255, 245, 160, 1));
}

.star.caught {
  animation: caught 0.7s ease;
}

@keyframes caught {
  0% { transform: translate(-50%, -50%) scale(1); }
  40% { transform: translate(-50%, -50%) scale(1.45) rotate(18deg); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

.star.wrong {
  animation: wrong 0.45s ease;
}

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

/* ---------------- Trampoline, worker, jumper ---------------- */

#trampoline {
  position: absolute;
  left: 50%;
  bottom: 4%;
  width: 26%;
  transform: translateX(-50%);
  transform-origin: 50% 100%;
  z-index: 1;
}

#trampoline svg {
  display: block;
  width: 100%;
  height: auto;
}

#mat {
  transform-box: fill-box;
  transform-origin: 50% 30%;
}

#trampoline.boing #mat {
  animation: boing 0.45s ease;
}

@keyframes boing {
  30% { transform: scaleY(1.9) translateY(4px); }
  60% { transform: scaleY(0.8); }
}

/* Built up from nothing by the worker when a level begins. */
#trampoline.building {
  animation: build 1.4s cubic-bezier(0.3, 1.4, 0.5, 1);
}

@keyframes build {
  0% { transform: translateX(-50%) scale(0.2, 0.05); opacity: 0.2; }
  60% { transform: translateX(-50%) scale(1.05, 1.05); opacity: 1; }
  100% { transform: translateX(-50%) scale(1); }
}

#worker {
  position: absolute;
  right: 5%;
  bottom: 9%;
  display: flex;
  align-items: flex-end;
  gap: 0.1rem;
  font-size: clamp(1.8rem, 5vw, 3.2rem);
  line-height: 1;
  z-index: 2;
}

#toolbox {
  font-size: 0.6em;
}

#hammer {
  font-size: 0.65em;
  transform-origin: 20% 80%;
  margin-left: -0.2em;
  margin-bottom: 0.4em;
}

#worker.hammering #hammer {
  animation: hammer 0.3s ease-in-out 4;
}

@keyframes hammer {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-55deg); }
}

#worker.cheer #worker-body {
  animation: cheer 0.5s ease 3;
}

@keyframes cheer {
  50% { transform: translateY(-12px); }
}

#jumper {
  position: absolute;
  left: 0;
  top: 0;
  font-size: clamp(2.2rem, 6vw, 3.6rem);
  line-height: 1;
  z-index: 4;
  will-change: transform;
  pointer-events: none;
}

#jumper-face {
  display: block;
  filter: drop-shadow(0 4px 3px rgba(0, 0, 0, 0.25));
}

/* While waiting on the trampoline, a gentle bounce on the spot. */
#jumper.idle #jumper-face {
  animation: idle 1.2s ease-in-out infinite;
}

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

#effects {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.flying-heart,
.sparkle {
  position: absolute;
  line-height: 1;
}

.flying-heart {
  font-size: 2rem;
}

.sparkle {
  font-size: 1.2rem;
  animation: sparkle 0.8s ease-out forwards;
}

@keyframes sparkle {
  from { transform: translate(-50%, -50%) scale(0.4); opacity: 1; }
  to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.2); opacity: 0; }
}

/* ---------------- End of a round ---------------- */

#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;
  font-size: 1.6rem;
  font-weight: bold;
}

#round-done-hearts {
  margin: 0.4rem 0 0.8rem;
  font-size: 1.6rem;
  letter-spacing: 0.1rem;
}

#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,
  .star:hover::before {
    transform: none;
  }
}

/* A phone held upright: a taller sky, so the stars do not crowd together. */
@media (max-width: 620px) {
  #scene {
    aspect-ratio: 3 / 4;
  }

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

  #task-worker {
    font-size: 2rem;
  }

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

  #trampoline {
    width: 40%;
  }

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

@media (prefers-reduced-motion: reduce) {
  .cloud,
  #jumper.idle #jumper-face,
  .sparkle {
    animation: none !important;
  }
}
