* { box-sizing: border-box; margin: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: #E6F1FB;
  color: #0C447C;
  /* Toddler-proofing: no text selection, callouts, double-tap zoom or tap flash. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

[hidden] { display: none !important; }

.view {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

svg { display: block; }

/* Round icon buttons */
.round {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #fff;
  display: grid;
  place-items: center;
  flex: none;
  transition: transform 0.12s;
}
.round:active { transform: scale(0.9); }
.round svg {
  width: 30px;
  height: 30px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.round.small { width: 44px; height: 44px; background: rgba(255, 255, 255, 0.7); }
.round.small svg { width: 22px; height: 22px; }
.round.big { width: 80px; height: 80px; background: var(--ink); color: #fff; }
.round.big svg { width: 40px; height: 40px; }

/* ---------- Home ---------- */
.home-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 8px;
}
.home-bar h1 { font-size: 30px; font-weight: 800; letter-spacing: -0.5px; }

.grid {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  padding: 8px 16px 24px;
  align-content: start;
}
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); gap: 18px; padding: 12px 24px 32px; } }
@media (min-width: 860px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 560px) and (orientation: landscape) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1100px) { .grid { grid-template-columns: repeat(6, 1fr); } }

.tile {
  aspect-ratio: 1;
  border-radius: 28px;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 20px;
  font-weight: 700;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.1);
  transition: transform 0.12s, box-shadow 0.12s;
}
.tile:active { transform: translateY(4px) scale(0.97); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1); }
.tile svg { width: 68%; height: 68%; }
.no-names .tile svg { width: 78%; height: 78%; }
.no-names .tile span,
.no-names .animal-name { display: none; }

.empty { grid-column: 1 / -1; text-align: center; padding: 48px 16px; font-size: 18px; }

/* ---------- Animal ---------- */
#animal { background: var(--bg); color: var(--ink); }

.animal-top { display: flex; padding: 16px 20px 0; }
.animal-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px 24px;
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
}

.stage {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.actor {
  position: relative;
  width: min(72vw, 52vh, 420px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}
.actor-art { width: 76%; height: 76%; display: block; transform-origin: 50% 85%; }
.actor-art svg { width: 100%; height: 100%; overflow: visible; }

.ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 6px solid #fff;
  opacity: 0;
  pointer-events: none;
}
.ring.r2 { inset: 9%; }
.playing .ring { animation: ring 1.4s ease-out infinite; }
.playing .ring.r2 { animation-delay: 0.35s; }
@keyframes ring {
  0% { opacity: 0; transform: scale(0.65); }
  40% { opacity: 0.9; }
  100% { opacity: 0; transform: scale(1.2); }
}

.animal-name { font-size: clamp(32px, 9vw, 56px); font-weight: 800; margin-top: 4px; }

.bubble {
  position: absolute;
  top: 2%;
  right: 6%;
  z-index: 1;
  max-width: 88%;
  text-align: center;
  line-height: 1.1;
  background: #fff;
  border-radius: 28px;
  padding: 8px 22px;
  font-size: clamp(26px, 8vw, 46px);
  font-weight: 800;
  transform: scale(0) rotate(8deg);
  transform-origin: 30% 100%;
  transition: transform 0.25s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.sounding .bubble { transform: scale(1) rotate(8deg); }

/* Idle: gentle breathing so the animal feels alive between taps. */
.actor-art { animation: breathe 3s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.04); } }

/* Eyes blink on every face. */
.eye { transform-box: fill-box; transform-origin: center; animation: blink 4s infinite; }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 97% { transform: scaleY(0.1); } }

/* One movement per animal while its sound plays. */
.playing .actor-art[data-move="bob"]    { animation: bob 0.9s ease-in-out infinite; }
.playing .actor-art[data-move="jump"]   { animation: jump 0.5s ease-out infinite; }
.playing .actor-art[data-move="wiggle"] { animation: wiggle 0.45s ease-in-out infinite; }
.playing .actor-art[data-move="waddle"] { animation: waddle 0.5s ease-in-out infinite; }
.playing .actor-art[data-move="hop"]    { animation: hop 0.6s ease-in-out infinite; }
.playing .actor-art[data-move="roar"]   { animation: roar 0.7s ease-in-out infinite; }
.playing .actor-art[data-move="stomp"]  { animation: stomp 0.8s ease-in-out infinite; }
.playing .actor-art[data-move="swing"]  { animation: swing 0.7s ease-in-out infinite; }

@keyframes bob    { 0%, 100% { transform: translateY(0) rotate(-5deg); } 50% { transform: translateY(-7%) rotate(5deg); } }
@keyframes jump   { 0%, 100% { transform: translateY(0) scale(1.05, 0.95); } 45% { transform: translateY(-16%) scale(0.96, 1.05); } }
@keyframes wiggle { 0%, 100% { transform: rotate(-9deg); } 50% { transform: rotate(9deg); } }
@keyframes waddle { 0%, 100% { transform: translateX(-6%) rotate(-8deg); } 50% { transform: translateX(6%) rotate(8deg); } }
@keyframes hop    { 0%, 100% { transform: translateY(0) scale(1.12, 0.85); } 50% { transform: translateY(-20%) scale(0.92, 1.1); } }
@keyframes roar   { 0%, 100% { transform: scale(1); } 20% { transform: scale(1.18) rotate(-3deg); } 40% { transform: scale(1.14) rotate(3deg); } 60% { transform: scale(1.18) rotate(-3deg); } }
@keyframes stomp  { 0%, 100% { transform: translateY(0) rotate(0); } 25% { transform: translateY(-6%) rotate(-6deg); } 50% { transform: translateY(2%) rotate(0); } 75% { transform: translateY(-6%) rotate(6deg); } }
@keyframes swing  { 0%, 100% { transform: translateX(-9%) rotate(12deg); } 50% { transform: translateX(9%) rotate(-12deg); } }

/* Entering an animal screen */
#animal.enter .actor { animation: pop-in 0.35s cubic-bezier(0.3, 1.5, 0.5, 1); }
@keyframes pop-in { from { transform: scale(0.4); opacity: 0; } }

/* Short screens (landscape phones): put the name beside nothing, shrink chrome. */
@media (max-height: 480px) {
  .animal-name { font-size: 28px; }
  .animal-bottom { position: absolute; left: 0; right: 0; bottom: 0; max-width: none; padding-bottom: 16px; }
  .actor { width: min(60vh, 50vw); }
}

/* ---------- Grown-ups ---------- */
#grownups {
  background: #F1EFE8;
  color: #2C2C2A;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
#grownups > * { width: 100%; max-width: 520px; margin-left: auto; margin-right: auto; flex: none; }

.gu-bar { display: flex; align-items: center; gap: 12px; padding: 16px; }
.gu-bar h2 { font-size: 22px; font-weight: 700; }
.gu-bar .round.small { background: #fff; }

#settings { padding-bottom: 32px; }
#grownups h3 { font-size: 14px; font-weight: 600; color: #5F5E5A; margin: 20px 32px 8px; }

.card { background: #fff; border-radius: 18px; margin: 0 16px 12px; overflow: hidden; }
#grownups > .card { width: calc(100% - 32px); max-width: 488px; }

.gate { text-align: center; padding: 28px 16px; font-size: 17px; }

.hold { position: relative; width: 96px; height: 96px; margin: 20px auto 0; display: grid; place-items: center; }
.hold-ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.hold-ring circle { fill: none; stroke-width: 6; }
.hold-ring .track { stroke: #D3D1C7; }
.hold-ring .progress { stroke: #1D9E75; stroke-linecap: round; stroke-dasharray: 176; stroke-dashoffset: 176; }
.hold.holding .progress { transition: stroke-dashoffset 3s linear; stroke-dashoffset: 0; }
.hold-icon { width: 36px; height: 36px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 56px;
  padding: 10px 16px;
  font-size: 17px;
  border-bottom: 1px solid #F1EFE8;
  width: 100%;
  text-align: left;
}
.card > .row:last-of-type { border-bottom: 0; }
.row-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.credits { margin: 0 32px 24px; font-size: 13px; line-height: 1.5; color: #5F5E5A; -webkit-user-select: text; user-select: text; }
.credits a { color: #0F6E56; }

.hint { padding: 0 16px 14px; font-size: 14px; color: #5F5E5A; line-height: 1.4; }

.toggle {
  appearance: none;
  -webkit-appearance: none;
  width: 52px;
  height: 32px;
  border-radius: 16px;
  background: #D3D1C7;
  position: relative;
  flex: none;
  transition: background 0.15s;
}
.toggle::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}
.toggle:checked { background: #1D9E75; }
.toggle:checked::after { transform: translateX(20px); }

input[type="range"] { width: 45%; accent-color: #1D9E75; }

.pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; padding: 14px; }
.pick-item {
  aspect-ratio: 1;
  border-radius: 16px;
  background: var(--bg);
  display: grid;
  place-items: center;
  position: relative;
  border: 3px solid transparent;
}
.pick-item svg { width: 72%; height: 72%; }
.pick-item[aria-pressed="true"] { border-color: #1D9E75; }
.pick-item[aria-pressed="false"] { opacity: 0.35; filter: grayscale(1); }

@media (prefers-reduced-motion: reduce) {
  .actor-art, .playing .actor-art[data-move], .eye { animation: none; }
  .playing .actor-art[data-move] { transform: scale(1.1); }
}
