:root {
  color-scheme: light;
  --ink: #1f2933;
  --muted: #64748b;
  --paper: #fffdf6;
  --sun: #ffd45a;
  --banana: #ffe26f;
  --banana-edge: #f5b82f;
  --chicken: #fff8df;
  --comb: #ff6b5f;
  --beak: #ffad33;
  --leaf: #35b779;
  --berry: #dc5a7a;
  --sky: #9bdcf7;
  --blue: #4f8edb;
  --shadow: 0 18px 50px rgba(31, 41, 51, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: ui-rounded, "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 12%, rgba(255, 212, 90, 0.55), transparent 25rem),
    radial-gradient(circle at 88% 18%, rgba(155, 220, 247, 0.7), transparent 22rem),
    linear-gradient(135deg, #fff7bf 0%, #f6fbff 54%, #e8ffe9 100%);
}

button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  padding: 0.8rem 1rem;
  font: inherit;
  font-weight: 800;
  color: #152233;
  background: white;
  box-shadow: 0 4px 0 rgba(31, 41, 51, 0.22);
  cursor: pointer;
  touch-action: manipulation;
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(31, 41, 51, 0.22);
}

button:focus-visible {
  outline: 4px solid rgba(79, 142, 219, 0.45);
  outline-offset: 3px;
}

.app {
  width: min(1120px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.home-screen {
  min-height: calc(100vh - 64px);
  display: none;
  align-content: center;
  padding: clamp(20px, 5vw, 58px);
  border: 3px solid rgba(31, 41, 51, 0.08);
  border-radius: 8px;
  background: rgba(255, 253, 246, 0.88);
  box-shadow: var(--shadow);
}

.home-screen.active {
  display: grid;
}

.home-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 260px);
  gap: clamp(18px, 5vw, 44px);
  align-items: center;
}

.home-mascot {
  width: min(100%, 260px);
  justify-self: end;
  filter: drop-shadow(0 16px 0 rgba(31, 41, 51, 0.08));
}

.game-menu {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: clamp(16px, 3vw, 26px);
  margin-top: clamp(24px, 5vw, 46px);
}

.game-card {
  min-height: 230px;
  display: grid;
  align-content: space-between;
  justify-items: start;
  padding: clamp(18px, 4vw, 30px);
  color: var(--ink);
  text-align: left;
}

.game-card-title {
  font-size: clamp(2rem, 5vw, 4rem);
  font-weight: 1000;
  line-height: 0.95;
}

.game-card-art {
  display: block;
  width: 100%;
  border: 3px dashed rgba(31, 41, 51, 0.2);
  border-radius: 8px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.74);
  font-size: clamp(1.1rem, 2.5vw, 1.55rem);
  font-weight: 900;
}

.word-card {
  background: var(--sun);
}

.munch-card {
  background: #b7f2b5;
}

.stage,
.word-lab,
.muncher-stage {
  border: 3px solid rgba(31, 41, 51, 0.08);
  border-radius: 8px;
  background: rgba(255, 253, 246, 0.88);
  box-shadow: var(--shadow);
}

.stage {
  overflow: hidden;
}

.topbar,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  padding: 22px clamp(18px, 4vw, 42px) 8px;
}

.kicker {
  margin: 0 0 4px;
  color: var(--berry);
  font-size: clamp(0.95rem, 2vw, 1.1rem);
  font-weight: 900;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  max-width: 12ch;
  font-size: clamp(2.25rem, 8vw, 5.8rem);
  line-height: 0.92;
}

h2 {
  font-size: clamp(1.4rem, 4vw, 2.3rem);
}

.icon-button {
  flex: 0 0 auto;
  background: var(--sky);
}

.square-button {
  width: 52px;
  min-height: 52px;
  display: grid;
  place-items: center;
  padding: 0;
}

.square-button svg,
.d-pad svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.hero {
  display: grid;
  grid-template-columns: minmax(230px, 0.9fr) minmax(280px, 1.1fr);
  gap: clamp(18px, 4vw, 46px);
  align-items: end;
  padding: 8px clamp(18px, 4vw, 42px) 32px;
}

.mascot-wrap {
  position: relative;
  min-height: 320px;
  display: grid;
  place-items: center;
}

.mascot {
  width: min(100%, 360px);
  filter: drop-shadow(0 18px 0 rgba(31, 41, 51, 0.08));
  transform-origin: 50% 78%;
  cursor: pointer;
}

.banana {
  fill: var(--banana);
  stroke: var(--ink);
  stroke-width: 7;
  stroke-linejoin: round;
}

.banana-edge,
.smile,
.leg,
.foot {
  fill: none;
  stroke: var(--ink);
  stroke-width: 7;
  stroke-linecap: round;
}

.banana-edge {
  stroke: var(--banana-edge);
}

.body,
.head {
  fill: var(--chicken);
  stroke: var(--ink);
  stroke-width: 7;
}

.comb {
  fill: var(--comb);
  stroke: var(--ink);
  stroke-width: 7;
  stroke-linejoin: round;
}

.wing {
  fill: #ffefad;
  stroke: var(--ink);
  stroke-width: 7;
  stroke-linecap: round;
}

.eye {
  fill: var(--ink);
}

.beak {
  fill: var(--beak);
  stroke: var(--ink);
  stroke-width: 7;
  stroke-linejoin: round;
}

.spot {
  fill: var(--leaf);
  stroke: var(--ink);
  stroke-width: 5;
}

.spot-b {
  fill: var(--berry);
}

.phrase-panel {
  display: grid;
  gap: 18px;
}

.phrase {
  min-height: 165px;
  display: flex;
  align-items: center;
  border: 4px dashed rgba(31, 41, 51, 0.22);
  border-radius: 8px;
  padding: clamp(18px, 4vw, 30px);
  background: #ffffff;
  font-size: clamp(2rem, 7vw, 4.8rem);
  font-weight: 1000;
  line-height: 1;
  word-break: break-word;
}

.actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.icon-action {
  display: grid;
  place-items: center;
}

.icon-action svg {
  width: 30px;
  height: 30px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#speakButton {
  background: #b7f2b5;
}

#surpriseButton {
  background: #ffd1df;
}

#clearButton {
  background: #d9e7ff;
}

.word-lab {
  margin-top: 18px;
  padding: clamp(16px, 3vw, 24px);
}

.word-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.word-button {
  min-height: 86px;
  color: white;
  text-shadow: 0 2px 0 rgba(31, 41, 51, 0.22);
}

.word-button:nth-child(6n + 1) {
  background: #e95f6a;
}

.word-button:nth-child(6n + 2) {
  background: #e5a900;
}

.word-button:nth-child(6n + 3) {
  background: #2fa76b;
}

.word-button:nth-child(6n + 4) {
  background: #4f8edb;
}

.word-button:nth-child(6n + 5) {
  background: #8c6be8;
}

.word-button:nth-child(6n + 6) {
  background: #e87532;
}

.muncher-stage {
  overflow: hidden;
}

.muncher-wrap {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 260px;
  gap: clamp(16px, 3vw, 28px);
  align-items: start;
  padding: 12px clamp(18px, 4vw, 42px) clamp(20px, 4vw, 42px);
}

.muncher-playfield {
  display: grid;
  justify-items: center;
  gap: 10px;
}

.muncher-board {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 6px;
  width: min(100%, 680px);
  border: 5px solid rgba(31, 41, 51, 0.16);
  border-radius: 8px;
  padding: 8px;
  background:
    linear-gradient(45deg, rgba(53, 183, 121, 0.14) 25%, transparent 25% 75%, rgba(53, 183, 121, 0.14) 75%),
    #f7ffe8;
  background-size: 48px 48px;
}

.muncher-cell {
  aspect-ratio: 1;
  position: relative;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: inset 0 0 0 2px rgba(31, 41, 51, 0.06);
}

.mini-banana {
  width: 42%;
  height: 66%;
  display: block;
  border: 5px solid var(--ink);
  border-left: 0;
  border-top-color: var(--banana-edge);
  border-radius: 0 90% 90% 0;
  background: var(--banana);
  transform: rotate(28deg);
}

.mini-chicken {
  position: relative;
  width: 58%;
  aspect-ratio: 1;
  border: 5px solid var(--ink);
  border-radius: 50%;
  background: var(--chicken);
  box-shadow: 0 6px 0 rgba(31, 41, 51, 0.1);
}

.mini-chicken::before {
  content: "";
  position: absolute;
  left: 18%;
  top: -26%;
  width: 52%;
  height: 32%;
  border: 4px solid var(--ink);
  border-radius: 60% 60% 35% 35%;
  background: var(--comb);
}

.mini-chicken::after {
  content: "";
  position: absolute;
  right: -24%;
  top: 36%;
  width: 38%;
  height: 28%;
  border: 4px solid var(--ink);
  clip-path: polygon(0 0, 100% 50%, 0 100%);
  background: var(--beak);
}

.mini-monster {
  display: grid;
  place-items: center;
  width: 72%;
  aspect-ratio: 1;
  border: 5px solid var(--ink);
  border-radius: 8px;
  background: #8c6be8;
  color: white;
  font-size: clamp(1rem, 3vw, 2.1rem);
  font-weight: 1000;
  line-height: 1;
  box-shadow: 0 6px 0 rgba(31, 41, 51, 0.12);
}

.catch-burst {
  position: absolute;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 96%;
  aspect-ratio: 1;
  clip-path: polygon(50% 0%, 59% 29%, 88% 12%, 71% 41%, 100% 50%, 71% 59%, 88% 88%, 59% 71%, 50% 100%, 41% 71%, 12% 88%, 29% 59%, 0% 50%, 29% 41%, 12% 12%, 41% 29%);
  background: #ffd45a;
  box-shadow: inset 0 0 0 4px #ff7b54, 0 0 0 4px rgba(31, 41, 51, 0.12);
  transform: rotate(-10deg);
  animation: burst-pop 900ms ease-out infinite;
}

.catch-burst::after {
  content: "";
  width: 38%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #ff5c35;
  box-shadow: 0 0 0 8px rgba(255, 255, 255, 0.64);
}

.mini-eye {
  position: absolute;
  left: 34%;
  top: 38%;
  width: 11%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--ink);
}

.muncher-panel {
  display: grid;
  gap: 14px;
}

.score-box {
  display: grid;
  gap: 4px;
  border-radius: 8px;
  padding: 16px;
  background: white;
  box-shadow: inset 0 0 0 3px rgba(31, 41, 51, 0.08);
}

.score-box span {
  color: var(--muted);
  font-weight: 900;
}

.score-box strong {
  font-size: clamp(3rem, 7vw, 5rem);
  line-height: 1;
}

.time-box strong {
  color: #8c3fd8;
}

.level-box strong {
  color: #2fa76b;
}

.score-total-box strong {
  color: #e87532;
}

.role-box strong {
  color: #8c3fd8;
  font-size: clamp(1.8rem, 4vw, 2.8rem);
}

.lives-meter {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border-radius: 8px;
  padding: 16px;
  background: white;
  box-shadow: inset 0 0 0 3px rgba(31, 41, 51, 0.08);
}

.life-icon {
  position: relative;
  width: 30px;
  aspect-ratio: 1;
  transform: rotate(-45deg);
  border: 3px solid var(--ink);
  border-top: 0;
  border-right: 0;
  border-radius: 0 0 0 8px;
  background: #d8dee9;
  opacity: 0.34;
}

.life-icon::before,
.life-icon::after {
  content: "";
  position: absolute;
  width: 100%;
  aspect-ratio: 1;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: inherit;
}

.life-icon::before {
  left: 0;
  top: -50%;
  border-bottom-color: transparent;
}

.life-icon::after {
  left: 50%;
  top: 0;
  border-left-color: transparent;
}

.life-icon.active {
  background: #e95f6a;
  opacity: 1;
}

.flip-button {
  background: #ffd1df;
}

.muncher-status {
  min-height: 72px;
  border-radius: 8px;
  padding: 14px;
  background: white;
  font-size: 1.2rem;
  font-weight: 900;
  line-height: 1.2;
}

.control-hint {
  border-radius: 8px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.76);
  color: var(--muted);
  font-weight: 900;
}

.d-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: min(100%, 290px);
}

.d-pad button {
  min-height: 54px;
  display: grid;
  place-items: center;
  padding: 0;
  background: #d9e7ff;
}

.d-pad button[data-move="up"] {
  grid-column: 2;
}

.d-pad button[data-move="left"] {
  grid-column: 1;
}

.d-pad button[data-move="right"] {
  grid-column: 3;
}

.d-pad button[data-move="down"] {
  grid-column: 2;
}

.confetti {
  position: fixed;
  top: -24px;
  left: var(--x);
  z-index: 10;
  width: 14px;
  height: 22px;
  border-radius: 3px;
  background: var(--c);
  pointer-events: none;
  animation: fall 850ms ease-in forwards;
}

.dancing {
  animation: wiggle 700ms ease-in-out;
}

@keyframes wiggle {
  0%,
  100% {
    transform: rotate(0deg) scale(1);
  }
  18% {
    transform: rotate(-8deg) scale(1.04);
  }
  36% {
    transform: rotate(9deg) scale(0.99);
  }
  54% {
    transform: rotate(-6deg) scale(1.06);
  }
  72% {
    transform: rotate(7deg) scale(1);
  }
}

@keyframes fall {
  to {
    transform: translateY(105vh) rotate(360deg);
    opacity: 0;
  }
}

@keyframes burst-pop {
  0% {
    transform: rotate(-10deg) scale(0.72);
    opacity: 0;
  }
  18% {
    transform: rotate(8deg) scale(1.12);
    opacity: 1;
  }
  100% {
    transform: rotate(-8deg) scale(1);
    opacity: 1;
  }
}

@media (max-width: 780px) {
  .app {
    width: min(100% - 16px, 1120px);
    padding: 8px 0 18px;
  }

  .home-screen {
    min-height: auto;
    padding: 18px;
  }

  .topbar {
    align-items: center;
    gap: 10px;
    padding: 12px 12px 8px;
  }

  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    flex-wrap: nowrap;
    gap: 8px;
    justify-content: flex-end;
  }

  .square-button {
    width: 46px;
    min-height: 46px;
  }

  .square-button svg,
  .d-pad svg {
    width: 24px;
    height: 24px;
  }

  .game-card {
    min-height: 150px;
  }

  .game-card-art {
    padding: 12px;
  }

  h1 {
    max-width: 10ch;
  }

  #muncherTitle {
    font-size: clamp(2rem, 10vw, 3.1rem);
  }

  .hero {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 0 16px 18px;
  }

  .mascot-wrap {
    min-height: 220px;
  }

  .mascot {
    width: min(72vw, 250px);
  }

  .actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .phrase {
    min-height: 104px;
    padding: 16px;
  }

  .game-menu,
  .muncher-wrap {
    grid-template-columns: 1fr;
  }

  .home-hero {
    grid-template-columns: 1fr;
  }

  .home-mascot {
    justify-self: center;
    width: min(70vw, 240px);
  }

  .muncher-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .muncher-board {
    margin-inline: auto;
    width: min(100%, 350px);
    gap: 4px;
    padding: 6px;
    border-width: 4px;
  }

  .d-pad {
    width: min(100%, 240px);
    gap: 6px;
  }

  .d-pad button {
    min-height: 46px;
  }

  .score-box {
    min-height: 58px;
    gap: 2px;
    padding: 7px 6px;
  }

  .lives-meter {
    min-height: 58px;
    gap: 8px;
    padding: 7px 6px;
  }

  .life-icon {
    width: 22px;
    border-width: 2px;
  }

  .life-icon::before,
  .life-icon::after {
    border-width: 2px;
  }

  .score-box span {
    font-size: 0.72rem;
    line-height: 1;
  }

  .score-box strong,
  .role-box strong {
    font-size: 1.42rem;
  }

  .muncher-status {
    grid-column: 1 / -1;
    min-height: 0;
    padding: 8px 10px;
    font-size: 0.95rem;
  }

  .control-hint {
    display: none;
  }

}

@media (max-width: 430px) {
  .app {
    width: min(100% - 18px, 1120px);
    padding-top: 10px;
  }

  .word-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .word-button {
    min-height: 76px;
    padding-inline: 0.5rem;
  }

  .actions button {
    padding-inline: 0.35rem;
    font-size: 0.9rem;
  }

  .home-mascot {
    width: min(58vw, 190px);
  }

  .game-menu {
    gap: 12px;
    margin-top: 18px;
  }

  .game-card {
    min-height: 128px;
    padding: 14px;
  }

  .muncher-wrap {
    gap: 8px;
    padding: 6px 8px 14px;
  }

  .muncher-stage .topbar {
    padding: 10px 8px 6px;
  }

  .muncher-stage .kicker {
    display: none;
  }

  #muncherTitle {
    max-width: 7ch;
    font-size: clamp(1.62rem, 9vw, 2.35rem);
  }

  .square-button {
    width: 40px;
    min-height: 40px;
  }

  .square-button svg,
  .d-pad svg {
    width: 22px;
    height: 22px;
  }

  .muncher-board {
    width: min(100%, 332px);
    gap: 3px;
    padding: 5px;
    border-width: 3px;
  }

  .d-pad {
    width: min(100%, 208px);
    gap: 5px;
  }

  .d-pad button {
    min-height: 39px;
  }

  .mini-banana {
    border-width: 3px;
  }

  .mini-chicken,
  .mini-monster {
    border-width: 3px;
  }

  .mini-chicken::before,
  .mini-chicken::after {
    border-width: 3px;
  }

  .score-box {
    padding-inline: 6px;
  }

  .lives-meter {
    padding-inline: 6px;
  }

  .role-box strong {
    font-size: 1.2rem;
  }
}

@media (max-width: 360px) {
  .app {
    width: min(100% - 12px, 1120px);
    padding: 4px 0 10px;
  }

  .muncher-stage .topbar {
    gap: 6px;
  }

  #muncherTitle {
    font-size: 1.45rem;
  }

  .top-actions {
    gap: 5px;
  }

  .square-button {
    width: 36px;
    min-height: 36px;
  }

  .muncher-wrap {
    gap: 6px;
    padding: 4px 6px 10px;
  }

  .muncher-board {
    width: min(100%, 286px);
    gap: 2px;
    padding: 4px;
  }

  .d-pad {
    width: 176px;
    gap: 4px;
  }

  .d-pad button {
    min-height: 32px;
  }

  .muncher-panel {
    gap: 4px;
  }

  .score-box {
    min-height: 50px;
    padding: 5px;
  }

  .lives-meter {
    min-height: 50px;
    gap: 6px;
    padding: 5px;
  }

  .life-icon {
    width: 18px;
  }

  .score-box span {
    font-size: 0.66rem;
  }

  .score-box strong,
  .role-box strong {
    font-size: 1.15rem;
  }

  .muncher-status {
    padding: 7px 8px;
    font-size: 0.9rem;
  }
}
