.kz-match {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  width: 100%;
  height: 100%;
  min-height: 0;
  box-sizing: border-box;
  padding: 0.4rem 0.5rem 0.45rem;
  font-family: system-ui, -apple-system, Segoe UI, sans-serif;
  color: #0f172a;
  overflow: hidden;
}

.kz-match__hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.3rem 0.65rem;
  flex-shrink: 0;
  padding: 0.4rem 0.7rem;
  border-radius: 0.55rem;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.06);
  font-weight: 800;
  font-size: 0.88rem;
}

.kz-match__target strong {
  color: #ea580c;
}

.kz-match__score.is-flash-score {
  color: #15803d;
}

.kz-match__lives.is-flash-life {
  color: #b91c1c;
  background: #fee2e2;
  border-radius: 999px;
  padding: 0.1rem 0.4rem;
}

.kz-match__stage {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 0.55rem;
  min-height: 0;
  min-width: 0;
  width: 100%;
  padding: 0.55rem 0.7rem 0.65rem;
  border-radius: 0.85rem;
  background: linear-gradient(180deg, #e0f2fe 0%, #f0f9ff 45%, #fff7ed 100%);
  overflow: hidden;
  box-sizing: border-box;
}

.kz-match > .kz-shape-ask {
  flex-shrink: 0;
  position: relative;
  z-index: 12;
}

.kz-match__prompt {
  margin: 0;
  flex-shrink: 0;
  text-align: center;
  font-size: clamp(0.92rem, 2.2vw, 1.1rem);
  font-weight: 800;
  color: #1e293b;
  line-height: 1.3;
  letter-spacing: 0.01em;
}

.kz-match__board {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  gap: 0.85rem;
  width: 100%;
  min-height: 0;
  min-width: 0;
}

/* Horizontal word + drop-slot cards */
.kz-match__map {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: stretch;
  gap: clamp(0.45rem, 2vw, 1rem);
  width: 100%;
  min-height: 0;
  flex: 0 0 auto;
}

.kz-match__card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  flex: 1 1 0;
  min-width: 0;
  max-width: 9.5rem;
  padding: 0.45rem 0.4rem 0.5rem;
  border-radius: 0.8rem;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.06);
}

.kz-match__word {
  font-size: clamp(1rem, 2.6vw, 1.35rem);
  font-weight: 900;
  letter-spacing: 0.01em;
  text-transform: lowercase;
  color: #0f172a;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  line-height: 1.2;
}

.kz-match__slot {
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(3.5rem, 10vh, 5rem);
  height: clamp(3.5rem, 10vh, 5rem);
  aspect-ratio: 1;
  flex-shrink: 0;
  padding: 0.15rem;
  border: 2px dashed #94a3b8;
  border-radius: 0.7rem;
  background: rgba(255, 255, 255, 0.95);
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease, transform 0.12s ease;
}

.kz-match__slot-hint {
  font-size: 0.68rem;
  font-weight: 700;
  color: #94a3b8;
  text-align: center;
  line-height: 1.15;
  pointer-events: none;
}

.kz-match__slot:hover,
.kz-match__slot:focus-visible,
.kz-match__slot.is-over {
  outline: none;
  border-color: #ea580c;
  border-style: solid;
  background: #fff7ed;
  transform: scale(1.03);
}

.kz-match__slot.is-filled {
  border-style: solid;
  border-color: #86efac;
  background: #bbf7d0;
  cursor: default;
  pointer-events: none;
}

.kz-match__slot.is-wrong {
  border-color: #f87171;
  background: #fecaca;
  animation: kz-match-shake 0.35s ease;
}

.kz-match__slot-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  border-radius: 0.45rem;
}

/* Picture options row under the map */
.kz-match__tray {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: center;
  gap: clamp(0.5rem, 2.5vw, 1.1rem);
  width: 100%;
  min-height: 0;
  flex: 0 0 auto;
  padding: 0.15rem 0 0.25rem;
}

.kz-match__pic {
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(3.5rem, 10vh, 5rem);
  height: clamp(3.5rem, 10vh, 5rem);
  aspect-ratio: 1;
  flex: 0 0 auto;
  padding: 0.2rem;
  border: 2px solid transparent;
  border-radius: 0.7rem;
  background: #fff;
  cursor: grab;
  box-shadow: 0 2px 0 rgba(15, 23, 42, 0.08);
  transition: transform 0.12s ease, border-color 0.12s ease, opacity 0.2s ease;
}

.kz-match__pic:active {
  cursor: grabbing;
}

.kz-match__img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  border-radius: 0.45rem;
  pointer-events: none;
}

.kz-match__pic:hover,
.kz-match__pic:focus-visible {
  transform: translateY(-2px);
  outline: none;
  border-color: rgba(234, 88, 12, 0.4);
}

.kz-match__pic.is-selected,
.kz-match__pic.is-dragging {
  border-color: #ea580c;
  box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.22);
}

.kz-match__pic.is-placed {
  opacity: 0.72;
  pointer-events: none;
  cursor: default;
  filter: none;
}

.kz-match__pic.is-wrong {
  background: #fecaca;
  border-color: #f87171;
  animation: kz-match-shake 0.35s ease;
}

@keyframes kz-match-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

.kz-match__float {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, 0);
  font-weight: 900;
  font-size: 1.15rem;
  pointer-events: none;
  animation: kz-match-float 0.9s ease forwards;
  z-index: 5;
}

.kz-match__float--score {
  color: #15803d;
}

.kz-match__float--life {
  color: #b91c1c;
}

@keyframes kz-match-float {
  0% {
    opacity: 1;
    transform: translate(-50%, 0);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -40px);
  }
}

.kz-match__overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.45);
  border-radius: 1rem;
  z-index: 6;
}

.kz-match__overlay[hidden] {
  display: none !important;
}

.kz-match__overlay-card {
  background: #fff;
  border-radius: 1rem;
  padding: 1.25rem 1.5rem;
  text-align: center;
  max-width: 18rem;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.25);
}

.kz-match__overlay-title {
  margin: 0 0 0.35rem;
  font-size: 1.25rem;
  font-weight: 900;
}

.kz-match__overlay-score {
  margin: 0 0 0.85rem;
  font-weight: 800;
}

.kz-match__restart {
  border: 0;
  border-radius: 999px;
  padding: 0.65rem 1.25rem;
  background: #ea580c;
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.kz-letter-hub__play .kz-match-mount,
.kz-letter-hub__play .kz-match {
  width: 100%;
  height: 100%;
  min-height: 0;
  gap: 0.28rem;
  padding: 0.25rem 0.3rem 0.3rem;
}

.kz-letter-hub__stage-inner:has(.kz-match-mount),
.kz-letter-hub__stage-inner:has(.kz-match) {
  align-items: stretch;
  justify-content: stretch;
}

.kz-letter-hub__play:has(.kz-match) {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Desktop hub: question on the left of the main stage; play board on the right. */
.kz-letter-hub__play .kz-match__hud {
  padding: 0.35rem 0.55rem;
  font-size: 0.8rem;
  gap: 0.35rem 0.65rem;
}

.kz-letter-hub__play .kz-match__stage {
  container-type: size;
  container-name: kz-match-stage;
  display: grid;
  grid-template-columns: minmax(6.25rem, 0.22fr) minmax(0, 1fr);
  grid-template-areas: 'prompt board';
  gap: 0.45rem;
  padding: 0.4rem;
  align-items: stretch;
  justify-content: stretch;
}

.kz-letter-hub__play .kz-match__prompt {
  grid-area: prompt;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  align-self: stretch;
  text-align: left;
  margin: 0;
  padding: 0.55rem 0.5rem;
  border-radius: 0.7rem;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.06);
  font-size: clamp(0.78rem, 4.2cqh, 1rem);
  line-height: 1.3;
}

.kz-letter-hub__play .kz-match__board {
  grid-area: board;
  gap: clamp(0.35rem, 2.5cqh, 0.65rem);
  justify-content: center;
  min-width: 0;
}

.kz-letter-hub__play .kz-match__map,
.kz-letter-hub__play .kz-match__tray {
  gap: clamp(0.3rem, 1.8cqw, 0.75rem);
}

.kz-letter-hub__play .kz-match__card {
  padding: 0.3rem 0.25rem 0.35rem;
  gap: 0.3rem;
  max-width: 7.5rem;
}

.kz-letter-hub__play .kz-match__word {
  font-size: clamp(0.85rem, 4.5cqh, 1.15rem);
}

.kz-letter-hub__play .kz-match__slot,
.kz-letter-hub__play .kz-match__pic {
  width: clamp(3.1rem, 26cqh, 5rem);
  height: clamp(3.1rem, 26cqh, 5rem);
}

.kz-letter-hub__play .kz-match__slot-hint {
  font-size: 0.58rem;
}

@media (max-width: 900px) {
  .kz-letter-hub__play .kz-match__stage {
    grid-template-columns: 1fr;
    grid-template-areas:
      'prompt'
      'board';
  }

  .kz-letter-hub__play .kz-match__prompt {
    justify-content: center;
    text-align: center;
    padding: 0.4rem 0.45rem;
  }
}

.kz-match-wrap {
  width: 100%;
  max-width: 44rem;
  margin: 0 auto;
  min-height: 22rem;
  height: min(70vh, 30rem);
}

@media (max-width: 560px) {
  .kz-match {
    padding: 0.25rem 0.3rem 0.3rem;
    gap: 0.3rem;
  }

  .kz-match__stage {
    padding: 0.4rem 0.35rem 0.45rem;
    gap: 0.35rem;
  }

  .kz-match__prompt {
    font-size: 0.85rem;
  }

  .kz-match__board {
    gap: 0.55rem;
    justify-content: center;
  }

  .kz-match__map,
  .kz-match__tray {
    gap: 0.3rem;
  }

  .kz-match__card {
    padding: 0.28rem 0.15rem 0.3rem;
    max-width: none;
    gap: 0.3rem;
  }

  .kz-match__pic,
  .kz-match__slot {
    width: 3.25rem;
    height: 3.25rem;
  }

  .kz-match__word {
    font-size: 0.9rem;
  }

  .kz-match__hud {
    font-size: 0.78rem;
    padding: 0.35rem 0.45rem;
  }

  .kz-match__slot-hint {
    font-size: 0.55rem;
  }
}

.kz-play-rich .kz-match__card {
  background: #fff7ed;
  border: 3px solid #fdba74;
  box-shadow: 0 4px 0 #fb923c;
  border-radius: 1rem;
  max-width: 11rem;
}

.kz-play-rich .kz-match__word {
  font-size: clamp(1.15rem, 3vw, 1.55rem);
  background: #fff;
  padding: 0.15rem 0.45rem;
  border-radius: 0.4rem;
  box-shadow: 0 2px 0 #fed7aa;
}

.kz-play-rich .kz-match__slot,
.kz-play-rich .kz-match__pic {
  width: clamp(4.25rem, 12vh, 6.25rem);
  height: clamp(4.25rem, 12vh, 6.25rem);
  border-radius: 1rem;
}

.kz-play-rich .kz-match__pic {
  background: #fff;
  box-shadow: 0 5px 0 #93c5fd;
}

.kz-letter-hub__play .kz-play-rich .kz-match__slot,
.kz-letter-hub__play .kz-play-rich .kz-match__pic {
  width: clamp(3.6rem, 30cqh, 6rem);
  height: clamp(3.6rem, 30cqh, 6rem);
}

.kz-play-rich .kz-match__prompt {
  font-size: clamp(1rem, 2.4vw, 1.2rem);
  background: rgba(255, 255, 255, 0.92);
  padding: 0.45rem 0.7rem;
  border-radius: 0.85rem;
}
