.kf-firefly-maze {
  width: 100%;
  font-family: 'Nunito', system-ui, sans-serif;
}

.kffm-picker {
  width: min(100%, 72rem);
  margin: 1.25rem auto 0;
  padding: clamp(1rem, 2.8vw, 1.75rem);
  box-sizing: border-box;
  border: 2px solid rgba(184, 160, 210, 0.55);
  border-radius: 30px;
  background: linear-gradient(145deg, #fdfaf4 0%, #f3eef8 100%);
  box-shadow: 0 14px 36px rgba(45, 27, 78, 0.12);
}

.kffm-picker-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.kffm-picker-heading h2,
.kffm-picker-heading p {
  margin: 0;
}

.kffm-picker-heading h2 {
  color: #2d1b4e;
  font-size: clamp(1.5rem, 3vw, 2rem);
}

.kffm-picker-heading p {
  color: #4a3f66;
  font-size: 1.05rem;
  font-weight: 700;
}

.kffm-levels {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(0.7rem, 2vw, 1.25rem);
}

.kffm-level {
  min-width: 0;
  min-height: 7rem;
  display: grid;
  grid-template-columns: minmax(7rem, 0.9fr) minmax(7.5rem, 1fr);
  align-items: center;
  gap: 0.8rem;
  box-sizing: border-box;
  border: 3px solid transparent;
  border-radius: 24px;
  padding: 0.55rem;
  background: #fff;
  color: #2d1b4e;
  text-align: left;
  box-shadow: 0 8px 20px rgba(45, 27, 78, 0.12);
  cursor: pointer;
  transition: transform 220ms ease, border-color 220ms ease, box-shadow 220ms ease;
}

.kffm-level:hover,
.kffm-level:focus-visible {
  transform: translateY(-3px);
  border-color: #b8a0d2;
  box-shadow: 0 12px 26px rgba(45, 27, 78, 0.18);
}

.kffm-level:focus-visible {
  outline: 4px solid #2ec4b6;
  outline-offset: 3px;
}

.kffm-level.is-selected {
  border-color: #2ec4b6;
  box-shadow: 0 0 0 3px rgba(46, 196, 182, 0.2), 0 12px 26px rgba(45, 27, 78, 0.16);
}

.kffm-level-art {
  position: relative;
  display: block;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  border-radius: 18px;
  background: #0f0a24;
}

.kffm-level-art > img:first-child {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 28%;
}

.kffm-level-friend {
  position: absolute;
  z-index: 1;
  left: 4%;
  bottom: -8%;
  width: 48%;
  height: auto;
  filter: drop-shadow(0 4px 5px rgba(15, 10, 36, 0.4));
}

.kffm-level-friend--bunny {
  left: -3%;
  bottom: -12%;
  width: 58%;
}

.kffm-level-friend--fawn {
  left: 1%;
  bottom: -15%;
  width: 43%;
}

.kffm-level-friend--otter {
  left: 0;
  bottom: -15%;
  width: 45%;
}

.kffm-level-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.08;
}

.kffm-level-copy strong {
  overflow-wrap: anywhere;
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-size: clamp(1.2rem, 2vw, 1.55rem);
}

.kffm-level-copy > span:last-child {
  margin-top: 0.25rem;
  color: #4a3f66;
  font-size: 0.95rem;
  font-weight: 800;
}

.kffm-level-difficulty {
  align-self: flex-start;
  margin-bottom: 0.35rem;
  border-radius: 999px;
  padding: 0.25rem 0.62rem;
  background: #ede6f5;
  color: #2d1b4e;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.kffm-level.is-selected .kffm-level-difficulty {
  background: #d8f6f2;
}

.kffm-story {
  width: min(100%, 58rem);
  display: grid;
  grid-template-columns: minmax(13.5rem, 16rem) minmax(0, 1fr);
  align-items: stretch;
  gap: clamp(1.5rem, 3vw, 2.25rem);
  box-sizing: border-box;
  margin: 1.1rem auto 0;
  border-radius: 24px;
  padding: 0.8rem;
  overflow: hidden;
  background: #2d1b4e;
  color: #fdfaf4;
  text-align: left;
  box-shadow: 0 12px 28px rgba(15, 10, 36, 0.2);
}

.kffm-story-art {
  min-width: 0;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  border: 2px solid rgba(255, 233, 168, 0.72);
  border-radius: 18px;
  background: #0f0a24;
  box-shadow: 0 8px 20px rgba(15, 10, 36, 0.3);
}

.kffm-story-art img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.kffm-story-text {
  min-width: 0;
  min-height: 12rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0.55rem clamp(0.55rem, 2vw, 1.2rem) 0.55rem 0.25rem;
}

.kffm-story-place {
  margin: 0 0 0.15rem;
  color: #ffe9a8;
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.kffm-story h2 {
  margin: 0;
  color: #fff;
  font-size: clamp(1.45rem, 3.5vw, 2rem);
}

.kffm-story-text > p:last-child {
  max-width: 46rem;
  margin: 0.35rem 0 0;
  color: #f4edf9;
  font-size: clamp(1.02rem, 2vw, 1.18rem);
  font-weight: 700;
  line-height: 1.45;
  white-space: pre-line;
}

@media (max-width: 700px) {
  .kffm-story {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .kffm-story-art {
    width: min(100%, 22rem);
    margin: 0 auto;
  }

  .kffm-story-text {
    min-height: 0;
    padding: 0.45rem 0.65rem 0.8rem;
    text-align: center;
  }

  .kffm-story-text > p:last-child {
    margin-inline: auto;
  }
}

.kffm-game {
  width: 100%;
}

.kffm-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin: 0.8rem auto 0.45rem;
}

.kffm-btn {
  min-height: 3.5rem;
  box-sizing: border-box;
  border: 2px solid #b8a0d2;
  border-radius: 999px;
  padding: 0.72rem 1.25rem;
  background: #ede6f5;
  color: #2d1b4e;
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-size: 1.02rem;
  font-weight: 700;
  cursor: pointer;
}

.kffm-btn:hover,
.kffm-btn:focus-visible {
  border-color: #2ec4b6;
  background: #fff;
}

.kffm-btn:focus-visible {
  outline: 4px solid #2ec4b6;
  outline-offset: 3px;
}

.kffm-btn[aria-pressed='true'] {
  border-color: #d4a843;
  background: #ffe9a8;
}

.kffm-status {
  min-height: 1.6rem;
  margin: 0;
  padding-inline: 1rem;
  color: #4a3f66;
  text-align: center;
  font-size: 1rem;
  font-weight: 800;
}

.kffm-stage {
  position: relative;
  width: min(100%, 44rem, calc((100dvh - 13.5rem) * 0.8));
  min-width: min(100%, 20rem);
  aspect-ratio: 4 / 5;
  margin: 0.6rem auto 0;
  overflow: hidden;
  border: 3px solid rgba(46, 196, 182, 0.72);
  border-radius: clamp(16px, 2.2vw, 30px);
  background: #0f0a24;
  box-shadow: 0 16px 46px rgba(15, 10, 36, 0.25);
}

.kffm-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.kffm-canvas:focus-visible {
  outline: 5px solid #2ec4b6;
  outline-offset: -7px;
}

.kffm-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  color: #fff;
  background: #2d1b4e;
  text-align: center;
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  pointer-events: none;
}

.kf-firefly-maze.is-ready .kffm-loading {
  display: none;
}

.kffm-win {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(15, 10, 36, 0.46);
}

.kffm-win[hidden] {
  display: none !important;
}

.kffm-win-card {
  width: min(88%, 28rem);
  box-sizing: border-box;
  border: 4px solid #ffe9a8;
  border-radius: 26px;
  padding: clamp(1.2rem, 4vw, 1.8rem);
  background: #fdfaf4;
  text-align: center;
  box-shadow: 0 12px 34px rgba(15, 10, 36, 0.32);
}

.kffm-win-card h2 {
  margin: 0 0 0.25rem;
  color: #2d1b4e;
  font-size: clamp(1.45rem, 4vw, 2rem);
}

.kffm-win-card p {
  margin: 0 0 1rem;
  color: #4a3f66;
  font-size: 1.05rem;
  font-weight: 700;
}

.kffm-win-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.kffm-win-card .kffm-btn:first-child {
  border-color: #2ec4b6;
  background: #2ec4b6;
  color: #0f0a24;
}

.kffm-confetti {
  position: absolute;
  z-index: 4;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.kffm-confetti span {
  --angle: calc(var(--i) * 30deg);
  position: absolute;
  left: 50%;
  top: 48%;
  width: 11px;
  height: 18px;
  border-radius: 7px;
  background: #d4a843;
  opacity: 0;
  transform: translate(-50%, -50%) rotate(var(--angle));
}

.kf-firefly-maze.is-celebrating .kffm-confetti span {
  animation: kffm-stardust 1.35s ease-out both;
  animation-delay: calc(var(--i) * 22ms);
}

.kf-firefly-maze.is-celebrating .kffm-confetti span:nth-child(3n + 1) {
  background: #2ec4b6;
}

.kf-firefly-maze.is-celebrating .kffm-confetti span:nth-child(3n + 2) {
  background: #b8a0d2;
}

@keyframes kffm-stardust {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(var(--angle)) translateY(0) scale(0.6);
  }
  16% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(var(--angle)) translateY(-230px) scale(1);
  }
}

@media (min-width: 768px) {
  .kffm-stage {
    width: min(100%, 58rem, calc((100dvh - 13.5rem) * 0.97));
    aspect-ratio: 32 / 33;
  }
}

@media (max-width: 960px) {
  .kffm-level {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .kffm-level-copy {
    align-items: center;
  }
}

@media (max-height: 700px) and (min-width: 768px) {
  .kffm-toolbar {
    margin-block: 0.35rem;
  }

  .kffm-status {
    font-size: 0.92rem;
  }

  .kffm-stage {
    width: min(100%, 58rem, calc((100dvh - 11.5rem) * 0.97));
  }
}

@media (max-width: 520px) {
  .kffm-picker {
    margin-top: 0.9rem;
    border-radius: 22px;
    padding: 0.8rem;
  }

  .kffm-picker-heading {
    display: block;
    text-align: center;
  }

  .kffm-picker-heading h2 {
    font-size: 1.4rem;
  }

  .kffm-picker-heading p {
    margin-top: 0.15rem;
    font-size: 0.9rem;
  }

  .kffm-levels {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.42rem;
  }

  .kffm-level {
    min-height: 0;
    gap: 0.35rem;
    border-radius: 17px;
    border-width: 2px;
    padding: 0.3rem 0.3rem 0.55rem;
  }

  .kffm-level-art {
    border-radius: 13px;
  }

  .kffm-level-copy strong {
    font-size: 0.98rem;
  }

  .kffm-level-copy > span:last-child {
    font-size: 0.76rem;
  }

  .kffm-level-difficulty {
    margin-bottom: 0.18rem;
    padding: 0.18rem 0.4rem;
    font-size: 0.62rem;
  }

  .kffm-story {
    margin-top: 0.8rem;
    border-radius: 20px;
  }

  .kffm-story-text > p:last-child {
    font-size: 1rem;
  }

  .kffm-stage {
    width: 100%;
    min-width: 0;
    max-width: 32rem;
    border-width: 2px;
    border-radius: 16px;
  }

  .kffm-toolbar {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.4rem;
    margin-top: 0.55rem;
  }

  .kffm-btn {
    min-height: 4rem;
    padding: 0.55rem 0.48rem;
    font-size: 0.9rem;
    line-height: 1.05;
  }

  .kffm-win-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .kffm-level {
    transition: none;
  }

  .kffm-level:hover,
  .kffm-level:focus-visible {
    transform: none;
  }

  .kf-firefly-maze.is-celebrating .kffm-confetti span {
    animation: none;
  }
}
