:root {
  --pink: #ffcadf;
  --peach: #ffd7b5;
  --mint: #c7f5db;
  --sky: #b9dcff;
  --berry: #ff5f7d;
  --ink: #2d3856;
  --cloud: #fff8fc;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: "Fredoka", "Baloo 2", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 15% 15%, #fff9d4 0, transparent 30%),
    radial-gradient(circle at 80% 10%, #d4f3ff 0, transparent 28%),
    linear-gradient(145deg, #ffe8f2 0%, #dff4ff 45%, #e9ffec 100%);
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.sky-decor {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -2;
}

.sky-decor::before,
.sky-decor::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  filter: blur(1px);
  animation: drift 16s linear infinite;
}

.sky-decor::before {
  width: 210px;
  height: 70px;
  top: 12%;
  left: -18%;
}

.sky-decor::after {
  width: 170px;
  height: 58px;
  top: 24%;
  right: -18%;
  animation-delay: -6s;
}

.float-shapes {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
}

.float-shapes span {
  position: absolute;
  display: block;
  border-radius: 999px;
  opacity: 0.32;
  animation: float-up 10s ease-in-out infinite;
}

.float-shapes span:nth-child(1) {
  width: 54px;
  height: 54px;
  left: 10%;
  bottom: -8%;
  background: #ffb7c8;
}

.float-shapes span:nth-child(2) {
  width: 36px;
  height: 36px;
  left: 27%;
  bottom: -14%;
  background: #b8f2ff;
  animation-delay: -2s;
}

.float-shapes span:nth-child(3) {
  width: 72px;
  height: 72px;
  left: 47%;
  bottom: -10%;
  background: #ffe29e;
  animation-delay: -4s;
}

.float-shapes span:nth-child(4) {
  width: 40px;
  height: 40px;
  left: 62%;
  bottom: -16%;
  background: #ffd5a6;
  animation-delay: -6s;
}

.float-shapes span:nth-child(5) {
  width: 64px;
  height: 64px;
  left: 76%;
  bottom: -12%;
  background: #d5ffd8;
  animation-delay: -1s;
}

.float-shapes span:nth-child(6) {
  width: 30px;
  height: 30px;
  left: 90%;
  bottom: -9%;
  background: #f8d0ff;
  animation-delay: -3.2s;
}

.app-shell {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  padding: clamp(12px, 2.8vw, 24px);
}

.scene {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: clamp(14px, 3vw, 32px);
  overflow: hidden;
}

.scene.is-active {
  display: flex;
  animation: fade-in 260ms ease;
}

.scene-panel {
  width: min(980px, 96vw);
  padding: clamp(14px, 2.6vw, 24px);
  max-height: calc(100dvh - clamp(28px, 6vw, 64px));
}

h1,
h2 {
  margin: 0;
  text-align: center;
  font-family: "Baloo 2", "Fredoka", sans-serif;
  letter-spacing: 0.04em;
  color: #1f2f53;
}

h1 {
  font-size: clamp(2rem, 6vw, 3.3rem);
}

h2 {
  font-size: clamp(1.7rem, 5vw, 2.4rem);
}

.start-panel {
  position: relative;
  overflow: hidden;
}

.start-panel::after {
  content: "";
  position: absolute;
  width: 180px;
  height: 180px;
  right: -40px;
  bottom: -40px;
  border-radius: 26px;
  background: linear-gradient(130deg, rgba(255, 120, 172, 0.2), rgba(166, 239, 255, 0.2));
  transform: rotate(20deg);
}

.choice-grid {
  margin-top: 24px;
  display: grid;
  gap: clamp(12px, 3vw, 24px);
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

.choice-button {
  position: relative;
  border: 3px solid #ffffff;
  border-radius: 22px;
  background: linear-gradient(150deg, #ffe6f0, #d8fff1);
  padding: 14px;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease;
  box-shadow: 0 10px 18px rgba(46, 52, 86, 0.12);
  touch-action: manipulation;
}

.choice-button:hover,
.choice-button:focus-visible {
  transform: translateY(-2px) scale(1.01);
  box-shadow: 0 16px 25px rgba(46, 52, 86, 0.15);
}

.choice-button img {
  width: min(220px, 100%);
  height: 170px;
  object-fit: contain;
}

.choice-button span {
  display: block;
  margin-top: 10px;
  font-size: 1.25rem;
  font-weight: 700;
}

.upload-panel {
  max-width: 640px;
  background: rgba(255, 255, 255, 0.26);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 24px;
  backdrop-filter: blur(2px);
}

#character-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.file-pick {
  display: inline-flex;
  justify-content: center;
  margin: 18px auto 0;
  width: 100%;
  padding: 12px 16px;
  border-radius: 999px;
  border: 2px dashed #f88aa7;
  background: #fff4fa;
  font-weight: 700;
  cursor: pointer;
}

.preview-shell {
  margin: 16px auto 0;
  width: min(310px, 80vw);
  aspect-ratio: 1 / 1;
  border-radius: 26px;
  background: linear-gradient(145deg, #fff, #f8feff);
  border: 2px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 0 1px rgba(140, 159, 216, 0.12);
}

.preview-shell img {
  width: 90%;
  height: 90%;
  object-fit: contain;
}

.upload-error {
  min-height: 1.3em;
  color: #d2395e;
  text-align: center;
  margin-top: 10px;
  font-weight: 600;
}

.upload-actions {
  display: grid;
  gap: 10px;
  margin-top: 8px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.action-btn {
  border: none;
  border-radius: 999px;
  padding: 12px 18px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  background: linear-gradient(120deg, #ff89a6, #ffb45d);
  color: #fff;
}

.action-btn[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}

.ghost-btn {
  background: #edf7ff;
  color: #335289;
}

#main-scene {
  align-items: stretch;
}

.home-btn {
  position: absolute;
  top: clamp(12px, 2.8vw, 24px);
  right: clamp(12px, 2.8vw, 24px);
  z-index: 3;
  border: 3px solid #fff;
  border-radius: 999px;
  background: linear-gradient(130deg, #fff9cd, #ffd9ae);
  box-shadow: 0 10px 20px rgba(57, 56, 105, 0.16);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-family: "Baloo 2", sans-serif;
  font-size: 1.1rem;
  cursor: pointer;
  touch-action: manipulation;
}

.home-btn img {
  width: 24px;
  height: 24px;
}

.playfield {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
  touch-action: manipulation;
}

.counter {
  position: absolute;
  top: clamp(58px, 10vh, 90px);
  font-family: "Baloo 2", sans-serif;
  font-size: clamp(1.6rem, 5vw, 2.9rem);
  font-weight: 800;
  color: #ff4e78;
  text-shadow: 2px 3px 0 #fff;
  background: rgba(255, 255, 255, 0.75);
  border-radius: 999px;
  padding: 6px 18px;
}

.counter.bump {
  animation: count-pop 180ms ease;
}

.character-wrap {
  position: relative;
  width: min(430px, 80vw);
  max-width: min(430px, calc(100dvh - 150px));
  aspect-ratio: 1/1;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translateY(14px);
}

.character-image {
  width: 92%;
  height: 92%;
  object-fit: contain;
  filter: drop-shadow(0 16px 24px rgba(46, 45, 70, 0.24));
  transition: transform 120ms ease;
}

.stick-image {
  position: absolute;
  right: -15%;
  top: 12%;
  width: clamp(100px, 26vw, 168px);
  transform-origin: 12% 88%;
  transform: rotate(20deg);
  filter: drop-shadow(0 9px 10px rgba(45, 37, 49, 0.24));
}

.bonk-impact {
  position: absolute;
  top: -4%;
  width: clamp(100px, 26vw, 180px);
  opacity: 0;
  transform: translateY(20px) scale(0.6);
  pointer-events: none;
}

.character-wrap.bonk-active .character-image {
  animation: hit-react 340ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.character-wrap.bonk-active .stick-image {
  animation: stick-swing 300ms ease-out;
}

.bonk-impact.show {
  animation: bonk-pop 300ms ease-out;
}

.playfield.audio-fallback {
  animation: screen-shake 180ms linear;
}

@keyframes hit-react {
  0% {
    transform: scale(1) rotate(0deg);
  }
  30% {
    transform: scale(0.92) rotate(-8deg);
  }
  70% {
    transform: scale(1.04) rotate(6deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
  }
}

@keyframes stick-swing {
  0% {
    transform: rotate(22deg);
  }
  40% {
    transform: rotate(-42deg);
  }
  100% {
    transform: rotate(20deg);
  }
}

@keyframes bonk-pop {
  0% {
    opacity: 0;
    transform: translateY(20px) scale(0.6);
  }
  40% {
    opacity: 1;
    transform: translateY(-8px) scale(1.1);
  }
  100% {
    opacity: 0;
    transform: translateY(-24px) scale(1);
  }
}

@keyframes count-pop {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.11);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes screen-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-3px);
  }
  75% {
    transform: translateX(3px);
  }
}

@keyframes drift {
  0% {
    transform: translateX(0) translateY(0);
  }
  100% {
    transform: translateX(140vw) translateY(6px);
  }
}

@keyframes float-up {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 0;
  }
  15% {
    opacity: 0.36;
  }
  85% {
    opacity: 0.3;
  }
  100% {
    transform: translateY(-120vh) rotate(230deg);
    opacity: 0;
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 8px;
  }

  .scene {
    padding: 8px;
  }

  .scene-panel {
    border-radius: 18px;
    padding: 10px;
  }

  h1 {
    font-size: clamp(1.5rem, 8.5vw, 2.1rem);
  }

  h2 {
    font-size: clamp(1.2rem, 6.2vw, 1.6rem);
  }

  .choice-grid {
    margin-top: 10px;
    gap: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .choice-button {
    padding: 8px;
    border-radius: 14px;
  }

  .choice-button img {
    height: clamp(74px, 23vw, 112px);
  }

  .choice-button span {
    margin-top: 4px;
    font-size: 0.95rem;
  }

  .upload-panel {
    max-width: 100%;
  }

  .file-pick {
    margin-top: 10px;
    padding: 9px 12px;
  }

  .preview-shell {
    margin-top: 10px;
    width: min(180px, 45vw);
    border-radius: 16px;
  }

  .upload-error {
    margin-top: 6px;
    font-size: 0.85rem;
    min-height: 1.1em;
  }

  .upload-actions {
    gap: 8px;
    margin-top: 4px;
    grid-template-columns: 1fr 1fr;
  }

  .action-btn {
    padding: 10px 10px;
    font-size: 0.9rem;
  }

  .home-btn {
    top: 10px;
    right: 10px;
    padding: 6px 10px;
    border-width: 2px;
  }

  .home-btn img {
    width: 20px;
    height: 20px;
  }

  .counter {
    top: 50px;
    font-size: clamp(1.1rem, 6.5vw, 1.7rem);
    padding: 4px 12px;
  }

  .character-wrap {
    width: min(84vw, calc(100dvh - 130px));
    max-width: min(84vw, calc(100dvh - 130px));
    transform: translateY(10px);
  }

  .stick-image {
    right: -14%;
    top: 15%;
    width: clamp(84px, 24vw, 120px);
  }

  .bonk-impact {
    top: -2%;
    width: clamp(86px, 24vw, 130px);
  }
}
