:root {
  --background: 40 25% 98%;
  --surface: 36 28% 96%;
  --foreground: 22 18% 12%;
  --muted-foreground: 24 10% 42%;
  --border: 28 17% 84%;
  --border-soft: 28 16% 88%;
  --accent: 40 20% 94%;
  --focus: 28 60% 36%;
  --primary: 22 18% 12%;
  --radius: 14px;
  --slime: 120 100% 50%;
  --transition-fast: 140ms ease;
  --transition-medium: 180ms ease;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  touch-action: manipulation;
}

body {
  background: radial-gradient(circle at 10% 2%, hsl(40 35% 96%), transparent 28%),
    radial-gradient(circle at 100% 0%, hsl(32 30% 95%), transparent 30%),
    hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: Fredoka, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

a {
  color: inherit;
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.app {
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 980px;
  margin: 0 auto;
  padding: 0.9rem 0.95rem 1.2rem;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 0.55rem;
  margin-bottom: 0.85rem;
  position: relative;
  padding-right: 44px;
  z-index: 4;
}

.topbar-title-wrap {
  align-self: center;
  justify-self: start;
  text-align: left;
}

.app.home-mode .topbar {
  grid-template-columns: 1fr auto;
}

.app.home-mode #backBtn.hidden {
  display: none;
}

.app:not(.home-mode) .topbar-title-wrap {
  display: none;
}

.headline {
  margin: 0;
  font-family: Inter, sans-serif;
  font-weight: 900;
  letter-spacing: -0.04em;
  font-size: clamp(1.5rem, 5.8vw, 2rem);
  line-height: 1;
}

.header-subtitle {
  margin: 0.38rem 0 0;
  color: hsl(var(--muted-foreground));
  font-size: 0.91rem;
  line-height: 1.25;
  font-style: italic;
}

.view.hidden {
  display: none;
}

.view-active {
  display: block;
}

.subtitle {
  margin: 1rem 0 1rem;
  color: hsl(var(--muted-foreground));
  font-size: 0.98rem;
}

.app-footer {
  margin: auto 0 0;
  padding-top: 1.25rem;
  text-align: center;
  color: hsl(var(--muted-foreground) / 0.72);
  font-size: 0.74rem;
}

.toy-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.78rem;
}

.toy-card {
  width: 100%;
  min-height: 170px;
  border: 1px solid hsl(var(--border-soft));
  border-radius: calc(var(--radius) + 2px);
  background: linear-gradient(180deg, hsl(var(--surface)) 0%, hsl(var(--background)) 100%);
  cursor: pointer;
  overflow: hidden;
  padding: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  transition: transform var(--transition-medium), border-color var(--transition-medium), background-color var(--transition-medium);
}

.toy-card:hover {
  transform: scale(1.01);
  border-color: hsl(var(--border));
}

.toy-card:active {
  transform: scale(0.98);
}

.toy-card-body {
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.9rem 0.8rem 0.5rem;
}

.toy-card-body svg {
  width: 74%;
  height: 74%;
  color: hsl(0 0% 15% / 0.72);
  transition: color var(--transition-fast);
}

.toy-card:hover .toy-card-body svg,
.toy-card:focus-visible .toy-card-body svg {
  color: hsl(0 0% 12% / 0.9);
}

.toy-card-footer {
  border-top: 1px solid hsl(var(--border-soft));
  text-align: center;
  font-weight: 500;
  font-size: 0.93rem;
  letter-spacing: 0.01em;
  padding: 0.7rem 0.7rem 0.76rem;
}

.panel {
  margin: 0 auto;
  text-align: center;
  max-width: 44rem;
}

.toy-panel {
  min-height: clamp(28rem, 72dvh, 44rem);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}

.toy-body {
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.panel-wide {
  max-width: 64rem;
}

.panel-title {
  margin: 0.2rem 0 0;
  font-family: Inter, sans-serif;
  font-weight: 900;
  letter-spacing: -0.03em;
  font-size: clamp(1.8rem, 6vw, 2.2rem);
}

.panel-desc {
  margin: 0.32rem 0 0.85rem;
  color: hsl(var(--muted-foreground));
}

.toy-action-btn {
  margin-top: 0.35rem;
  justify-self: center;
  width: fit-content;
}

.btn {
  border: 1px solid transparent;
  border-radius: calc(var(--radius) - 4px);
  padding: 0.52rem 0.9rem;
  cursor: pointer;
  transition: background-color var(--transition-fast), transform var(--transition-fast), border-color var(--transition-fast);
}

.btn:hover {
  border-color: hsl(var(--border));
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-ghost {
  background: transparent;
}

.btn-ghost:hover {
  background: hsl(var(--accent));
}

.btn.hidden {
  visibility: hidden;
}

.icon-btn {
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 999px;
  cursor: pointer;
}

#muteBtn {
  position: absolute;
  top: 0;
  right: 0;
}

.icon-btn .icon {
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

.back-icon {
  font-size: 1.2rem;
  font-weight: 400;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
}

.topbar-spacer {
  width: 44px;
  height: 44px;
}

.icon {
  width: 21px;
  height: 21px;
}

.icon-sound-off {
  display: none;
}

.icon-btn.is-muted .icon-sound-on {
  display: none;
}

.icon-btn.is-muted .icon-sound-off {
  display: block;
}

.sr-only {
  border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

.spinner-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.spinner-btn {
  width: min(82vw, 24rem);
  height: min(82vw, 24rem);
  border: 0;
  background: transparent;
  color: hsl(var(--primary));
  padding: 0;
  cursor: grab;
  touch-action: none;
  transition: transform 120ms ease-out;
}

.spinner-btn.dragging {
  cursor: grabbing;
  transform: scale(0.95);
}

.spinner-stage {
  width: 100%;
  height: 100%;
  display: block;
  position: relative;
}

.fidget-spinner-rings {
  width: 100%;
  height: 100%;
  will-change: transform;
  backface-visibility: hidden;
}

.spinner-core {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  transform: translate(-50%, -50%);
  background: currentColor;
  pointer-events: none;
}

.counter {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0.22rem 0 0.75rem;
}

.counter-label {
  font-size: 1.05rem;
  font-family: Fredoka, sans-serif;
  font-weight: 400;
  color: hsl(var(--muted-foreground));
}

.push-pop-board {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.58rem;
  touch-action: none;
  padding: 0.45rem;
}

.push-pop-row {
  display: flex;
  gap: 0.62rem;
  justify-content: center;
}

.bubble {
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 999px;
  border: 2px solid hsl(var(--border));
  background: hsl(var(--background));
  transition: transform 100ms ease, background-color 100ms ease, border-color 100ms ease, opacity 180ms ease;
}

.bubble:hover {
  background: hsl(var(--accent));
}

.bubble:active {
  transform: scale(0.95);
}

.bubble.popped {
  background: hsl(var(--primary));
  border-color: hsl(var(--primary));
  box-shadow: inset 0 2px 6px rgb(0 0 0 / 0.25);
  transform: scale(0.9);
}

.bubble.completing {
  opacity: 0.5;
}

.pig-wrap {
  width: min(82vw, 24rem);
  height: min(82vw, 24rem);
  margin: 0 auto;
}

.pig-svg {
  width: 100%;
  height: 100%;
  color: hsl(var(--primary));
}

.pig-svg .face-part {
  transition: opacity 120ms ease;
}

.pig-svg.is-faceless .face-part {
  opacity: 0;
}

.cursor-pointer {
  cursor: pointer;
}

.slime-container {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  padding: 0;
  pointer-events: none;
  z-index: 1;
}

.slime-canvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 0;
  background: transparent;
  cursor: grab;
  touch-action: none;
  pointer-events: auto;
}

.slime-canvas:active {
  cursor: grabbing;
}

#slimeView .panel-title,
#slimeView .panel-desc,
#slimeView .toy-action-btn {
  position: relative;
  z-index: 3;
}

#slimeView .panel-title,
#slimeView .panel-desc {
  pointer-events: none;
}

.icon-anim-origin-center {
  transform-origin: center;
  transform-box: fill-box;
}

.icon-anim-origin-bottom {
  transform-origin: 50% 100%;
  transform-box: fill-box;
}

@keyframes squish {
  0%,
  100% {
    transform: scaleY(1);
  }

  50% {
    transform: scaleY(0.8);
  }
}

@keyframes wiggle {
  0%,
  100% {
    transform: translateY(0) rotate(0deg) scale(1);
  }

  15% {
    transform: translateY(-30%) rotate(-8deg) scale(1.1);
  }

  30% {
    transform: translateY(0) rotate(8deg) scale(1.1);
  }

  45% {
    transform: translateY(-15%) rotate(-4deg) scale(1.05);
  }

  60% {
    transform: translateY(0) rotate(4deg) scale(1.05);
  }

  75% {
    transform: translateY(-5%) rotate(-2deg) scale(1);
  }
}

@keyframes jiggle {
  0%,
  100% {
    transform: scale(1) rotate(0deg);
  }

  25% {
    transform: scale(1.1) rotate(-5deg);
  }

  50% {
    transform: scale(1.1) rotate(5deg);
  }

  75% {
    transform: scale(1.05) rotate(-2deg);
  }
}

@keyframes gentle-bounce {
  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-3%);
  }
}

@keyframes spin-slow {
  to {
    transform: rotate(360deg);
  }
}

@keyframes push-pop-pulse {
  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(0.85);
  }
}

@keyframes slime-wave {
  0%,
  100% {
    transform: scale(1, 1);
  }

  50% {
    transform: scale(1.05, 1.1);
  }
}

.animate-squish {
  animation: squish 0.2s ease-in-out;
}

.animate-wiggle {
  animation: wiggle 1.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.animate-jiggle {
  animation: jiggle 0.4s ease-out;
}

.animate-gentle-bounce {
  animation: gentle-bounce 2.5s ease-in-out infinite;
}

.animate-spin-slow {
  animation: spin-slow 12s linear infinite;
}

.animate-push-pop-pulse {
  animation: push-pop-pulse 2s ease-in-out infinite;
}

.animate-slime-wave {
  animation: slime-wave 4s ease-in-out infinite;
}

:focus-visible {
  outline: 2px solid hsl(var(--focus));
  outline-offset: 2px;
}

@media (max-width: 359px) {
  .toy-grid {
    grid-template-columns: 1fr;
  }

  .toy-card {
    min-height: 154px;
  }
}

@media (min-width: 640px) {
  .app {
    padding: 1.4rem 1.5rem 1.5rem;
  }

  .topbar {
    margin-bottom: 1rem;
  }

  .subtitle {
    margin-top: 1.25rem;
    margin-bottom: 1.2rem;
    font-size: 1.02rem;
  }

  .toy-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.95rem;
  }

  .bubble {
    width: 4rem;
    height: 4rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .toy-card:hover,
  .toy-card:active {
    transform: none;
  }
}
