:root {
  --ink: #26120f;
  --bg-1: #9fd8ff;
  --bg-2: #f6ffbf;
  --panel: #fff9efde;
  --accent: #ff6e5f;
  --blue: #2a76be;
  --pink: #b11f63;
  --splash-grass-dark: #2f5c3f;
  --splash-grass-mid: #4f8d4f;
  --splash-path-gold: #d4ac5a;
  --splash-bark: #6c4528;
  --splash-berry: #8a2f48;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Nunito", sans-serif;
  background:
    radial-gradient(circle at 15% 10%, #ffffff8a 0, #ffffff00 30%),
    radial-gradient(circle at 80% 12%, #ffe8aa80 0, #ffffff00 28%),
    linear-gradient(165deg, var(--bg-1), #9ce2dc 55%, var(--bg-2));
}

.app-shell {
  width: min(700px, 100vw);
  margin: 0 auto;
  min-height: 100vh;
  padding: max(10px, env(safe-area-inset-top)) 10px max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.topbar {
  background:
    linear-gradient(160deg, #fff7e8f2, #f6ecd7ed),
    repeating-linear-gradient(130deg, #fff5e3cc, #fff5e3cc 12px, #fceacecc 12px, #fceacecc 24px);
  border-radius: 20px;
  padding: 13px 14px;
  border: 2px solid #fffef4;
  outline: 2px solid #eecf93;
  outline-offset: -6px;
  box-shadow: 0 10px 25px #2c56722f, inset 0 -8px 15px #b9863b1a;
}

.topbar h1 {
  margin: 0;
  font-family: "Bungee", cursive;
  font-size: clamp(1.15rem, 5.7vw, 1.9rem);
  line-height: 1.05;
  letter-spacing: 0.4px;
}

.topbar p {
  margin: 4px 0 8px;
  font-weight: 800;
  font-size: clamp(0.85rem, 3.7vw, 1rem);
}

.meta-row {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 5px;
  font-weight: 900;
  font-size: clamp(0.82rem, 3.5vw, 0.98rem);
}

.game-wrap {
  position: relative;
  border-radius: 24px;
  overflow: hidden;
  border: 2px solid #fffdf0;
  outline: 3px solid #4b7b59;
  outline-offset: -10px;
  box-shadow: 0 14px 28px #2a576d40, inset 0 0 0 10px #143e4f;
  background: #89d5ff;
}

#game {
  width: 100%;
  height: auto;
  display: block;
  touch-action: none;
}

.touch-controls {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: max(2px, env(safe-area-inset-bottom));
  transform: translateY(-10vh);
}

.pad-left,
.pad-right {
  display: flex;
  gap: 8px;
}

.control {
  border: 0;
  min-width: 74px;
  min-height: 58px;
  padding: 8px 12px;
  border-radius: 15px;
  font-size: 1rem;
  font-weight: 900;
  color: #fff;
  touch-action: manipulation;
  user-select: none;
  box-shadow: 0 8px 15px #20355444, inset 0 -3px 0 #0000002b;
  letter-spacing: 0.2px;
}

.control.move {
  background: linear-gradient(150deg, var(--splash-grass-mid), var(--splash-grass-dark));
}

.control.jump {
  color: #2a1a10;
  background: linear-gradient(150deg, #efc678, var(--splash-path-gold));
}

.control.sprint {
  background: linear-gradient(150deg, #a44f3b, var(--splash-bark));
}

.control:active,
.control.active {
  transform: translateY(1px) scale(0.98);
  filter: brightness(1.08);
}

.card-wrap {
  position: absolute;
  inset: 0;
  border-radius: 18px;
  background:
    radial-gradient(circle at 50% 35%, #3f6c6b33 0, #233a4173 48%, #142830cc 100%),
    linear-gradient(180deg, #20383f9e, #172f379e);
  backdrop-filter: blur(1.5px);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  padding: 16px;
  animation: fadein 500ms ease;
  overflow: hidden;
}

@keyframes fadein {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.paper-scene {
  width: min(560px, 94vw);
  aspect-ratio: 1 / 1.12;
  position: relative;
  transform-style: preserve-3d;
  perspective: 1200px;
  overflow: visible;
}

.paper-card {
  position: absolute;
  inset: 6% 5% 7%;
  transform-style: preserve-3d;
}

.sheet,
.cover {
  position: absolute;
  inset: 0;
  border-radius: 18px;
}

.sheet {
  background:
    radial-gradient(circle at 16% 10%, #fffdf6 0, #fff7e5 32%, #ffeacc 80%),
    repeating-linear-gradient(38deg, #fff9ee, #fff9ee 14px, #ffefd8 14px, #ffefd8 28px);
  border: 3px solid #ffefcf;
  outline: 2px dashed #ffa17e;
  outline-offset: -10px;
  padding: clamp(0.8rem, 3.2vw, 1.12rem);
  box-shadow:
    0 24px 40px #00000056,
    inset 0 -18px 24px #d9755a29,
    inset 0 9px 15px #ffffffa6;
  opacity: 0;
  transform: translateZ(4px) scale(0.96);
  animation: none;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.sheet::before {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 14px;
  pointer-events: none;
  background:
    radial-gradient(circle at 8% 8%, #ffffff70 0, #ffffff00 40%),
    radial-gradient(circle at 90% 90%, #ffc6802e 0, #ffffff00 45%);
  mix-blend-mode: soft-light;
}

.sheet h2 {
  margin: 0;
  font-family: "Bungee", cursive;
  color: #bb2d2d;
  font-size: clamp(1rem, 5.1vw, 1.38rem);
  line-height: 1.05;
  letter-spacing: 0.2px;
  text-wrap: balance;
}

.sheet p {
  margin: 0.56rem 0 0;
  font-weight: 800;
  font-size: clamp(0.9rem, 3.5vw, 1rem);
  line-height: 1.32;
}

.sheet h3 {
  margin: 0.66rem 0 0;
  font-family: "Bungee", cursive;
  color: #8c1f43;
  font-size: clamp(1rem, 4.6vw, 1.34rem);
  text-transform: uppercase;
  line-height: 1.08;
  letter-spacing: 0.2px;
  text-wrap: balance;
}

.sheet .tiny {
  margin-top: 0.58rem;
  font-size: clamp(0.79rem, 3.1vw, 0.92rem);
  line-height: 1.24;
}

.sheet .mariposita-word {
  position: relative;
  display: inline-block;
}

.sheet .card-gif {
  width: min(46%, 170px);
  height: auto;
  object-fit: contain;
  align-self: center;
  margin-top: auto;
  margin-bottom: 2px;
  border-radius: 10px;
  border: 1px solid #ffffffa8;
  box-shadow: 0 8px 14px #6b3a2b2b;
}

.cover {
  background:
    linear-gradient(150deg, #ffb09f, #f17679 52%, #cf4a62),
    repeating-linear-gradient(34deg, #ffc6b1, #ffc6b1 12px, #ef8f82 12px, #ef8f82 24px);
  box-shadow:
    inset 0 0 0 2px #ffdcd0cc,
    inset 0 -18px 24px #a9365340,
    0 14px 25px #0000003f;
}

.cover::before,
.cover::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.cover::before {
  inset: 10px 12px;
  border-radius: 14px;
  border: 1px dashed #ffd8c8b5;
  box-shadow: inset 0 0 0 1px #ffffff2e;
}

.cover::after {
  inset: 0;
  border-radius: inherit;
  background:
    radial-gradient(circle at 20% 18%, #ffffff48 0, #ffffff00 42%),
    radial-gradient(circle at 78% 82%, #7f2a442b 0, #00000000 45%);
  mix-blend-mode: soft-light;
}

.cover.left {
  clip-path: polygon(0 0, 100% 0, 80% 100%, 0 100%);
  transform-origin: left center;
  filter: saturate(1.03) brightness(1.03);
  animation: none;
}

.cover.right {
  clip-path: polygon(0 0, 100% 0, 100% 100%, 20% 100%);
  transform-origin: right center;
  filter: saturate(0.96) brightness(0.98);
  animation: none;
}

.bat {
  display: none;
  position: absolute;
  left: 50%;
  top: 58%;
  width: 18px;
  height: 12px;
  margin-left: -9px;
  opacity: 0;
}

.bat::before,
.bat::after {
  content: "";
  position: absolute;
  top: 0;
  width: 9px;
  height: 12px;
  background: #241018;
  border-radius: 12px 12px 2px 2px;
}

.bat::before {
  left: 0;
  transform-origin: right center;
}

.bat::after {
  right: 0;
  transform-origin: left center;
}

.bat-1::before,
.bat-1::after,
.bat-2::before,
.bat-2::after,
.bat-3::before,
.bat-3::after,
.bat-4::before,
.bat-4::after,
.bat-5::before,
.bat-5::after {
  animation: none;
}

.butterfly {
  position: absolute;
  width: 30px;
  height: 24px;
  opacity: 0;
  transform: translateY(8px) scale(0.75);
  animation: none;
}

.word-butterfly {
  left: auto;
  right: -0.08em;
  top: -0.95em;
}

.butterfly::before,
.butterfly::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 22px;
  background: linear-gradient(170deg, #ffc35f, #ff6f8e);
  border-radius: 14px 14px 10px 14px;
  top: 0;
}

.butterfly::before {
  left: 0;
  transform-origin: right center;
  animation: none;
}

.butterfly::after {
  right: 0;
  transform-origin: left center;
  transform: scaleX(-1);
  animation: none;
}

.card-wrap.revealed .sheet {
  animation: sheet-reveal 780ms ease 550ms forwards;
}

.card-wrap.revealed .cover.left {
  animation: fold-left 900ms cubic-bezier(0.6, 0.04, 0.32, 1) 150ms forwards;
}

.card-wrap.revealed .cover.right {
  animation: fold-right 900ms cubic-bezier(0.6, 0.04, 0.32, 1) 150ms forwards;
}

.card-wrap.revealed .bat-1 {
  animation: bat-flight-1 1.3s ease-out 760ms forwards;
}

.card-wrap.revealed .bat-2 {
  animation: bat-flight-2 1.2s ease-out 880ms forwards;
}

.card-wrap.revealed .bat-3 {
  animation: bat-flight-3 1.35s ease-out 940ms forwards;
}

.card-wrap.revealed .bat-4 {
  animation: bat-flight-4 1.22s ease-out 1.02s forwards;
}

.card-wrap.revealed .bat-5 {
  animation: bat-flight-5 1.3s ease-out 1.1s forwards;
}

.card-wrap.revealed .bat::before,
.card-wrap.revealed .bat::after {
  animation: wing-flap 180ms ease-in-out infinite alternate;
}

.card-wrap.revealed .butterfly {
  animation: butterfly-rise 1.8s ease-out 1.25s forwards;
}

.card-wrap.revealed .word-butterfly {
  animation: butterfly-word-rise 1.2s ease-out 0.9s forwards;
}

.card-wrap.revealed .butterfly::before {
  animation: butterfly-flap-left 220ms ease-in-out infinite alternate;
}

.card-wrap.revealed .butterfly::after {
  animation: butterfly-flap-right 220ms ease-in-out infinite alternate;
}

.bat-swarm {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 120;
}

.swarm-bat {
  position: absolute;
  display: block;
  width: 30px;
  height: auto;
  transform-origin: center center;
  will-change: transform, opacity;
  image-rendering: pixelated;
  pointer-events: none;
}

@keyframes fold-left {
  from {
    transform: rotateY(0deg) translateZ(8px);
  }
  to {
    transform: rotateY(-150deg) translateX(-8px) translateZ(-4px);
  }
}

@keyframes fold-right {
  from {
    transform: rotateY(0deg) translateZ(8px);
  }
  to {
    transform: rotateY(150deg) translateX(8px) translateZ(-4px);
  }
}

@keyframes sheet-reveal {
  from {
    opacity: 0;
    transform: translateZ(4px) scale(0.94);
  }
  to {
    opacity: 1;
    transform: translateZ(0) scale(1);
  }
}

@keyframes wing-flap {
  from {
    transform: rotateY(0deg);
  }
  to {
    transform: rotateY(55deg);
  }
}

@keyframes swarm-flutter {
  from {
    transform: scaleY(0.94);
  }
  to {
    transform: scaleY(1.06);
  }
}

@keyframes bat-flight-1 {
  0% { opacity: 0; transform: translate(0, 0) scale(0.3); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translate(-120px, -120px) scale(0.9); }
}

@keyframes bat-flight-2 {
  0% { opacity: 0; transform: translate(0, 0) scale(0.35); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translate(-30px, -150px) scale(0.85); }
}

@keyframes bat-flight-3 {
  0% { opacity: 0; transform: translate(0, 0) scale(0.32); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translate(95px, -145px) scale(0.95); }
}

@keyframes bat-flight-4 {
  0% { opacity: 0; transform: translate(0, 0) scale(0.34); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translate(140px, -80px) scale(0.82); }
}

@keyframes bat-flight-5 {
  0% { opacity: 0; transform: translate(0, 0) scale(0.34); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translate(-85px, -72px) scale(0.86); }
}

@keyframes butterfly-rise {
  0% {
    opacity: 0;
    transform: translateY(8px) scale(0.75);
  }
  25% {
    opacity: 1;
  }
  100% {
    opacity: 1;
    transform: translate(0, -110px) scale(1.05) rotate(-7deg);
  }
}

@keyframes butterfly-word-rise {
  0% {
    opacity: 0;
    transform: translateY(6px) scale(0.72);
  }
  40% {
    opacity: 1;
  }
  100% {
    opacity: 1;
    transform: translate(-2px, -10px) scale(0.95) rotate(-7deg);
  }
}

@keyframes butterfly-flap-left {
  from {
    transform: rotateY(0deg) rotate(-8deg);
  }
  to {
    transform: rotateY(62deg) rotate(8deg);
  }
}

@keyframes butterfly-flap-right {
  from {
    transform: scaleX(-1) rotateY(0deg) rotate(-8deg);
  }
  to {
    transform: scaleX(-1) rotateY(62deg) rotate(8deg);
  }
}

#restart {
  border: 0;
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 900;
  color: #fff;
  background: linear-gradient(140deg, var(--accent), #ff8a61);
  box-shadow: 0 8px 16px #7f2a2855;
}

.hidden {
  display: none;
}

@media (min-width: 830px) {
  .app-shell {
    padding-top: 20px;
    padding-bottom: 20px;
    gap: 14px;
  }

  .control {
    min-width: 92px;
    min-height: 62px;
  }
}

.splash-screen {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  background: linear-gradient(180deg, #102233, #142a38 65%, #17303c);
  padding: 16px 0;
}

.splash-screen.hidden {
  display: none;
}

.splash-art {
  width: min(98vw, 900px);
  height: min(82vh, 980px);
  object-fit: contain;
  border-radius: 14px;
  border: 2px solid #ffffffb8;
  box-shadow: 0 20px 38px #00000066;
}

.start-btn {
  border: 0;
  border-radius: 999px;
  padding: 12px 20px;
  font-weight: 900;
  color: #fff8ea;
  background: linear-gradient(140deg, #b26442, var(--splash-bark));
  box-shadow: 0 10px 20px #3d24185c;
}

.splash-hint {
  margin: -2px 0 0;
  color: #f4e6c7;
  font-weight: 800;
  font-size: clamp(0.85rem, 3.6vw, 1rem);
  text-shadow: 0 2px 8px #00000066;
}

.touch-controls.locked {
  opacity: 0.35;
  pointer-events: none;
}

body.splash-active .app-shell {
  visibility: hidden;
}
