:root {
  color-scheme: light;
  --paper: #edf3e6;
  --ink: #1f241d;
  --muted: #5b6554;
  --line: #c2ccb8;
  --fragile-glass: #d4f0eb;
  --goal: #6fa33f;
  --goal-deep: #3f6825;
  --block-skin: #8b592c;
  --block-flesh: #85c84b;
  --control: #24301f;
  --control-text: #fffaf2;
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  border: 0;
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: 100vw;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 86px;
  padding: 18px clamp(18px, 4vw, 44px);
  border-bottom: 1px solid var(--line);
  background: rgba(237, 243, 230, 0.94);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.mark {
  width: 38px;
  height: 38px;
  border-radius: 40% 55% 48% 52%;
  background:
    radial-gradient(circle at 50% 50%, var(--block-flesh) 0 38%, transparent 39%),
    radial-gradient(circle at 42% 45%, #1d2419 0 4%, transparent 5%),
    radial-gradient(circle at 58% 55%, #1d2419 0 4%, transparent 5%),
    var(--block-skin);
  box-shadow: 0 4px 0 #24301f;
}

h1,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.45rem, 2.4vw, 2.1rem);
  line-height: 1;
  letter-spacing: 0;
}

.brand p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.95rem;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  color: var(--muted);
  font-size: 0.95rem;
}

.stats span {
  min-width: 78px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  text-align: center;
  white-space: nowrap;
}

.stats strong {
  color: var(--ink);
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  min-height: 0;
}

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  background:
    linear-gradient(90deg, rgba(31, 36, 29, 0.05) 1px, transparent 1px),
    linear-gradient(0deg, rgba(31, 36, 29, 0.05) 1px, transparent 1px),
    #dfe8d5;
  background-size: 32px 32px;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.panel {
  display: grid;
  grid-template-rows: auto 160px auto;
  align-content: start;
  gap: 18px;
  padding: 24px;
  border-left: 1px solid var(--line);
  background: #ffffff;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.level-grid button {
  height: 38px;
  border: 1px solid var(--line);
  background: #f4f7ef;
  color: var(--ink);
  font-weight: 700;
}

.level-grid button[aria-current="true"] {
  border-color: var(--goal);
  background: var(--goal);
  color: white;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(3, 46px);
  justify-content: center;
  align-content: center;
  gap: 8px;
}

.dir,
.actions button {
  background: var(--control);
  color: var(--control-text);
  font-weight: 800;
  box-shadow: 0 3px 0 #000;
}

.dir {
  font-size: 1.25rem;
}

.dir:active,
.actions button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #000;
}

.north {
  grid-column: 2;
  grid-row: 1;
}

.west {
  grid-column: 1;
  grid-row: 2;
}

.east {
  grid-column: 3;
  grid-row: 2;
}

.south {
  grid-column: 2;
  grid-row: 3;
}

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

.actions button {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 52px;
  line-height: 1.1;
  white-space: nowrap;
}

.action-label {
  font-size: 0.95rem;
}

.action-hint {
  color: rgba(255, 250, 242, 0.78);
  font-size: 0.72rem;
  font-weight: 700;
}

#nextBtn.next-peck-target {
  outline: 2px solid rgba(134, 201, 79, 0.68);
  outline-offset: 3px;
}

#nextBtn.is-pecked {
  animation: next-peck-pulse 360ms ease-in-out 5;
}

.kiwi-runner {
  --bird-start-x: 0px;
  --bird-start-y: 0px;
  --bird-end-x: 0px;
  --bird-end-y: 0px;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 30;
  width: 220px;
  height: 156px;
  pointer-events: none;
  opacity: 0;
  overflow: visible;
  transform: translate(var(--bird-start-x), var(--bird-start-y)) scale(0.68);
  transform-origin: 40% 84%;
}

.kiwi-runner.is-active {
  animation: kiwi-runner-path 3600ms cubic-bezier(0.2, 0.82, 0.2, 1) forwards;
}

.kiwi-runner__image {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 2px 0 rgba(31, 36, 29, 0.18));
}

.kiwi-runner.is-active .kiwi-runner__image {
  animation:
    kiwi-walk-bob 360ms ease-in-out 0ms 7,
    kiwi-peck 360ms ease-in-out 2520ms 5;
  transform-origin: 54% 72%;
}

.actions button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
  box-shadow: 0 3px 0 #000;
}

@keyframes kiwi-runner-path {
  0% {
    opacity: 0;
    transform: translate(var(--bird-start-x), var(--bird-start-y)) scale(0.68);
  }
  8% {
    opacity: 1;
  }
  70% {
    opacity: 1;
    transform: translate(var(--bird-end-x), var(--bird-end-y)) scale(0.84);
  }
  100% {
    opacity: 1;
    transform: translate(var(--bird-end-x), var(--bird-end-y)) scale(0.84);
  }
}

@keyframes kiwi-walk-bob {
  0%,
  100% {
    transform: translateY(0) rotate(-1deg);
  }
  50% {
    transform: translateY(-6px) rotate(2deg);
  }
}

@keyframes kiwi-peck {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }
  45% {
    transform: translate(12px, -4px) rotate(-1deg);
  }
}

@keyframes next-peck-pulse {
  0%,
  100% {
    transform: translateY(0);
  }
  45% {
    transform: translateY(2px);
  }
}

@media (max-width: 760px) {
  body {
    overflow: auto;
  }

  .app-shell {
    min-height: 100vh;
    height: auto;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats {
    gap: 6px;
    justify-content: flex-start;
    font-size: 0.85rem;
  }

  .stats span {
    min-width: 0;
    padding: 7px 8px;
  }

  .play-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(420px, 60vh) auto;
    width: 100%;
    max-width: 100vw;
    min-width: 0;
  }

  .panel {
    grid-template-columns: minmax(0, 1fr);
    min-width: 0;
    width: 100%;
    max-width: 100%;
    padding: clamp(14px, 4vw, 20px);
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .level-grid,
  .dpad,
  .actions {
    min-width: 0;
    max-width: 100%;
  }

  .actions {
    gap: 8px;
  }

  .actions button,
  .level-grid button {
    min-width: 0;
  }

  .actions button {
    padding-inline: 6px;
  }

  .action-hint {
    font-size: 0.68rem;
  }
}
