:root {
  color-scheme: light;

  --white: #ffffff;
  --mint-50: #f0fff8;
  --mint-100: #dcfaeb;
  --mint-200: #b8efd4;
  --mint-300: #87ddb7;
  --green: #1fa873;
  --green-dark: #126749;
  --green-deep: #0c4f39;
  --pink: #ffabc8;
  --pink-dark: #dd4f7d;
  --yellow: #ffe17e;
  --red: #f15b6c;
  --text: #143d33;
  --shadow: rgba(12, 79, 57, 0.18);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

html {
  background: #c8efdc;
}

body {
  overflow: hidden;
  overscroll-behavior: none;

  font-family:
    "Arial Rounded MT Bold",
    "Trebuchet MS",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;

  color: var(--text);
  background: #c8efdc;

  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
}

button,
.player,
.playfield {
  touch-action: none;
}

img {
  -webkit-user-drag: none;
  user-select: none;
}

.app {
  position: relative;

  width: min(100vw, 500px);
  height: 100dvh;
  min-height: 540px;

  margin-inline: auto;

  overflow: hidden;

  background:
    radial-gradient(circle at 13% 12%, rgba(255, 255, 255, 0.95) 0 5%, transparent 5.5%),
    radial-gradient(circle at 85% 18%, rgba(255, 225, 126, 0.45) 0 8%, transparent 8.5%),
    linear-gradient(180deg, #effff8 0%, #d9f8e8 48%, #b8ebd2 100%);

  box-shadow: 0 0 60px rgba(12, 79, 57, 0.22);
}

.screen {
  position: absolute;
  inset: 0;

  width: 100%;
  height: 100%;

  transition:
    opacity 220ms ease,
    transform 220ms ease;
}

.is-hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.985);
}

.opening-screen {
  display: grid;
  place-items: center;

  padding:
    max(24px, env(safe-area-inset-top))
    20px
    max(24px, env(safe-area-inset-bottom));

  overflow: hidden;
}

.opening-bubbles {
  position: absolute;
  inset: 0;

  pointer-events: none;
}

.opening-bubbles span {
  position: absolute;

  font-size: clamp(1.4rem, 6vw, 2.4rem);

  animation: float-decoration 4s ease-in-out infinite;
}

.opening-bubbles span:nth-child(1) {
  left: 7%;
  top: 12%;
}

.opening-bubbles span:nth-child(2) {
  right: 8%;
  top: 8%;
  animation-delay: -1.3s;
}

.opening-bubbles span:nth-child(3) {
  right: 5%;
  bottom: 16%;
  animation-delay: -2.2s;
}

.opening-bubbles span:nth-child(4) {
  left: 6%;
  bottom: 12%;
  animation-delay: -0.8s;
}

.opening-bubbles span:nth-child(5) {
  left: 16%;
  top: 42%;
  animation-delay: -3s;
}

.opening-card,
.win-card {
  position: relative;
  z-index: 2;

  width: min(100%, 420px);

  padding: 28px 22px;

  text-align: center;

  border: 4px solid rgba(255, 255, 255, 0.95);
  border-radius: 34px;

  background: rgba(255, 255, 255, 0.88);

  box-shadow:
    0 24px 50px var(--shadow),
    inset 0 0 0 2px rgba(31, 168, 115, 0.08);

  backdrop-filter: blur(12px);
}

.opening-icon,
.win-tooth {
  display: grid;
  place-items: center;

  width: 86px;
  height: 86px;

  margin: -66px auto 12px;

  border: 5px solid var(--white);
  border-radius: 50%;

  background: linear-gradient(180deg, var(--yellow), #fff3bd);

  font-size: 3.1rem;

  box-shadow: 0 10px 24px rgba(12, 79, 57, 0.18);

  animation: tooth-bounce 1.8s ease-in-out infinite;
}

.eyebrow {
  margin: 0 0 10px;

  color: var(--green);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.12em;
}

h1,
h2 {
  margin: 0;

  color: var(--green-deep);

  font-weight: 1000;
  line-height: 0.88;

  text-shadow:
    0 3px 0 var(--white),
    0 6px 0 rgba(31, 168, 115, 0.14);
}

h1 {
  font-size: clamp(3.2rem, 16vw, 5.4rem);
}

h2 {
  font-size: clamp(2.35rem, 11vw, 4rem);
}

.opening-copy,
.win-message {
  max-width: 340px;
  margin: 20px auto;

  font-size: 1.04rem;
  font-weight: 700;
  line-height: 1.45;
}

.opening-instruction,
.win-joke {
  margin: 18px auto 0;

  color: rgba(20, 61, 51, 0.72);
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.4;
}

.primary-button {
  min-width: 220px;
  min-height: 58px;

  padding: 14px 24px;

  border: 0;
  border-radius: 999px;

  color: var(--white);
  background: linear-gradient(180deg, #35ce96, var(--green));

  font-weight: 1000;
  letter-spacing: 0.04em;

  box-shadow:
    0 8px 0 var(--green-dark),
    0 14px 24px rgba(18, 103, 73, 0.24);

  cursor: pointer;

  transition:
    transform 100ms ease,
    box-shadow 100ms ease;
}

.primary-button:active {
  transform: translateY(5px);

  box-shadow:
    0 3px 0 var(--green-dark),
    0 8px 14px rgba(18, 103, 73, 0.22);
}

.game-screen {
  overflow: hidden;
}

.game-header {
  position: relative;
  z-index: 30;

  display: flex;
  align-items: flex-start;
  gap: 10px;

  height: 112px;

  padding:
    max(12px, env(safe-area-inset-top))
    14px
    8px;
}

.score-panel {
  flex: 1;

  min-width: 0;

  padding: 10px 14px;

  border: 3px solid rgba(255, 255, 255, 0.95);
  border-radius: 20px;

  background: rgba(255, 255, 255, 0.88);

  box-shadow: 0 10px 25px rgba(12, 79, 57, 0.12);

  backdrop-filter: blur(8px);
}

.score-label {
  display: block;

  margin-bottom: 2px;

  color: var(--green-dark);
  font-size: 0.67rem;
  font-weight: 1000;
  letter-spacing: 0.08em;
}

.score-row {
  display: flex;
  align-items: baseline;
  gap: 5px;

  color: var(--green-deep);
}

.score-row strong {
  font-size: 1.75rem;
  line-height: 1;
}

.score-row span {
  font-size: 0.92rem;
  font-weight: 900;
}

.progress-track {
  width: 100%;
  height: 7px;

  margin-top: 7px;

  overflow: hidden;

  border-radius: 999px;

  background: #cde9db;
}

.progress-fill {
  width: 0%;
  height: 100%;

  border-radius: inherit;

  background: linear-gradient(90deg, var(--green), var(--yellow));

  transition: width 180ms ease;
}

.icon-button {
  display: grid;
  place-items: center;

  width: 50px;
  height: 50px;

  flex: 0 0 auto;

  border: 3px solid var(--white);
  border-radius: 16px;

  background: rgba(255, 255, 255, 0.9);

  font-size: 1.35rem;

  box-shadow: 0 8px 20px rgba(12, 79, 57, 0.12);

  cursor: pointer;
}

.game-title-row {
  position: absolute;
  z-index: 25;
  top: 103px;
  left: 0;
  right: 0;

  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;

  pointer-events: none;
}

#stageLabel {
  padding: 7px 13px;

  border: 2px solid rgba(255, 255, 255, 0.94);
  border-radius: 999px;

  color: var(--green-dark);
  background: rgba(255, 255, 255, 0.8);

  font-size: 0.72rem;
  font-weight: 1000;
  letter-spacing: 0.06em;

  box-shadow: 0 7px 18px rgba(12, 79, 57, 0.1);
}

#comboCounter {
  color: var(--pink-dark);
  font-size: 0.74rem;
  font-weight: 1000;
}

.playfield {
  position: absolute;
  inset: 0;

  overflow: hidden;

  background:
    linear-gradient(90deg, transparent 49%, rgba(255,255,255,0.24) 50%, transparent 51%),
    repeating-linear-gradient(
      0deg,
      rgba(255,255,255,0.15) 0 2px,
      transparent 2px 56px
    );
}

.clinic-decoration {
  position: absolute;
  z-index: 1;

  display: flex;
  flex-direction: column;
  gap: 8px;

  pointer-events: none;

  opacity: 0.36;
}

.clinic-decoration-left {
  left: 12px;
  top: 30%;
}

.clinic-decoration-right {
  right: 12px;
  top: 42%;
}

.clinic-decoration span {
  font-size: 1.75rem;
}

.falling-layer,
.message-layer,
.reaction-flash {
  position: absolute;
  inset: 0;
}

.falling-layer {
  z-index: 10;

  pointer-events: none;
}

.message-layer {
  z-index: 40;

  pointer-events: none;
}

.reaction-flash {
  z-index: 35;

  pointer-events: none;
  opacity: 0;
}

.reaction-flash.is-correct {
  animation: correct-flash 420ms ease-out;
}

.reaction-flash.is-wrong {
  animation: wrong-flash 500ms ease-out;
}

.falling-item {
  position: absolute;
  top: 0;
  left: 0;

  display: grid;
  place-items: center;

  width: var(--item-size);
  height: var(--item-size);

  transform: translate3d(var(--x), var(--y), 0);

  will-change: transform;

  filter: drop-shadow(0 7px 5px rgba(12, 79, 57, 0.18));
}

.falling-item-inner {
  display: grid;
  place-items: center;

  width: 100%;
  height: 100%;

  font-size: calc(var(--item-size) * 0.82);
  line-height: 1;

  transform-origin: center;

  animation: item-float 1.05s ease-in-out infinite alternate;
}

.falling-item.is-wobbling .falling-item-inner {
  animation:
    item-float 0.78s ease-in-out infinite alternate,
    item-wobble 0.6s ease-in-out infinite alternate;
}

.falling-item.is-final .falling-item-inner {
  border-radius: 50%;

  background: radial-gradient(
    circle,
    rgba(255, 244, 168, 0.95) 0%,
    rgba(255, 225, 126, 0.6) 44%,
    rgba(255, 225, 126, 0) 72%
  );

  animation:
    final-tooth-glow 0.75s ease-in-out infinite alternate,
    item-wobble 0.8s ease-in-out infinite alternate;
}

.player {
  position: absolute;
  z-index: 20;
  left: 50%;
  bottom: max(-3px, env(safe-area-inset-bottom));

  width: min(46vw, 230px);

  transform: translateX(-50%);
  transform-origin: center bottom;

  will-change: left, transform;
}

.player-image {
  display: block;

  width: 100%;
  height: auto;

  pointer-events: none;

  filter: drop-shadow(0 9px 7px rgba(12, 79, 57, 0.2));
}

.player.wrong-reaction {
  animation: player-shake 420ms ease-in-out;
}

.player.correct-reaction {
  animation: player-bounce 320ms ease-out;
}

.catch-zone {
  position: absolute;
  z-index: 5;

  left: 50%;
  top: 2.2%;

  width: 48%;
  height: 12%;

  transform: translateX(-50%);

  border-radius: 16px;

  pointer-events: none;
}

body.debug-catch-zone .catch-zone {
  border: 3px dashed #f00000;
  background: rgba(255, 0, 0, 0.2);
}

.score-popup {
  position: absolute;
  z-index: 60;

  transform: translate(-50%, -50%);

  font-size: 2rem;
  font-weight: 1000;

  pointer-events: none;

  animation: popup-rise 720ms ease-out forwards;
}

.score-popup.is-correct {
  color: var(--green-dark);

  text-shadow:
    0 2px 0 var(--white),
    0 4px 9px rgba(12, 79, 57, 0.22);
}

.score-popup.is-wrong {
  color: var(--red);

  text-shadow:
    0 2px 0 var(--white),
    0 4px 9px rgba(221, 79, 125, 0.22);
}

.combo-message,
.final-message {
  position: absolute;
  left: 50%;
  top: 37%;

  width: 90%;

  transform: translateX(-50%);

  text-align: center;

  color: var(--green-dark);

  font-size: clamp(1.55rem, 8vw, 2.8rem);
  font-weight: 1000;
  line-height: 1;

  text-shadow:
    0 3px 0 var(--white),
    0 7px 14px rgba(12, 79, 57, 0.2);

  animation: message-pop 900ms ease-out forwards;
}

.final-message {
  color: #d39a00;
  font-size: clamp(2rem, 10vw, 3.6rem);
}

.sparkle {
  position: absolute;

  font-size: 1.2rem;

  animation: sparkle-burst 650ms ease-out forwards;
}

.win-screen {
  display: grid;
  place-items: center;

  padding:
    max(28px, env(safe-area-inset-top))
    20px
    max(26px, env(safe-area-inset-bottom));

  overflow: hidden;

  background:
    radial-gradient(circle at center, rgba(255,255,255,0.95), transparent 48%),
    linear-gradient(180deg, #ebfff6, #b7ebd1);
}

.win-card {
  max-height: calc(100dvh - 48px);
  overflow: auto;

  padding-top: 24px;
}

.win-character-wrap {
  display: flex;
  justify-content: center;

  height: min(34dvh, 260px);

  margin: 12px auto 4px;

  overflow: hidden;
}

.win-character {
  display: block;

  width: auto;
  height: 100%;

  object-fit: contain;

  filter: drop-shadow(0 8px 7px rgba(12, 79, 57, 0.18));

  animation: victory-bounce 1.1s ease-in-out infinite alternate;
}

.win-message {
  margin-top: 8px;
  margin-bottom: 10px;

  font-size: 0.94rem;
}

.win-joke {
  margin: 0 auto 18px;
}

.confetti-layer {
  position: absolute;
  inset: 0;

  overflow: hidden;

  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -12%;

  width: 10px;
  height: 18px;

  border-radius: 3px;

  animation: confetti-fall var(--duration) linear forwards;
}

@keyframes float-decoration {
  0%,
  100% {
    transform: translateY(0) rotate(-4deg);
  }

  50% {
    transform: translateY(-12px) rotate(5deg);
  }
}

@keyframes tooth-bounce {
  0%,
  100% {
    transform: translateY(0) rotate(-4deg);
  }

  50% {
    transform: translateY(-8px) rotate(4deg);
  }
}

@keyframes item-float {
  from {
    transform: rotate(-5deg) scale(0.96);
  }

  to {
    transform: rotate(5deg) scale(1.04);
  }
}

@keyframes item-wobble {
  from {
    margin-left: -7px;
  }

  to {
    margin-left: 7px;
  }
}

@keyframes final-tooth-glow {
  from {
    transform: scale(0.98) rotate(-6deg);
    filter: drop-shadow(0 0 6px rgba(255, 199, 0, 0.75));
  }

  to {
    transform: scale(1.1) rotate(6deg);
    filter: drop-shadow(0 0 18px rgba(255, 199, 0, 1));
  }
}

@keyframes player-shake {
  0%,
  100% {
    transform: translateX(-50%) rotate(0);
  }

  20% {
    transform: translateX(calc(-50% - 9px)) rotate(-3deg);
  }

  40% {
    transform: translateX(calc(-50% + 9px)) rotate(3deg);
  }

  60% {
    transform: translateX(calc(-50% - 6px)) rotate(-2deg);
  }

  80% {
    transform: translateX(calc(-50% + 6px)) rotate(2deg);
  }
}

@keyframes player-bounce {
  0%,
  100% {
    transform: translateX(-50%) scale(1);
  }

  50% {
    transform: translateX(-50%) scale(1.055);
  }
}

@keyframes popup-rise {
  0% {
    opacity: 0;
    transform: translate(-50%, -30%) scale(0.7);
  }

  20% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.2);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -145%) scale(0.96);
  }
}

@keyframes message-pop {
  0% {
    opacity: 0;
    transform: translateX(-50%) scale(0.65);
  }

  18% {
    opacity: 1;
    transform: translateX(-50%) scale(1.12);
  }

  70% {
    opacity: 1;
    transform: translateX(-50%) scale(1);
  }

  100% {
    opacity: 0;
    transform: translateX(-50%) translateY(-28px) scale(0.94);
  }
}

@keyframes sparkle-burst {
  from {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.5);
  }

  to {
    opacity: 0;
    transform:
      translate(
        calc(-50% + var(--sparkle-x)),
        calc(-50% + var(--sparkle-y))
      )
      scale(1.25)
      rotate(160deg);
  }
}

@keyframes correct-flash {
  0% {
    opacity: 0;
    background: rgba(44, 211, 145, 0);
  }

  30% {
    opacity: 1;
    background: rgba(44, 211, 145, 0.16);
  }

  100% {
    opacity: 0;
    background: rgba(44, 211, 145, 0);
  }
}

@keyframes wrong-flash {
  0% {
    opacity: 0;
    background: rgba(241, 91, 108, 0);
  }

  30% {
    opacity: 1;
    background: rgba(241, 91, 108, 0.19);
  }

  100% {
    opacity: 0;
    background: rgba(241, 91, 108, 0);
  }
}

@keyframes victory-bounce {
  from {
    transform: translateY(3px) rotate(-1deg);
  }

  to {
    transform: translateY(-8px) rotate(1deg);
  }
}

@keyframes confetti-fall {
  0% {
    transform: translate3d(0, -10vh, 0) rotate(0);
  }

  100% {
    transform:
      translate3d(var(--drift), 115vh, 0)
      rotate(var(--rotation));
  }
}

@media (max-height: 670px) {
  .game-header {
    height: 98px;
    padding-top: max(8px, env(safe-area-inset-top));
  }

  .game-title-row {
    top: 91px;
  }

  .score-panel {
    padding: 7px 12px;
  }

  .score-row strong {
    font-size: 1.5rem;
  }

  .player {
    width: min(41vw, 205px);
  }

  .opening-card {
    padding-top: 24px;
    padding-bottom: 22px;
  }

  .opening-icon {
    width: 72px;
    height: 72px;
    margin-top: -57px;
    font-size: 2.6rem;
  }

  .opening-copy {
    margin: 14px auto;
  }
}

@media (min-width: 501px) {
  .app {
    border-left: 1px solid rgba(255, 255, 255, 0.7);
    border-right: 1px solid rgba(255, 255, 255, 0.7);
  }
}

@media (prefers-reduced-motion: reduce) {
  .opening-bubbles span,
  .opening-icon,
  .win-tooth,
  .win-character,
  .falling-item-inner {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
  }
}
