.game-stack-the-box {
  --stack-stage-art: none;
  --stack-navy: #17213a;
  --stack-blue: #43658b;
  --stack-gold: #ffd45a;
  --stack-red: #e62129;
  --stack-teal: #1cb5a3;
  --stack-cream: #fff0c2;
  display: flex;
  flex-direction: column;
  width: 100%;
}

.portal-page.is-game-focus .mini-game-card:has(.game-stack-the-box) {
  --game-card-play-min-height: 452px;
  --game-card-play-max-height: 780px;
  --game-stage-play-min-height: 322px;
}

.game-stack-the-box .game-hud {
  gap: 6px;
  padding: 8px;
  border-bottom: 3px solid #d6a437;
  background: linear-gradient(180deg, #304866, #17213a);
  box-shadow: inset 0 -3px 0 rgba(4, 10, 24, 0.38);
}

.game-stack-the-box .game-hud-item {
  min-height: 34px;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 5px 8px;
  border: 1px solid rgba(255, 212, 90, 0.5);
  border-radius: 10px;
  background: #16233b;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.05), 0 3px 0 rgba(4, 10, 24, 0.34);
}

.game-stack-the-box .game-hud-label {
  color: var(--stack-gold);
  font-size: 9px;
  line-height: 1;
  letter-spacing: 0.07em;
}

.game-stack-the-box .game-hud-value {
  color: #ffffff;
  font-size: 18px;
  line-height: 1;
}

.game-stack-the-box .game-stage {
  min-height: 322px;
  overflow: hidden;
  padding: 0;
  background:
    linear-gradient(180deg, rgba(23, 33, 58, 0.02), rgba(23, 33, 58, 0.12)),
    var(--stack-stage-art) center / cover no-repeat,
    var(--stack-navy);
  isolation: isolate;
  touch-action: manipulation;
  user-select: none;
}

.game-stack-the-box .game-stage::before {
  z-index: 1;
  inset: 17% 15% 12%;
  height: auto;
  border: 1px dashed rgba(255, 212, 90, 0.18);
  border-radius: 24px 24px 12px 12px;
  background: linear-gradient(180deg, rgba(255, 240, 194, 0.035), transparent 58%);
  filter: none;
  pointer-events: none;
}

.game-stack-the-box .game-stage::after {
  z-index: 9;
  background: linear-gradient(90deg, rgba(8, 17, 34, 0.12), transparent 10% 90%, rgba(8, 17, 34, 0.12));
  pointer-events: none;
}

.portal-page.is-game-focus .game-stack-the-box:not(.is-countdown):not(.is-playing):not(.is-completing):not(.is-finished) .game-stage {
  min-height: clamp(364px, 50svh, 420px);
}

@supports (height: 100dvh) {
  .portal-page.is-game-focus .game-stack-the-box:not(.is-countdown):not(.is-playing):not(.is-completing):not(.is-finished) .game-stage {
    min-height: clamp(364px, 50dvh, 420px);
  }
}

.portal-page.is-game-focus .game-stack-the-box.is-countdown .game-stage,
.portal-page.is-game-focus .game-stack-the-box.is-playing .game-stage,
.portal-page.is-game-focus .game-stack-the-box.is-completing .game-stage {
  min-height: var(--game-stage-play-min-height);
  height: clamp(340px, calc(100svh - 236px), 566px);
}

@supports (height: 100dvh) {
  .portal-page.is-game-focus .game-stack-the-box.is-countdown .game-stage,
  .portal-page.is-game-focus .game-stack-the-box.is-playing .game-stage,
  .portal-page.is-game-focus .game-stack-the-box.is-completing .game-stage {
    height: clamp(340px, calc(100dvh - 236px), 566px);
  }
}

.game-stack-the-box.is-finished .game-stage {
  min-height: 0;
  height: auto;
  background: #ffffff;
}

.game-stack-the-box.is-finished .game-overlay {
  position: static;
  display: block;
  padding: 12px 16px;
  background: #ffffff;
}

.game-stack-the-box.is-finished .game-overlay-panel {
  width: 100%;
  padding: 0;
  color: #111827;
  background: transparent;
  box-shadow: none;
  text-align: left;
}

.game-stack-the-box .stack-world,
.game-stack-the-box .stack-landed-layer,
.game-stack-the-box .stack-moving-layer {
  position: absolute;
  z-index: 3;
  inset: 0;
  pointer-events: none;
}

.game-stack-the-box .stack-platform {
  position: absolute;
  right: 14%;
  bottom: 28px;
  left: 14%;
  height: 34px;
  border: 3px solid #372716;
  border-radius: 9px 9px 15px 15px;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.08) 0 20px, rgba(15, 31, 58, 0.08) 20px 22px),
    linear-gradient(180deg, #c58b43, #805025);
  box-shadow: inset 0 5px 0 rgba(255, 235, 184, 0.28), 0 9px 0 rgba(29, 20, 12, 0.48), 0 16px 20px rgba(8, 12, 23, 0.3);
}

.game-stack-the-box .stack-crane-guide {
  position: absolute;
  z-index: 4;
  top: 18px;
  left: 50%;
  width: 2px;
  height: 70px;
  border-left: 2px dashed rgba(255, 212, 90, 0.46);
  opacity: 0;
  transform: translateX(-50%);
  transition: opacity 140ms ease;
  pointer-events: none;
}

.game-stack-the-box .stack-crane-guide span {
  position: absolute;
  right: -8px;
  bottom: 0;
  width: 16px;
  height: 10px;
  border: 3px solid var(--stack-gold);
  border-top: 0;
  border-radius: 0 0 10px 10px;
}

.game-stack-the-box.is-playing .stack-crane-guide {
  opacity: 0.68;
}

.game-stack-the-box .stack-box {
  position: absolute;
  left: var(--box-x);
  height: 28px;
  border: 2px solid rgba(31, 19, 15, 0.74);
  border-radius: 6px;
  box-shadow:
    inset 0 4px 0 rgba(255, 255, 255, 0.28),
    inset -7px 0 0 rgba(20, 26, 45, 0.14),
    0 5px 0 rgba(25, 16, 13, 0.34),
    0 8px 12px rgba(4, 10, 24, 0.22);
  transform: translateY(var(--stack-shift));
}

.game-stack-the-box .stack-box::before {
  position: absolute;
  top: -7px;
  right: 4px;
  left: 4px;
  height: 8px;
  border: 2px solid rgba(39, 22, 15, 0.6);
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  background: inherit;
  content: "";
  transform: skewX(-24deg);
}

.game-stack-the-box .stack-box--palette-0 {
  background: linear-gradient(180deg, #ef4246, #b81e2a);
}

.game-stack-the-box .stack-box--palette-1 {
  background: linear-gradient(180deg, #25c8b5, #11786f);
}

.game-stack-the-box .stack-box--palette-2 {
  background: linear-gradient(180deg, #ffd45a, #d28a1d);
}

.game-stack-the-box .stack-box__ribbon {
  position: absolute;
  top: -5px;
  bottom: 0;
  left: 50%;
  width: 13px;
  border-right: 2px solid rgba(83, 44, 12, 0.35);
  border-left: 2px solid rgba(255, 255, 255, 0.48);
  background: #f9d78d;
  transform: translateX(-50%);
}

.game-stack-the-box .stack-box strong {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  width: max-content;
  color: #ffffff;
  font-size: 7px;
  line-height: 1;
  letter-spacing: 0.04em;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.45);
  transform: translate(-50%, -50%);
}

.game-stack-the-box .stack-box--landed {
  bottom: calc(62px + var(--box-level) * 28px - var(--stack-shift));
  animation: stack-box-settle 180ms ease-out both;
}

.game-stack-the-box .stack-box--moving {
  bottom: calc(108px + var(--moving-level) * 28px - var(--stack-shift));
  z-index: 5;
}

.game-stack-the-box .stack-box--moving.is-perfect,
.game-stack-the-box .stack-box--moving.is-landed {
  animation: stack-box-drop 230ms ease-in both;
}

.game-stack-the-box .stack-box--moving.is-failed {
  animation: stack-box-fall 230ms ease-in both;
}

.game-stack-the-box .stack-feedback {
  position: absolute;
  z-index: 8;
  top: 88px;
  left: 50%;
  min-width: 76px;
  margin: 0;
  padding: 7px 13px;
  border: 2px solid #ffffff;
  border-radius: 999px;
  color: #ffffff;
  background: #17213a;
  box-shadow: 0 6px 0 rgba(9, 14, 28, 0.3);
  font-size: 11px;
  font-weight: 950;
  text-align: center;
  opacity: 0;
  transform: translateX(-50%) translateY(8px) scale(0.92);
  transition: opacity 100ms ease, transform 100ms ease;
  pointer-events: none;
}

.game-stack-the-box.is-perfect .stack-feedback,
.game-stack-the-box.is-landed .stack-feedback,
.game-stack-the-box.is-failed .stack-feedback {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
}

.game-stack-the-box.is-perfect .stack-feedback {
  color: #3b2b0c;
  background: var(--stack-gold);
}

.game-stack-the-box.is-landed .stack-feedback {
  background: var(--stack-teal);
}

.game-stack-the-box.is-failed .stack-feedback {
  background: var(--stack-red);
}

.game-stack-the-box.is-perfect .game-stage {
  box-shadow: inset 0 0 0 4px rgba(255, 212, 90, 0.64), inset 0 0 44px rgba(255, 212, 90, 0.18);
}

.game-stack-the-box.is-failed .game-stage {
  box-shadow: inset 0 0 0 4px rgba(230, 33, 41, 0.66), inset 0 0 46px rgba(230, 33, 41, 0.14);
}

.game-stack-the-box .game-overlay {
  z-index: 10;
  padding: 18px;
  background: rgba(14, 24, 43, 0.54);
  backdrop-filter: none;
}

.game-stack-the-box .game-overlay-panel {
  width: min(310px, 100%);
  padding: 18px 18px 19px;
  border: 4px solid #f2c75c;
  border-radius: 18px;
  color: var(--stack-navy);
  background:
    linear-gradient(90deg, rgba(30, 63, 91, 0.05) 1px, transparent 1px) 0 0 / 12px 12px,
    var(--stack-cream);
  box-shadow: 0 0 0 3px #273e5b, 0 9px 0 rgba(9, 17, 33, 0.5), 0 22px 38px rgba(5, 10, 22, 0.34);
}

.game-stack-the-box .game-overlay-panel h2 {
  margin: 7px 0 6px;
  color: var(--stack-navy);
  font-size: 27px;
  line-height: 1.05;
  text-shadow: none;
}

.game-stack-the-box .game-overlay-panel p {
  margin: 0 auto 14px;
  max-width: 244px;
  color: #43526a;
  font-size: 13px;
  font-weight: 750;
  line-height: 1.35;
}

.game-stack-the-box .stack-ready-badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border: 2px solid var(--stack-navy);
  border-radius: 999px;
  color: var(--stack-navy);
  background: var(--stack-gold);
  box-shadow: 0 3px 0 rgba(23, 33, 58, 0.32);
  font-size: 10px;
  font-weight: 950;
}

.game-stack-the-box .stack-ready-art {
  position: relative;
  width: 190px;
  height: 120px;
  margin: 7px auto 0;
}

.game-stack-the-box .stack-ready-guide {
  display: inline-flex;
  margin: -2px auto 4px;
  padding: 5px 10px;
  border: 2px solid var(--stack-ink);
  border-radius: 999px;
  color: var(--stack-ink);
  background: var(--stack-gold);
  font-size: 10px;
  font-weight: 1000;
  letter-spacing: 0.025em;
}

.game-stack-the-box .stack-ready-hook {
  position: absolute;
  z-index: 4;
  top: 0;
  left: 50%;
  width: 3px;
  height: 39px;
  background: #32475f;
  transform: translateX(-50%);
}

.game-stack-the-box .stack-ready-hook::after {
  position: absolute;
  bottom: -7px;
  left: -8px;
  width: 16px;
  height: 15px;
  border: 4px solid #d5982d;
  border-top: 0;
  border-radius: 0 0 11px 11px;
  content: "";
}

.game-stack-the-box .stack-ready-box {
  position: absolute;
  left: 50%;
  width: 92px;
  height: 28px;
  border: 3px solid #332517;
  border-radius: 6px;
  box-shadow: inset 0 4px 0 rgba(255, 255, 255, 0.3), 0 5px 0 rgba(51, 37, 23, 0.28);
}

.game-stack-the-box .stack-ready-box::after {
  position: absolute;
  top: -2px;
  bottom: -2px;
  left: 50%;
  width: 13px;
  background: #ffe092;
  content: "";
  transform: translateX(-50%);
}

.game-stack-the-box .stack-ready-box--one {
  bottom: 3px;
  background: var(--stack-red);
  transform: translateX(-50%);
}

.game-stack-the-box .stack-ready-box--two {
  bottom: 34px;
  background: var(--stack-teal);
  transform: translateX(-56%);
}

.game-stack-the-box .stack-ready-box--three {
  bottom: 65px;
  background: var(--stack-gold);
  transform: translateX(-42%);
}

.game-stack-the-box .stack-ready-drop {
  position: absolute;
  z-index: 5;
  top: 24px;
  right: 30px;
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 3px solid #ffffff;
  border-radius: 50%;
  color: #ffffff;
  background: var(--stack-red);
  box-shadow: 0 4px 0 rgba(99, 14, 21, 0.32);
  font-size: 22px;
  font-weight: 950;
  animation: stack-ready-drop 1.25s ease-in-out infinite;
}

.game-stack-the-box .countdown-value {
  color: var(--stack-gold);
  text-shadow: 0 0 22px rgba(255, 212, 90, 0.6), 0 5px 0 rgba(9, 17, 33, 0.38);
}

.game-stack-the-box.is-completing .game-stage {
  min-height: var(--game-stage-play-min-height);
}

@media (max-width: 360px) {
  .game-stack-the-box .game-hud-item {
    gap: 3px;
    padding-inline: 5px;
  }

  .game-stack-the-box .game-hud-label {
    font-size: 8px;
  }

  .game-stack-the-box .game-overlay {
    padding: 14px;
  }

  .game-stack-the-box .game-overlay-panel {
    padding: 15px 13px 17px;
  }

  .game-stack-the-box .stack-ready-art {
    height: 112px;
    transform: scale(0.92);
  }
}

@keyframes stack-box-settle {
  from { opacity: 0.65; transform: translateY(calc(var(--stack-shift) - 8px)) scale(1.03); }
  to { opacity: 1; transform: translateY(var(--stack-shift)) scale(1); }
}

@keyframes stack-box-drop {
  0% { transform: translateY(var(--stack-shift)); }
  70% { transform: translateY(calc(var(--stack-shift) + 46px)) scaleY(0.94); }
  100% { opacity: 0; transform: translateY(calc(var(--stack-shift) + 50px)) scaleY(0.9); }
}

@keyframes stack-box-fall {
  0% { opacity: 1; transform: translateY(var(--stack-shift)) rotate(0); }
  100% { opacity: 0; transform: translateY(calc(var(--stack-shift) + 150px)) rotate(22deg); }
}

@keyframes stack-ready-drop {
  0%, 65%, 100% { transform: translateY(-4px); }
  35% { transform: translateY(5px); }
}
