
.chest {
  position: relative;
  display: inline-block;
  width: 30px;
  height: 24px;
  background: url("../art/ui/capsule.webp") center / contain no-repeat;
}

.chest::after { content: none; }

.fly-chest {
  position: fixed;
  z-index: 16;
}

.deal {
  --deal-label-bg: #201128;
  --deal-prize-shade: linear-gradient(#1c1024b3, #1c1024b3);
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  justify-content: center;
  background: var(--bg-deep);
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition: opacity 250ms ease, visibility 0s linear 250ms;
}

#app.under-deal *,
#app.under-deal *::before,
#app.under-deal *::after {
  animation-play-state: paused;
}

.deal.open {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
  transition: opacity 250ms ease, visibility 0s;
}

.deal:not(.open) .deal-panel::before,
.deal:not(.open) .deal-panel::after {
  animation: none;
}

.deal-panel {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 520px;
  height: 100%;
  padding: max(10px, var(--safe-top)) 12px max(12px, calc(var(--safe-bottom) + 2px));
  gap: 7px;
  background:
    linear-gradient(180deg, #10051d66, #10051dcc),
    url("../art/ui/voyage-background.webp") center / cover no-repeat;
  background-color: var(--bg-deep);
}

.deal-title {
  position: relative;
  align-self: center;
  padding: 4px 34px 6px;
  font-size: clamp(1.3rem, 6.4vw, 1.8rem);
  font-weight: 900;
  font-style: italic;
  letter-spacing: 0.02em;
  text-align: center;
  white-space: nowrap;
  background-color: var(--red);
  background-image: var(--gold-bevel), linear-gradient(180deg, #c44be9, var(--red) 50%, #3c095a);
  -webkit-background-clip: text, border-box;
  background-clip: text, border-box;
  clip-path: polygon(0 0, 100% 0, 94% 50%, 100% 100%, 0 100%, 6% 50%);
}

.deal-panel::before,
.deal-panel::after {
  content: "✦";
  color: var(--gold-light);
  position: absolute;
  top: calc(max(10px, var(--safe-top)) + 40px);
  font-size: 2rem;
  filter: drop-shadow(0 0 10px rgba(255, 80, 40, 0.8));
  animation: lantern 2400ms ease-in-out infinite alternate;
  transform-origin: 50% 0;
}

.deal-panel::before { left: max(8px, calc(50% - 250px)); }
.deal-panel::after { right: max(8px, calc(50% - 250px)); animation-delay: -1200ms; }

.deal-base {
  align-self: center;
  padding: 2px 18px;
  border-radius: 6px;
  background: linear-gradient(180deg, #000, #1a1240);
  border: 2px solid var(--gold-dark);
  color: var(--jade);
  font-family: var(--display);
  font-size: 0.8rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-align: center;
  text-transform: uppercase;
}

.deal-base strong {
  margin-left: 4px;
  color: #fff;
  font-size: 1.05rem;
}

.deal-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}

.deal-board {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: grid;
  grid-template-columns: 64px 64px;
  grid-template-rows: repeat(12, 1fr);
  grid-auto-flow: column;
  justify-content: space-between;
  align-content: stretch;
  gap: 3px 0;
  padding: 6px 5px;
  pointer-events: none;
}

.deal-board::before,
.deal-board::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: -1;
  width: 74px;
  background: url("../art/ui/bargain-rail.webp") center / 100% 100% no-repeat;
}

.deal-board::before { left: 0; }
.deal-board::after { right: 0; }

.deal-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  border-radius: 5px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.35), transparent 50%),
    linear-gradient(180deg, #2fd47a, #0b6a36);
  border: 1px solid var(--gold-light);
  box-shadow: 0 0 0 1px var(--gold-deep), 0 1px 2px rgba(0, 0, 0, 0.5);
  color: #fff;
  font-family: var(--display);
  font-size: 0.76rem;
  font-weight: 900;
  text-align: center;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.7);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity 300ms ease, filter 300ms ease;
}

.deal-pill:nth-child(n + 13) {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.35), transparent 50%),
    linear-gradient(180deg, #3b8bff, #12347a);
}

.deal-pill.high {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.4), transparent 50%),
    linear-gradient(180deg, #ff5ad0, #a0107a);
}

.deal-pill.out {
  background: linear-gradient(180deg, #3a2a50, #1a1030);
  border-color: var(--gold-deep);
  color: rgba(255, 255, 255, 0.4);
  text-decoration: line-through;
}

.deal-boosts {
  min-height: 1.2em;
  color: var(--jade);
  font-family: var(--display);
  font-size: 0.85rem;
  font-weight: 900;
  text-align: center;
  text-shadow: 0 0 8px rgba(47, 212, 122, 0.6);
}

.deal-prompt {
  color: #fff;
  font-family: var(--display);
  font-size: 1.1rem;
  font-weight: 900;
  text-align: center;
  text-shadow: 0 2px 0 #000, 0 0 10px rgba(255, 90, 70, 0.8);
}

.deal-prompt.result {
  align-self: center;
  padding: 2px 18px;
  border: 2px solid var(--gold-dark);
  border-radius: 6px;
  background: var(--deal-label-bg);
  color: var(--gold-light);
  font-size: clamp(2rem, 8vw, 2.4rem);
  font-weight: 400;
  line-height: 1;
  white-space: nowrap;
}

.deal-chests {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(8, minmax(0, 58px));
  align-content: center;
  gap: 2px 0;
  margin: 0 80px;
  padding: 4px 0;
  border-radius: 6px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.35), rgba(0, 0, 0, 0.15));
}

.deal-chest {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 1px;
  min-height: 0;
  padding: 2px 0 7px;
  background: url("../art/drawn/deal-shelf.svg") center bottom -3px / 100% 12px no-repeat;
}

.deal-chest .chest {
  flex: none;
  width: min(94%, 66px);
  height: min(48px, 100%);
  background-size: 100% 100%;
  isolation: isolate;
}

.deal-chest:not(:disabled):active .chest {
  transform: scale(0.92);
}

.deal-chest-label {
  position: absolute;
  bottom: min(14px, calc((100% - 7px) / 4));
  left: 50%;
  transform: translateX(-50%);
  min-width: 18px;
  padding: 0 3px;
  border-radius: 9px;
  background: #28000a;
  color: var(--gold-light);
  font-family: var(--display);
  font-size: 0.78rem;
  line-height: 15px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.deal-chest:disabled {
  cursor: default;
}

.deal.open.finished .deal-chest:disabled { pointer-events: none; }

.deal:has(.deal-round.show) .deal-prompt { opacity: 0; }

.deal-chest.mine .deal-chest-label {
  background: var(--deal-label-bg);
  color: var(--gold-light);
  font-size: 12px;
  bottom: 14px;
}

.deal-chest.mine:not(.opened) .chest {
  visibility: hidden;
}

.deal-mine {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 0 auto;
  padding: 6px 22px 6px 16px;
  border-radius: 14px 14px 6px 6px;
  border: 2px solid var(--gold);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.25), transparent 50%),
    linear-gradient(180deg, #a020a0, #4a0a6a);
  box-shadow: 0 0 0 1px var(--gold-deep), 0 6px 0 #2a0638, 0 0 18px rgba(255, 79, 216, 0.45);
  visibility: hidden;
}

.deal-mine.show {
  visibility: visible;
}

.deal-mine .chest {
  width: 46px;
  height: 36px;
  filter: drop-shadow(0 0 7px var(--gold));
}

.deal-mine.arriving .chest {
  visibility: hidden;
}

.deal-mine.landed {
  animation: chest-pop 500ms cubic-bezier(0.2, 1.6, 0.4, 1);
}

.deal-mine.opened .chest {
  filter: brightness(1.4);
}

.deal-mine-text {
  font-size: 1rem;
  font-weight: 900;
  letter-spacing: 0.06em;
}

.deal-mine-text strong {
  display: block;
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
}

.fly-chest.pick {
  z-index: 46;
  transform-origin: top left;
  filter: drop-shadow(0 0 8px var(--gold));
}

.deal-round {
  position: absolute;
  left: 50%;
  top: 54%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  --deal-round-w: min(90vw, 360px);
  width: var(--deal-round-w);
  aspect-ratio: 744 / 454;
  padding: calc(var(--deal-round-w) * 0.259) calc(var(--deal-round-w) * 0.1) calc(var(--deal-round-w) * 0.035);
  background: url("../art/deal-round/board.webp") center / 100% 100% no-repeat;
  filter: drop-shadow(0 12px 18px rgba(0, 0, 0, 0.7));
  text-align: center;
  transform: translate(-50%, -50%) scale(0);
  opacity: 0;
  pointer-events: none;
}

.deal-round::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 96.5%;
  width: 13%;
  aspect-ratio: 1;
  background: url("../art/nebula-empress/star-crystal.webp") center / contain no-repeat;
  transform: translateX(-50%);
}

.deal-chest.opening,
.deal-mine.opening .chest {
  animation: chest-rattle 110ms ease-in-out infinite alternate;
  filter: brightness(1.3);
}

.deal-chest.chosen {
  animation: chest-chosen 300ms ease-in-out infinite alternate;
}

.deal-board.boosted {
  animation: board-boost 800ms ease-out;
}

.deal-intro.show {
  pointer-events: auto;
}

.deal-round.show {
  animation: deal-round 1800ms ease forwards;
}

.deal-round-title {
  position: relative;
  margin: 0;
  color: #f6d6ff;
  font-family: var(--display);
  font-size: 1.1rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-shadow: 0 0 8px var(--magenta);
}

.deal-round-main {
  color: #fff;
  font-family: var(--display);
  font-size: clamp(1.8rem, 9vw, 2.4rem);
  font-weight: 900;
  line-height: 1.05;
  text-shadow: 0 3px 0 #000;
}

.deal-round-sub {
  font-size: 1.2rem;
  font-weight: 900;
  text-transform: uppercase;
}

.deal-chest.opening .chest,
.deal-mine.opening .chest,
.deal-chest.opened .chest,
.deal-mine.opened .chest {
  background-image: url("../art/ui/capsule-opening.webp");
  background-size: 400% 100%;
  background-position: 100% 0;
}
.deal-chest.opening .chest,
.deal-mine.opening .chest {
  animation: capsule-open-frames var(--capsule-open-ms, 550ms) steps(3, end) both;
}
.deal-mine.peeking .chest {
  animation: capsule-open-frames 380ms steps(3, end) both;
}
.deal-mine.peeking .deal-mine-text strong {
  animation: chest-pop 380ms cubic-bezier(0.2, 1.6, 0.4, 1);
}
.deal-chest.final-other .chest {
  filter: drop-shadow(0 0 8px var(--gold-light));
  animation: final-other-pulse 900ms ease-in-out infinite alternate;
}
body.scene-motion-paused .deal-chest.final-other .chest,
body.destination-active .deal-chest.final-other .chest {
  animation-play-state: paused;
}
.deal-chest.opened .chest { opacity: 0.65; }
.deal-chest.unchosen .chest { opacity: 0.45; filter: saturate(0.6); }
@keyframes capsule-open-frames {
  from { background-position: 0% 0; }
  to { background-position: 100% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .deal-chest.opening .chest,
  .deal-mine.opening .chest,
  .deal-mine.peeking .chest { animation: none; background-position: 100% 0; }
  .deal-mine.peeking .deal-mine-text strong,
  .deal-chest.final-other .chest { animation: none; transform: none; }
}

.deal-chest[data-ladder="green"] { --deal-prize-art: url("../art/ui/prize-plaque-green.webp"); --deal-prize-glow: #2fd47a; }
.deal-chest[data-ladder="blue"] { --deal-prize-art: url("../art/ui/prize-plaque-blue.webp"); --deal-prize-glow: #3b8bff; }
.deal-chest[data-ladder="high"] { --deal-prize-art: url("../art/ui/prize-plaque-magenta.webp"); --deal-prize-glow: #ff5ad0; }

.deal-chest.opened .deal-chest-label,
.deal-chest.mine.opened .deal-chest-label {
  top: auto;
  bottom: calc(7px + min(24px, (100% - 9px) / 2));
  transform: translate(-50%, 50%);
  padding: 3px 6px 2px;
  border-radius: 0;
  background:
    var(--deal-prize-shade) center / calc(100% - 6px) calc(100% - 4px) no-repeat,
    var(--deal-prize-art) center / 100% 100% no-repeat;
  color: #fff9cb;
  font-size: 17px;
  font-weight: 400;
  line-height: 1;
  text-shadow: 0 1px 1px #000, 0 0 2px #000;
}

.float-text.deal-prize {
  color: #fff9cb;
  font-size: 22px;
  text-shadow: 0 1px 1px #000, 0 0 2px #000, 0 0 10px var(--deal-prize-glow, var(--gold));
  animation: deal-prize-stamp 700ms ease-out forwards;
}

@keyframes deal-prize-stamp {
  from { opacity: 0; transform: translate(-50%, -50%) scale(1.6); }
  25% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  to { opacity: 0; transform: translate(-50%, -50%) scale(1.25); }
}

@media (prefers-reduced-motion: reduce) {
  .float-text.deal-prize { animation-duration: 1ms; }
}

.deal-chest.popping {
  animation: chest-pop 500ms cubic-bezier(0.2, 1.6, 0.4, 1);
}

