@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@600;700;800&family=Nunito:wght@700;800;900&display=swap');

:root {
  --cream: #fff9dd;
  --ink: #173326;
  --green: #2f8d45;
  --light-green: #a5d94f;
  --yellow: #ffd84d;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #bde8df;
  color: var(--ink);
  font-family: "Nunito", system-ui, sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

button { font: inherit; }

#game { position: relative; width: 100%; height: 100%; isolation: isolate; }

#scene { display: block; width: 100%; height: 100%; cursor: crosshair; }

.hud {
  position: fixed;
  z-index: 5;
  top: max(14px, env(safe-area-inset-top));
  left: max(76px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  pointer-events: none;
}

.brand, .stat {
  background: rgba(255, 255, 239, .9);
  border: 3px solid rgba(255, 255, 255, .75);
  box-shadow: 0 7px 0 rgba(22, 67, 42, .22), 0 10px 24px rgba(14, 49, 31, .13);
  backdrop-filter: blur(9px);
}

.brand {
  justify-self: start;
  padding: 9px 16px 8px;
  border-radius: 18px;
  font-family: "Baloo 2", sans-serif;
  font-size: clamp(17px, 3vw, 25px);
  font-weight: 800;
  letter-spacing: .07em;
}

.panda-dot {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  margin-right: 7px;
  border-radius: 50%;
  color: #15291f;
  background: #fff;
  box-shadow: -7px -5px 0 -3px #15291f, 7px -5px 0 -3px #15291f;
}

.stat {
  min-width: 102px;
  padding: 7px 14px 5px;
  border-radius: 17px;
  text-align: center;
  line-height: 1;
}

.stat-label { display: block; margin-bottom: 3px; font-size: 10px; letter-spacing: .14em; color: #5c725f; }
.stat strong { font-family: "Baloo 2", sans-serif; font-size: 25px; color: #236b37; }
.stat .target { font-size: 13px; color: #69806d; }
.time-box.danger { animation: pulse .65s infinite alternate; background: #fff1dc; }
.time-box.danger strong { color: #e65034; }

.overlay {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background: radial-gradient(circle at 50% 35%, rgba(248,255,201,.4), rgba(11,59,35,.65));
  opacity: 0;
  visibility: hidden;
  transition: opacity .35s, visibility .35s;
}

.overlay.visible { opacity: 1; visibility: visible; }

.card {
  width: min(440px, 100%);
  max-height: 94vh;
  overflow: visible;
  padding: 30px 32px 28px;
  border: 5px solid rgba(255,255,255,.88);
  border-radius: 35px;
  background: linear-gradient(160deg, rgba(255,253,225,.98), rgba(239,255,211,.96));
  box-shadow: 0 18px 0 rgba(20,64,37,.27), 0 30px 70px rgba(8,38,25,.3);
  text-align: center;
  transform: translateY(20px) scale(.95);
  transition: transform .4s cubic-bezier(.2,.9,.25,1.3);
}

.visible .card { transform: translateY(0) scale(1); }
.eyebrow { margin: 5px 0 0; font-size: 12px; letter-spacing: .19em; color: #548558; }
h1, h2 { margin: -6px 0 3px; font-family: "Baloo 2", sans-serif; line-height: 1; color: #245c34; }
h1 { font-size: clamp(58px, 15vw, 82px); letter-spacing: .04em; text-shadow: 0 5px 0 #b9db69; }
h2 { font-size: 54px; }
.story { margin: 9px auto 17px; max-width: 330px; font-size: 17px; line-height: 1.35; color: #45634c; }

.mini-panda { position: relative; width: 90px; height: 70px; margin: -69px auto 5px; }
.mini-panda .face {
  position: absolute; inset: 9px 4px 0; z-index: 2; display: grid; place-items: center;
  border: 4px solid #21372a; border-radius: 49% 49% 45% 45%; background: #fffdf0;
  color: #203328; font-style: normal; font-size: 27px; letter-spacing: 4px;
}
.mini-panda .ear { position: absolute; top: 3px; width: 28px; height: 28px; border-radius: 50%; background: #21372a; }
.mini-panda .ear.left { left: 4px; } .mini-panda .ear.right { right: 4px; }

.how-to {
  display: flex; align-items: center; gap: 14px; padding: 11px 15px; border-radius: 20px;
  background: #e2f3af; text-align: left; color: #345440;
}
.how-to p { margin: 0; font-size: 14px; line-height: 1.3; }
.how-icon { flex: 0 0 auto; font-size: 34px; filter: drop-shadow(0 3px 0 #fff); }
.goal { margin: 15px 0 13px; font-size: 14px; color: #5f755f; }

.main-button {
  width: 100%; min-height: 61px; padding: 12px 24px; border: 0; border-radius: 19px;
  background: linear-gradient(#55b64f, #2e8a42); color: white;
  box-shadow: 0 7px 0 #1d6432, 0 11px 20px rgba(33,91,47,.25);
  font-family: "Baloo 2", sans-serif; font-size: 27px; font-weight: 800; letter-spacing: .04em;
  cursor: pointer; transition: transform .12s, box-shadow .12s;
}
.main-button:hover { filter: brightness(1.08); transform: translateY(-2px); }
.main-button:active { transform: translateY(5px); box-shadow: 0 2px 0 #1d6432; }
.main-button span { margin-left: 8px; color: var(--yellow); }

.hint {
  position: fixed; z-index: 7; left: 50%; bottom: max(22px, env(safe-area-inset-bottom));
  translate: -50% 0; padding: 9px 16px; border-radius: 18px;
  color: #23452f; background: rgba(255,252,219,.91); box-shadow: 0 5px 0 rgba(26,72,42,.2);
  font-size: 14px; pointer-events: none; opacity: 0; transition: opacity .3s;
}
.hint.show { opacity: 1; animation: float 1.2s ease-in-out infinite alternate; }
.tap-icon { font-size: 21px; }

.game-controls {
  position: fixed;
  z-index: 8;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .25s;
}

.game-controls.active { opacity: 1; }

.joystick {
  position: absolute;
  left: max(22px, env(safe-area-inset-left));
  bottom: max(24px, env(safe-area-inset-bottom));
  width: 142px;
  height: 142px;
  border: 4px solid rgba(255,255,255,.55);
  border-radius: 50%;
  background: rgba(25,72,43,.38);
  box-shadow: inset 0 0 28px rgba(9,42,24,.2), 0 8px 24px rgba(10,42,27,.2);
  backdrop-filter: blur(5px);
  pointer-events: auto;
  touch-action: none;
}

.joystick::after {
  content: '';
  position: absolute;
  inset: 29px;
  border: 2px solid rgba(255,255,255,.16);
  border-radius: 50%;
}

.joystick-knob {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 50%;
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  translate: -50% -50%;
  border: 4px solid rgba(255,255,255,.75);
  border-radius: 50%;
  background: linear-gradient(145deg, #75c75e, #2f8d45);
  box-shadow: 0 6px 0 #236c36, 0 9px 18px rgba(0,0,0,.22);
  color: white;
  font-size: 25px;
  will-change: transform;
}

.joy-arrow { position: absolute; color: rgba(255,255,255,.6); font-size: 12px; line-height: 1; }
.joy-arrow.up { top: 8px; left: 50%; translate: -50% 0; }
.joy-arrow.right { right: 8px; top: 50%; translate: 0 -50%; }
.joy-arrow.down { bottom: 8px; left: 50%; translate: -50% 0; }
.joy-arrow.left { left: 8px; top: 50%; translate: 0 -50%; }

.chop-button {
  position: absolute;
  right: max(25px, env(safe-area-inset-right));
  bottom: max(35px, env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
  width: 112px;
  height: 112px;
  border: 5px solid rgba(255,255,255,.75);
  border-radius: 50%;
  background: linear-gradient(#ffd85b, #f5a936);
  box-shadow: 0 8px 0 #bd7027, 0 13px 25px rgba(70,42,11,.25);
  color: #603914;
  cursor: pointer;
  pointer-events: auto;
  touch-action: none;
}

.chop-button span { font-size: 39px; line-height: .9; }
.chop-button b { font-size: 13px; letter-spacing: .04em; }
.chop-button.ready { animation: ready-pulse .65s ease-in-out infinite alternate; background: linear-gradient(#fff07a, #ffb62f); }
.chop-button:active { translate: 0 6px; box-shadow: 0 2px 0 #bd7027; }

.message, .combo { position: fixed; z-index: 9; pointer-events: none; font-family: "Baloo 2", sans-serif; font-weight: 800; opacity: 0; }
.message { color: white; font-size: 28px; text-shadow: 0 3px 0 #24743b, 0 5px 8px rgba(0,0,0,.2); transform: translate(-50%,-50%); }
.message.pop { animation: score-pop .75s ease-out; }
.combo { top: 108px; left: 50%; color: #fff2a1; font-size: clamp(26px, 6vw, 42px); text-shadow: 0 4px 0 #d47a20; transform: translateX(-50%) rotate(-3deg); }
.combo.pop { animation: combo-pop .65s ease-out; }

.final-score { margin: 10px auto 22px; padding: 15px; border-radius: 22px; background: #ddefa7; }
.final-score span { display: block; font-size: 11px; letter-spacing: .15em; color: #5b775c; }
.final-score strong { display: block; font-family: "Baloo 2"; font-size: 55px; line-height: 1; color: #27703d; }
.end-emoji { font-size: 64px; margin-bottom: 2px; animation: float .8s ease-in-out infinite alternate; }

.loading { position: fixed; z-index: 30; inset: 0; display: grid; place-content: center; gap: 10px; text-align: center; background: #c8ece2; transition: opacity .5s, visibility .5s; }
.loading.hidden { opacity: 0; visibility: hidden; }
.loading span { width: 54px; height: 54px; margin: auto; border: 7px solid #eef5bd; border-top-color: #378c4a; border-radius: 50%; animation: spin .8s linear infinite; }
.loading p { color: #326447; }
.error { position: fixed; z-index: 40; inset: 0; display: grid; place-content: center; gap: 8px; padding: 30px; background: #fff2cc; text-align: center; }
.error[hidden] { display: none; }

@keyframes spin { to { rotate: 360deg; } }
@keyframes pulse { to { transform: scale(1.07); } }
@keyframes float { to { transform: translateY(-7px); } }
@keyframes score-pop { 0% { opacity: 0; transform: translate(-50%,-10%) scale(.5); } 25% { opacity: 1; transform: translate(-50%,-50%) scale(1.25) rotate(-4deg); } 100% { opacity: 0; transform: translate(-50%,-130%) scale(.9); } }
@keyframes combo-pop { 0% { opacity: 0; transform: translateX(-50%) scale(.5); } 25%,65% { opacity: 1; transform: translateX(-50%) scale(1.1) rotate(-3deg); } 100% { opacity: 0; transform: translateX(-50%) translateY(-25px); } }
@keyframes ready-pulse { to { scale: 1.08; filter: brightness(1.08); } }

@media (max-width: 600px) {
  .hud { grid-template-columns: 1fr auto; }
  .brand { grid-row: 1; }
  .score-box { grid-row: 2; justify-self: start; }
  .time-box { grid-column: 2; grid-row: 1 / span 2; }
  .stat { min-width: 86px; padding-inline: 9px; }
  .card { padding: 25px 20px 22px; border-radius: 28px; }
  .mini-panda { margin-top: -61px; transform: scale(.86); }
  .story { font-size: 15px; }
  .combo { top: 125px; }
  .joystick { width: 126px; height: 126px; left: max(14px, env(safe-area-inset-left)); bottom: max(17px, env(safe-area-inset-bottom)); }
  .joystick-knob { width: 58px; height: 58px; }
  .chop-button { width: 96px; height: 96px; right: max(17px, env(safe-area-inset-right)); bottom: max(25px, env(safe-area-inset-bottom)); }
  .chop-button span { font-size: 32px; }
  .hint { bottom: max(153px, calc(env(safe-area-inset-bottom) + 143px)); white-space: nowrap; }
}

@media (max-height: 650px) {
  .card { transform: scale(.86); max-height: 110vh; overflow: auto; }
  .visible .card { transform: scale(.86); }
  .mini-panda { display: none; }
  h1 { font-size: 54px; }
  .story { margin-block: 5px 9px; }
  .goal { margin-block: 8px; }
  .main-button { min-height: 52px; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; } }
