.kz-maze {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  width: 100%;
  min-height: 16rem;
  height: 100%;
  box-sizing: border-box;
  font-family: var(--kz-game-font, system-ui, sans-serif);
  color: var(--kz-game-ink, #0f172a);
}

.kz-maze__stage {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.55rem;
  border-radius: 1rem;
  background: linear-gradient(180deg, #c4b5fd 0%, #93c5fd 50%, #fef08a 100%);
  min-height: 13rem;
}

.kz-maze__hint {
  margin: 0;
  font-weight: 800;
  font-size: 0.82rem;
  text-align: center;
  max-width: 18rem;
  line-height: 1.3;
  flex: 0 0 auto;
}

.kz-maze__board {
  --kz-maze-size: 4;
  display: grid;
  grid-template-columns: repeat(var(--kz-maze-size), minmax(1.85rem, 2.35rem));
  gap: 0.28rem;
}

.kz-maze__cell {
  aspect-ratio: 1;
  border: 2px solid rgba(15, 23, 42, 0.12);
  border-radius: 0.45rem;
  background: rgba(255, 255, 255, 0.72);
  color: #334155;
  font-size: 0.95rem;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
  padding: 0;
  line-height: 1;
}

.kz-maze__cell--rime {
  font-size: 0.72rem;
}

.kz-maze__cell[data-path='1'] {
  background: #fff7ed;
  color: #c2410c;
  border-color: rgba(234, 88, 12, 0.35);
}

.kz-maze__cell.is-visited {
  background: #fdba74;
  color: #7c2d12;
  box-shadow: inset 0 0 0 2px #ea580c;
}

.kz-maze__cell.is-cursor {
  outline: 3px solid #16a34a;
}

.kz-maze__cell.is-wrong {
  background: #fecaca;
  color: #991b1b;
}

.kz-maze__cell.is-shake {
  animation: kz-maze-shake 0.35s ease;
}

@keyframes kz-maze-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  30% {
    transform: translateX(-4px);
  }
  70% {
    transform: translateX(4px);
  }
}

/* Hub stage fit — size board from stage box, never viewport vh */
.kz-letter-hub__play .kz-maze-mount,
.kz-letter-hub__play .kz-maze {
  width: 100%;
  height: 100%;
  min-height: 0;
  gap: 0.3rem;
}

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

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

.kz-letter-hub__play .kz-maze__hud {
  padding: 0.35rem 0.55rem;
  font-size: 0.8rem;
  gap: 0.35rem 0.65rem;
  flex: 0 0 auto;
}

.kz-letter-hub__play .kz-maze__stage {
  min-height: 0;
  flex: 1 1 auto;
  gap: 0.3rem;
  padding: 0.4rem;
  /* Size children against this stage, not the browser viewport. */
  container-type: size;
  container-name: kz-maze-stage;
}

.kz-letter-hub__play .kz-maze__hint {
  font-size: 0.72rem;
  max-width: min(18rem, 95cqw);
  line-height: 1.2;
}

.kz-letter-hub__play .kz-maze__board {
  /* Leave room for hint; square board capped by stage width/height. */
  --kz-maze-board: min(90cqw, calc(100cqh - 2.4rem), 17.5rem);
  width: var(--kz-maze-board);
  max-width: 100%;
  max-height: calc(100cqh - 2.4rem);
  aspect-ratio: 1;
  grid-template-columns: repeat(var(--kz-maze-size), minmax(0, 1fr));
  gap: clamp(0.15rem, 1.1cqh, 0.32rem);
  flex: 0 0 auto;
}

.kz-letter-hub__play .kz-maze__cell {
  width: 100%;
  min-width: 0;
  font-size: clamp(0.85rem, 5.2cqh, 1.25rem);
}

.kz-letter-hub__play .kz-maze__cell--rime {
  font-size: clamp(0.62rem, 3.8cqh, 0.85rem);
}

@media (prefers-reduced-motion: reduce) {
  .kz-maze__cell.is-shake {
    animation: none;
  }
}
