body.market-modal-open {
  overflow: hidden;
}

#market-modal {
  position: fixed;
  inset: 0;
  z-index: 1000006;
  display: none;
  font-family: 'Baloo 2', system-ui, sans-serif;
  color: #ffffff;
  --market-scale: 0.9; /* keep modal sizing constant */
  font-size: 16px;
}

#market-modal.is-visible {
  display: block;
}

#market-modal .market-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
}

#market-modal .market-modal__shell {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
  pointer-events: none;
}

#market-modal .market-modal__dialog {
  position: relative;
  width: min(420px, calc(100vw - 32px));
  max-width: 420px;
  min-width: 320px;
  max-height: min(720px, calc(100vh - 32px));
  background: rgba(18, 6, 41, 0.95);
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: calc(18px * var(--market-scale)) calc(16px * var(--market-scale)) calc(20px * var(--market-scale));
  box-shadow: 0 24px 42px rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  pointer-events: auto;
  overflow-y: auto;
  box-sizing: border-box;
  transform: scale(calc(0.94 * var(--market-scale)));
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

#market-modal.is-visible .market-modal__dialog {
  opacity: 1;
  transform: scale(var(--market-scale));
}

.market-modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.market-modal__header h2 {
  margin: 0;
  font-size: calc(28px * var(--market-scale));
  letter-spacing: 0.4px;
}

.market-modal__close {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  font-size: calc(13px * var(--market-scale));
  line-height: 1;
  cursor: pointer;
}

.market-modal__body {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.market-section {
  background: rgba(6, 2, 18, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  padding: calc(12px * var(--market-scale));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.market-section.actions {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

.market-section__hint {
  margin: 0 0 8px;
  font-size: calc(0.65 * 12px * 1.3 * var(--market-scale));
  color: rgba(244, 220, 255, 0.9);
  text-align: center;
}

.market-items {
  display: flex;
  flex-direction: column;
  gap: calc(8px * var(--market-scale));
}

.market-item {
  display: flex;
  align-items: center;
  gap: calc(8px * var(--market-scale));
  padding: calc(8px * var(--market-scale)) calc(9px * var(--market-scale));
  border-radius: 14px;
  background: rgba(10, 0, 26, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  flex-wrap: nowrap;
}

.market-item__icon {
  width: 70px;
  height: 70px;
  border-radius: 13px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(12px * var(--market-scale));
  color: #ffffff;
  flex-shrink: 0;
  letter-spacing: 0.8px;
}

.market-item__icon-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.market-item__text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.market-item__name {
  font-size: calc(12.5px * var(--market-scale));
}

.market-item__price {
  font-size: calc(10px * var(--market-scale));
  color: #f4dcff;
  opacity: 0.9;
}

.market-item__description {
  font-size: calc(9px * var(--market-scale));
  color: rgba(244, 220, 255, 0.85);
}

.market-item__action {
  flex-shrink: 0;
  flex: 0 0 clamp(120px, 28%, 180px);
  display: flex;
  justify-content: flex-end;
}

.market-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  border: none;
  border-radius: 11px;
  padding: calc(5px * var(--market-scale)) calc(8px * var(--market-scale));
  font-size: calc(9px * var(--market-scale));
  letter-spacing: 0.4px;
  font-family: 'Baloo 2', system-ui, sans-serif;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease, opacity 0.2s ease;
  width: 50%;
  max-width: 50%;
  color: #ffffff;
  align-self: stretch;
  min-width: 90px;
}

.market-btn:active {
  transform: scale(0.95);
}

#market-toast {
  position: fixed;
  top: 26px;
  left: 50%;
  transform: translate(-50%, -20px);
  opacity: 0;
  pointer-events: none;
  padding: 12px 20px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(6, 2, 18, 0.94);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-size: 14px;
  letter-spacing: 0.3px;
  text-align: center;
  color: #ffffff;
  z-index: 1000015;
  transition: opacity 0.18s ease, transform 0.18s ease;
  min-width: 220px;
}

#market-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

#market-toast[data-variant="error"] {
  background: rgba(122, 10, 40, 0.92);
  border-color: rgba(255, 154, 181, 0.65);
}

#market-toast[data-variant="success"] {
  background: rgba(6, 32, 18, 0.94);
  border-color: rgba(200, 255, 222, 0.65);
}

.market-btn.primary {
  background: linear-gradient(120deg, #4d9fff, #5dc1ff);
}

.market-btn.secondary {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.market-btn.ghost {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  flex: 0 0 auto;
  padding: calc(8px * var(--market-scale)) calc(12px * var(--market-scale));
}

@media (min-width: 520px) {
  #market-modal .market-modal__dialog {
    padding: 30px 32px 34px;
  }

  .market-section.actions {
    flex-direction: row;
  }
}

@media (max-height: 640px) {
  #market-modal .market-modal__dialog {
    align-self: flex-start;
    margin-top: 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #market-modal .market-modal__dialog,
  .market-btn {
    transition: none;
  }
}

@media (max-width: 640px) {
  #market-modal {
    --market-scale: 0.88;
  }

  #market-modal .market-modal__shell {
    padding: 0;
    align-items: stretch;
  }

  #market-modal .market-modal__dialog {
    width: 100vw;
    min-width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    border: none;
    padding: calc(22px + env(safe-area-inset-top, 0px)) 16px calc(26px + env(safe-area-inset-bottom, 0px));
    box-shadow: none;
    transform: translateY(24px);
  }

  #market-modal.is-visible .market-modal__dialog {
    transform: translateY(0);
  }

  .market-section {
    border-radius: 12px;
    padding: 12px;
  }

  .market-items {
    gap: 10px;
  }

  .market-item {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    text-align: left;
  }

  .market-item__icon {
    width: 56px;
    height: 56px;
  }

  .market-item__name {
    font-size: 14px;
  }

  .market-item__price {
    font-size: 12px;
  }

  .market-item__description {
    font-size: 11px;
  }

  .market-item__action {
    flex: 0 0 clamp(110px, 32%, 150px);
  }

  .market-btn {
    font-size: 9px;
    padding: 6px 8px;
    width: 60%;
    max-width: 60%;
    align-self: flex-end;
  }

  .market-section.actions {
    padding-top: 16px;
  }
}
