* {
  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 {
  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;
}

#active-player {
  flex-shrink: 0;
  font-weight: bold;
  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: 780px;
  padding: 0 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
}

#play-row {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
}

/* --- Gender --- */

#gender-bar {
  display: flex;
  gap: 0.8rem;
}

.gender-button {
  background: #ffffff;
  border: 3px solid transparent;
  border-radius: 16px;
  padding: 0.5rem 1.2rem;
  font-size: 1.05rem;
  font-family: inherit;
  font-weight: bold;
  color: #2b2d42;
  cursor: pointer;
  box-shadow: 0 4px 0 #6c8ebf;
  transition: transform 0.1s ease;
}

.gender-button:hover {
  transform: translateY(-3px);
}

.gender-button.active {
  border-color: #f6c343;
  background: #fff9c4;
}

/* --- Counters --- */

#counters {
  display: flex;
  gap: 1rem;
  width: 100%;
}

.counter {
  flex: 1;
  min-width: 0;
  background: #ffffff;
  border-radius: 18px;
  padding: 0.7rem 0.5rem;
  box-shadow: 0 5px 0 #6c8ebf;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.counter-label {
  font-size: 0.8rem;
  font-weight: bold;
  color: #5a5f7a;
  white-space: nowrap;
}

.counter-value {
  font-size: 2rem;
  font-weight: bold;
  color: #1e88e5;
  line-height: 1.1;
}

#muscleup-counter .counter-value {
  color: #ef6c00;
}

#combo-counter .counter-value {
  color: #8e24aa;
}

#onearm-counter .counter-value {
  color: #00838f;
}

.counter.bump {
  animation: counter-bump 0.45s ease;
}

@keyframes counter-bump {
  0% { transform: scale(1); }
  35% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* --- Scene --- */

#scene {
  position: relative;
  background: #ffffff;
  border-radius: 22px;
  box-shadow: 0 6px 0 #6c8ebf;
  padding: 0.6rem;
  display: flex;
  justify-content: center;
  overflow: hidden;
}

#figure {
  height: min(50vh, 380px);
  width: auto;
  display: block;
  border-radius: 16px;
  overflow: hidden;
}

#cheer {
  position: absolute;
  top: 68%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.3rem;
  font-weight: bold;
  color: #ef6c00;
  background: rgba(255, 255, 255, 0.92);
  border: 3px solid #f6c343;
  border-radius: 999px;
  padding: 0.35rem 1rem;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  z-index: 2;
}

#cheer.show {
  animation: cheer-pop 1.4s ease;
}

@keyframes cheer-pop {
  0% { opacity: 0; transform: translateX(-50%) translateY(10px) scale(0.7); }
  25% { opacity: 1; transform: translateX(-50%) translateY(-4px) scale(1.1); }
  70% { opacity: 1; transform: translateX(-50%) translateY(-16px) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-34px) scale(0.95); }
}

/* --- Side panel --- */

#side-panel {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  width: 220px;
  flex-shrink: 0;
}

#energy-box {
  background: #ffffff;
  border-radius: 18px;
  padding: 0.8rem;
  box-shadow: 0 5px 0 #6c8ebf;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  align-items: center;
}

#energy-label {
  font-weight: bold;
  font-size: 1rem;
}

#energy-track {
  width: 100%;
  height: 18px;
  background: #e3e8ef;
  border-radius: 999px;
  overflow: hidden;
}

#energy-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #7bd88f, #2e7d32);
  transition: width 0.35s ease;
}

#energy-value {
  font-weight: bold;
  font-size: 0.95rem;
  color: #2e7d32;
}

#energy-box.denied {
  animation: energy-shake 0.5s ease;
}

#energy-box.denied #energy-value {
  color: #b3151b;
}

#food-hint {
  margin: 0;
  font-size: 0.8rem;
  color: #5a5f7a;
  text-align: center;
}

/* --- Food bar --- */

#food-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
}

.food-button {
  position: relative;
  background: #ffffff;
  border: none;
  border-radius: 18px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  box-shadow: 0 5px 0 #b06a3b;
  transition: transform 0.1s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  font-family: inherit;
}

.food-button:hover {
  transform: translateY(-4px);
}

.food-button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #b06a3b;
}

.food-icon {
  font-size: 2.4rem;
  line-height: 1;
}

.food-key {
  font-size: 0.75rem;
  font-weight: bold;
  color: #8a5a30;
  border: 2px solid #d8a878;
  border-radius: 6px;
  padding: 0 0.4rem;
}

@keyframes energy-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.flying-food {
  position: fixed;
  font-size: 2.4rem;
  line-height: 1;
  pointer-events: none;
  z-index: 50;
}

/* --- Figure parts --- */

#grip-marks line {
  stroke: #5a6779;
  stroke-width: 1.6;
  stroke-linecap: round;
  opacity: 0.55;
}

#ground-shadow {
  fill: rgba(40, 60, 90, 0.16);
}

.hand {
  fill: url(#skin-grad);
  stroke: #c98040;
  stroke-width: 1.5;
}

#hair {
  fill: #4a3728;
}

/* Limb thickness is driven by variables so the figure can bulk up as combos
   are completed. */
#figure {
  --limb-w: 5;
  --torso-w: 7;
  --girdle-w: 6;
  --foot-w: 4.5;
}

.limb {
  stroke: #2b2d42;
  stroke-width: var(--limb-w);
  stroke-linecap: round;
}

.limb.torso {
  stroke-width: var(--torso-w);
}

.limb.shoulders,
.limb.hips {
  stroke-width: var(--girdle-w);
}

.limb.foot {
  stroke-width: var(--foot-w);
}

.joint {
  fill: #2b2d42;
}

.eye {
  fill: #2b2d42;
}

.mouth {
  fill: none;
  stroke: #2b2d42;
  stroke-width: 2.2;
  stroke-linecap: round;
}

.brow,
.eye-shut {
  fill: none;
  stroke: #2b2d42;
  stroke-width: 2.2;
  stroke-linecap: round;
}

.mouth-open {
  fill: #a03c3c;
}

.face-strain {
  opacity: 0;
}

.drop {
  fill: #6ec8f5;
  opacity: 0;
}

/* --- Animation wiring --- */

#camera {
  transform-box: view-box;
  transform-origin: 100px 39px;
}

#lower-body {
  transform-box: view-box;
  transform-origin: 100px 105px;
}

#torso-group {
  transform-box: view-box;
  transform-origin: 100px 105px;
}

#legs-group {
  transform-box: view-box;
  transform-origin: 100px 158px;
}

#head {
  transform-box: view-box;
  transform-origin: 100px 84px;
}

#arm-left {
  transform-box: view-box;
  transform-origin: 78px 39px;
}

#arm-right {
  transform-box: view-box;
  transform-origin: 122px 39px;
}

/* Hands stay locked on the bar. The arms shorten (and at the top of a muscle
   up flip past the bar) while the body rises to match, so the grip never
   detaches. */

#figure.pullup #lower-body { animation: body-pullup 0.75s cubic-bezier(0.4, 0, 0.35, 1); }
#figure.pullup .arm { animation: arm-pullup 0.75s cubic-bezier(0.4, 0, 0.35, 1); }
#figure.pullup .face-relaxed { animation: face-fade-out 0.75s ease; }
#figure.pullup .face-strain { animation: face-fade-in 0.75s ease; }
#figure.pullup .drop { animation: sweat-fly 0.75s ease; }

#figure.muscleup #lower-body { animation: body-muscleup 1.5s cubic-bezier(0.35, 0, 0.3, 1); }
#figure.muscleup .arm { animation: arm-muscleup 1.5s cubic-bezier(0.35, 0, 0.3, 1); }
#figure.muscleup .face-relaxed { animation: face-fade-out 1.5s ease; }
#figure.muscleup .face-strain { animation: face-fade-in 1.5s ease; }
#figure.muscleup .drop { animation: sweat-fly-big 1.5s ease; }

#figure.combo #lower-body { animation: body-combo 2.4s cubic-bezier(0.35, 0, 0.3, 1); }
#figure.combo #torso-group { animation: torso-combo 2.4s cubic-bezier(0.35, 0, 0.3, 1); }
#figure.combo #legs-group { animation: legs-combo 2.4s cubic-bezier(0.35, 0, 0.3, 1); }
#figure.combo .arm { animation: arm-combo 2.4s cubic-bezier(0.35, 0, 0.3, 1); }
#figure.combo #camera { animation: camera-combo 2.4s ease; }
#figure.combo .face-relaxed { animation: face-fade-out 2.4s ease; }
#figure.combo .face-strain { animation: face-fade-in 2.4s ease; }
#figure.combo .drop { animation: sweat-fly-big 2.4s ease; }

#figure .limb,
#figure .joint {
  transition: stroke-width 0.5s ease;
}

#figure.grow .limb {
  animation: muscle-flash 0.9s ease;
}

@keyframes muscle-flash {
  0%, 100% { stroke: #2b2d42; }
  40% { stroke: #2e7d32; }
}

#figure.eating #head { animation: chew 0.8s ease; }
#figure.eating .face-relaxed { animation: face-fade-out 0.8s ease; }
#figure.eating .face-strain { animation: face-fade-in 0.8s ease; }

/* One-arm routine: let go with the right hand, raise a steak to the mouth with
   it, eat, then pull up on the left arm alone. */

#free-arm {
  opacity: 0;
  transform-box: view-box;
  transform-origin: var(--free-arm-origin-x, 114px) 105px;
}

#free-steak {
  transform-box: fill-box;
  transform-origin: center;
  opacity: 0;
}

#figure.onearm #free-arm { animation: free-arm-onearm 3.2s ease; }
#figure.onearm #free-steak { animation: steak-onearm 3.2s ease; }
#figure.onearm #hand-right,
#figure.onearm #arm-right { animation: bar-arm-release 3.2s ease; }
#figure.onearm #lower-body { animation: body-onearm 3.2s ease; }
#figure.onearm #arm-left { animation: arm-onearm 3.2s ease; }
#figure.onearm #torso-group { animation: torso-onearm 3.2s ease; }
#figure.onearm #head { animation: head-onearm 3.2s ease; }
#figure.onearm .face-relaxed { animation: face-onearm-out 3.2s ease; }
#figure.onearm .face-strain { animation: face-onearm-in 3.2s ease; }

@keyframes free-arm-onearm {
  0% { opacity: 0; transform: rotate(0deg) scaleY(1); }
  7% { opacity: 1; transform: rotate(0deg) scaleY(1); }
  14% { transform: rotate(0deg) scaleY(1); }
  26% { transform: rotate(143deg) scaleY(0.42); }
  46% { transform: rotate(143deg) scaleY(0.42); }
  57% { transform: rotate(0deg) scaleY(1); }
  93% { opacity: 1; transform: rotate(0deg) scaleY(1); }
  100% { opacity: 0; transform: rotate(0deg) scaleY(1); }
}

@keyframes steak-onearm {
  0% { opacity: 0; transform: scale(1); }
  9% { opacity: 1; transform: scale(1); }
  32% { opacity: 1; transform: scale(1); }
  44% { opacity: 0; transform: scale(0.2); }
  100% { opacity: 0; transform: scale(0.2); }
}

@keyframes bar-arm-release {
  0% { opacity: 1; }
  7% { opacity: 0; }
  93% { opacity: 0; }
  100% { opacity: 1; }
}

@keyframes body-onearm {
  0% { transform: translateY(0); }
  58% { transform: translateY(0); }
  71% { transform: translateY(-72px); }
  84% { transform: translateY(0); }
  100% { transform: translateY(0); }
}

@keyframes arm-onearm {
  0% { transform: scaleY(1); }
  58% { transform: scaleY(1); }
  71% { transform: scaleY(-0.09); }
  84% { transform: scaleY(1); }
  100% { transform: scaleY(1); }
}

/* Hanging from the left hand alone pulls the body over under that grip. */
@keyframes torso-onearm {
  0% { transform: rotate(0deg); }
  10% { transform: rotate(7deg); }
  84% { transform: rotate(7deg); }
  100% { transform: rotate(0deg); }
}

@keyframes head-onearm {
  0%, 30%, 48%, 100% { transform: scale(1); }
  34% { transform: scale(1.14, 0.9); }
  38% { transform: scale(0.94, 1.1); }
  42% { transform: scale(1.12, 0.92); }
}

@keyframes face-onearm-out {
  0%, 29% { opacity: 1; }
  33%, 46% { opacity: 0; }
  50%, 60% { opacity: 1; }
  64%, 80% { opacity: 0; }
  86%, 100% { opacity: 1; }
}

@keyframes face-onearm-in {
  0%, 29% { opacity: 0; }
  33%, 46% { opacity: 1; }
  50%, 60% { opacity: 0; }
  64%, 80% { opacity: 1; }
  86%, 100% { opacity: 0; }
}

@keyframes body-pullup {
  0% { transform: translateY(0); }
  45% { transform: translateY(-72px); }
  100% { transform: translateY(0); }
}

@keyframes arm-pullup {
  0% { transform: scaleY(1); }
  45% { transform: scaleY(-0.09); }
  100% { transform: scaleY(1); }
}

@keyframes body-muscleup {
  0% { transform: translateY(0); }
  25% { transform: translateY(-72px); }
  55% { transform: translateY(-120px); }
  78% { transform: translateY(-120px); }
  100% { transform: translateY(0); }
}

@keyframes arm-muscleup {
  0% { transform: scaleY(1); }
  25% { transform: scaleY(-0.09); }
  55% { transform: scaleY(-0.82); }
  78% { transform: scaleY(-0.82); }
  100% { transform: scaleY(1); }
}

/* Combo: pull up, muscle up into a support above the bar, then press to a
   handstand. The legs are hinged at the hips so the body folds into a pike
   on the way up and extends into the handstand, instead of the whole body
   swinging round in one wide arc. */

@keyframes body-combo {
  0% { transform: translateY(0); }
  15% { transform: translateY(-72px); }
  32% { transform: translateY(-120px); }
  47% { transform: translateY(-132px); }
  56% { transform: translateY(-132px); }
  78% { transform: translateY(-132px); }
  88% { transform: translateY(-124px); }
  100% { transform: translateY(0); }
}

@keyframes torso-combo {
  0% { transform: rotate(0deg); }
  32% { transform: rotate(0deg); }
  39% { transform: rotate(22deg); }
  47% { transform: rotate(88deg); }
  56% { transform: rotate(180deg); }
  78% { transform: rotate(180deg); }
  88% { transform: rotate(90deg); }
  100% { transform: rotate(0deg); }
}

@keyframes legs-combo {
  0% { transform: rotate(0deg); }
  32% { transform: rotate(0deg); }
  39% { transform: rotate(58deg); }
  47% { transform: rotate(92deg); }
  56% { transform: rotate(0deg); }
  78% { transform: rotate(0deg); }
  88% { transform: rotate(90deg); }
  100% { transform: rotate(0deg); }
}

@keyframes arm-combo {
  0% { transform: scaleY(1); }
  15% { transform: scaleY(-0.09); }
  32% { transform: scaleY(-0.82); }
  47% { transform: scaleY(-1); }
  78% { transform: scaleY(-1); }
  88% { transform: scaleY(-0.9); }
  100% { transform: scaleY(1); }
}

@keyframes camera-combo {
  0% { transform: scale(1); }
  28% { transform: scale(1); }
  45% { transform: scale(0.58); }
  80% { transform: scale(0.58); }
  100% { transform: scale(1); }
}

@keyframes chew {
  0%, 100% { transform: scale(1); }
  18% { transform: scale(1.14, 0.9); }
  36% { transform: scale(0.94, 1.1); }
  54% { transform: scale(1.12, 0.92); }
  72% { transform: scale(0.97, 1.04); }
}

@keyframes face-fade-out {
  0% { opacity: 1; }
  18% { opacity: 0; }
  80% { opacity: 0; }
  100% { opacity: 1; }
}

@keyframes face-fade-in {
  0% { opacity: 0; }
  18% { opacity: 1; }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes sweat-fly {
  0% { opacity: 0; transform: translate(0, 0); }
  30% { opacity: 0.9; transform: translate(0, 0); }
  100% { opacity: 0; transform: translate(-6px, 26px); }
}

@keyframes sweat-fly-big {
  0% { opacity: 0; transform: translate(0, 0); }
  20% { opacity: 0.9; transform: translate(0, 0); }
  60% { opacity: 0.7; transform: translate(-8px, 30px); }
  100% { opacity: 0; transform: translate(-12px, 54px); }
}

.drop-2 { animation-delay: 0.05s !important; }
.drop-3 { animation-delay: 0.1s !important; }

/* --- Instructions --- */

#instructions {
  background: #fff9c4;
  border: 3px solid #f6c343;
  border-radius: 18px;
  padding: 0.7rem 0.8rem;
}

#instructions p {
  margin: 0.3rem 0;
  font-weight: bold;
  font-size: 0.85rem;
}

.instructions-title {
  text-align: center;
  font-size: 1rem !important;
  margin-top: 0 !important;
}

.instructions-note {
  font-size: 0.78rem !important;
  font-weight: normal !important;
  color: #6b5000;
  text-align: center;
  margin-bottom: 0 !important;
}

#instructions b {
  color: #b3151b;
}

.key {
  display: inline-block;
  background: #ffffff;
  border: 2px solid #d9b53a;
  border-radius: 8px;
  padding: 0.05rem 0.4rem;
  margin-right: 0.3rem;
  font-size: 0.78rem;
}

/* --- Girl variant --- */

.girl-only {
  display: none;
}

#figure.girl .girl-only {
  display: block;
}

#long-hair,
#fringe {
  fill: #f2c14e;
}

#figure.girl #hair {
  display: none;
}

#skirt {
  fill: #e05c8a;
}

/* Touch devices: no lingering hover state after a tap, and no double-tap zoom
   when a child taps quickly. */
button,
a {
  touch-action: manipulation;
}

@media (hover: none) {
  button:hover,
  a:hover,
  .game-card:hover,
  .category-button:hover,
  .choice-card:hover,
  .option-button:hover,
  .difficulty-button:hover,
  .food-button:hover,
  .gender-button:hover,
  .device-button:hover,
  .book-button:hover,
  .memory-card:hover {
    transform: none;
  }
}

/* Keyboard-only hints make no sense on a touch screen. */
@media (hover: none) and (pointer: coarse) {
  .kbd-hint {
    display: none;
  }
}
