/* Inventory */
.inventory {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: linear-gradient(135deg, #1a3d2e 0%, #0f2a1f 100%);
  border: 3px solid rgba(255, 215, 0, 0.5);
  border-radius: 15px;
  padding: 1rem;
  min-width: 200px;
  max-width: 300px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6), 0 0 20px rgba(255, 215, 0, 0.3),
    inset 0 0 15px rgba(255, 215, 0, 0.1);
  z-index: 1000;
  animation: inventoryAppear 0.5s ease-out;
  backdrop-filter: blur(10px);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

.inventory:not(.expanded):hover {
  border-color: rgba(255, 215, 0, 0.8);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6), 0 0 30px rgba(255, 215, 0, 0.5),
    inset 0 0 15px rgba(255, 215, 0, 0.15);
  transform: translateY(-2px);
}

.inventory.expanded {
  cursor: default;
}

@keyframes inventoryAppear {
  0% {
    opacity: 0;
    transform: translateY(20px) scale(0.9);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.inventory-header {
  text-align: center;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid rgba(255, 215, 0, 0.3);
}

.inventory-header h3 {
  font-family: "Playfair Display", serif;
  font-size: 1.3rem;
  color: var(--primary-color);
  text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
  margin: 0;
  font-weight: 700;
}

.inventory-items-controls-wrapper {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.inventory-items {
  display: flex;
  flex-direction: row;
  gap: 0.75rem;
  padding: 0.5rem;
  flex-wrap: nowrap;
  justify-content: flex-start;
  border: 2px solid rgba(255, 215, 0, 0.3);
  border-radius: 8px;
  flex: 1 1 100%;
  min-width: 100%;
  width: 100%;
  box-sizing: border-box;
  overflow-x: auto;
  overflow-y: hidden;
}

.inventory-item {
  width: 60px;
  height: 60px;
  aspect-ratio: 1;
  background: rgba(13, 93, 46, 0.3);
  border: 2px solid rgba(255, 215, 0, 0.4);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3),
    inset 0 0 10px rgba(255, 215, 0, 0.1);
  animation: itemAdd 0.5s ease-out;
  flex-shrink: 0;
}

@keyframes itemAdd {
  0% {
    opacity: 0;
    transform: scale(0) rotate(-180deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
}

.inventory-item:hover {
  transform: scale(1.1) translateY(-3px);
  border-color: var(--primary-color);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4), 0 0 20px rgba(255, 215, 0, 0.4),
    inset 0 0 15px rgba(255, 215, 0, 0.2);
  background: rgba(13, 93, 46, 0.5);
}

.inventory-item::after {
  content: "";
  position: absolute;
  top: -2px;
  left: -2px;
  right: -2px;
  bottom: -2px;
  border-radius: 8px;
  background: linear-gradient(
    135deg,
    rgba(255, 215, 0, 0.3) 0%,
    transparent 50%,
    rgba(255, 215, 0, 0.3) 100%
  );
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: -1;
}

.inventory-item:hover::after {
  opacity: 1;
}

/* Envelope item in inventory */
.inventory-item.envelope-item {
  background: rgba(13, 93, 46, 0.3);
  border-color: rgba(255, 215, 0, 0.4);
}

.inventory-item.envelope-item:hover {
  background: rgba(13, 93, 46, 0.5);
  border-color: var(--primary-color);
}

/* Letter item in inventory */
.inventory-item.letter-item {
  background: rgba(13, 93, 46, 0.3);
  border-color: rgba(255, 215, 0, 0.4);
}

.inventory-item.letter-item:hover {
  background: rgba(13, 93, 46, 0.5);
  border-color: var(--primary-color);
}

/* Gift card item in inventory */
.inventory-item.gift-card-item {
  background: linear-gradient(
    135deg,
    var(--card-bg) 0%,
    rgba(13, 93, 46, 0.8) 100%
  );
  border-color: rgba(255, 215, 0, 0.6);
}

.inventory-item.gift-card-item:hover {
  background: linear-gradient(
    135deg,
    var(--card-bg) 0%,
    rgba(13, 93, 46, 0.9) 100%
  );
  border-color: var(--primary-color);
}

/* Expanded inventory state */
.inventory.expanded {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(90vw, 1000px);
  max-width: 90vw;
  min-width: 80vw;
  height: min(90vh, 900px);
  max-height: 900px;
  min-height: 60vh;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8), 0 0 40px rgba(255, 215, 0, 0.4),
    inset 0 0 30px rgba(255, 215, 0, 0.15);
  box-sizing: border-box;
}

.inventory.expanded .inventory-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.inventory.expanded .inventory-header h3 {
  margin: 0;
}

.inventory-close-button {
  background: transparent;
  border: 2px solid rgba(255, 215, 0, 0.5);
  border-radius: 50%;
  width: 2.5rem;
  height: 2.5rem;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.5rem;
  color: var(--primary-color);
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.inventory.expanded .inventory-close-button {
  display: flex;
}

.inventory-close-button:hover {
  background: rgba(255, 215, 0, 0.2);
  border-color: var(--primary-color);
  transform: scale(1.1);
}

/* Inventory display container */
.inventory-display {
  display: none;
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  border: 2px solid rgba(255, 215, 0, 0.3);
  margin-top: 1rem;
  position: relative;
  min-height: 0;
  width: 100%;
  box-sizing: border-box;
}

.inventory.expanded .inventory-display {
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto !important;
  min-height: 0;
  height: auto;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Keep inventory items visible when expanded - show as gallery at bottom */
.inventory.expanded .inventory-items-controls-wrapper {
  margin-top: 1rem;
  flex-shrink: 0;
}

.inventory.expanded .inventory-items {
  display: flex;
  flex-direction: row;
  gap: 0.75rem;
  padding: 1rem;
  border: 2px solid rgba(255, 215, 0, 0.3);
  border-radius: 8px;
  max-height: 120px;
  overflow-y: auto;
  flex-wrap: wrap;
  justify-content: flex-start;
}

/* Active state for selected item in gallery */
.inventory-item.active {
  border-color: var(--primary-color);
  border-width: 3px;
  box-shadow: 0 0 20px rgba(255, 215, 0, 0.8), 0 4px 12px rgba(0, 0, 0, 0.4),
    inset 0 0 20px rgba(255, 215, 0, 0.3);
  transform: scale(1.15);
  background: rgba(13, 93, 46, 0.7);
}

.inventory-item.active::after {
  opacity: 1;
}

/* Inventory controls */
.inventory-controls {
  display: flex;
  gap: 1rem;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
}

.inventory-flip-button,
.inventory-rotate-button,
.inventory-zoom-button {
  background: rgba(13, 93, 46, 0.5);
  border: 2px solid rgba(255, 215, 0, 0.5);
  border-radius: 50%;
  width: 3rem;
  height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.5rem;
  color: var(--primary-color);
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3),
    inset 0 0 10px rgba(255, 215, 0, 0.1);
}

.inventory-flip-button:hover,
.inventory-rotate-button:hover,
.inventory-zoom-button:hover {
  background: rgba(13, 93, 46, 0.7);
  border-color: var(--primary-color);
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4), 0 0 20px rgba(255, 215, 0, 0.4),
    inset 0 0 15px rgba(255, 215, 0, 0.2);
}

.inventory-flip-button:active,
.inventory-rotate-button:active,
.inventory-zoom-button:active {
  transform: scale(0.95);
}

/* Envelope display in inventory */
.inventory-display .envelope-container {
  position: relative !important;
  max-width: 100%;
  width: 100%;
  margin: 1rem auto;
  padding: 0;
  min-height: 0;
  height: auto;
  perspective: 1000px;
  --rotation-scale: 2;
  --rotation-angle: 0deg;
  transform: scale(var(--rotation-scale)) rotate(var(--rotation-angle)) !important;
  transform-origin: center center;
  transition: transform 0.3s ease;
  display: flex !important;
  align-items: center;
  justify-content: center;
  z-index: 5;
}

/* Override envelope-clone-reset transform for inventory */
.inventory-display .envelope-container.envelope-clone-reset {
  transform: scale(var(--rotation-scale)) rotate(var(--rotation-angle)) !important;
}

.inventory-display .envelope {
  max-width: 100%;
  margin: 0 auto;
  position: relative !important;
  width: 100% !important;
  max-width: 500px !important;
  min-width: 300px;
  transform-style: preserve-3d;
}

.inventory-display .envelope-front {
  max-width: 100%;
  position: relative;
  width: 100% !important;
  opacity: 1 !important;
  visibility: visible !important;
  backface-visibility: hidden;
  transform-style: preserve-3d;
}

.inventory-display .envelope-back {
  max-width: 100% !important;
  position: absolute !important;
  width: 100% !important;
  max-width: 500px !important;
  top: 50% !important;
  left: 50% !important;
  /* Initial state - animation will override this */
  transform: translate(-50%, -50%) rotate(1deg) rotateY(-90deg);
  opacity: 0;
  pointer-events: none;
  visibility: visible !important;
  z-index: 1;
  margin: 0 !important;
  right: auto !important;
  bottom: auto !important;
  backface-visibility: hidden;
  transform-style: preserve-3d;
}

.inventory-display .envelope-back.envelope-back-reset {
  opacity: 0 !important;
  pointer-events: none !important;
  transform: translate(-50%, -50%) rotate(1deg) rotateY(-90deg) !important;
  top: 50% !important;
  left: 50% !important;
  position: absolute !important;
  margin: 0 !important;
}

/* Override reset when visible - allow animation to work */
.inventory-display .envelope-back.envelope-back-reset.visible,
.inventory-display .envelope-back.envelope-back-reset.envelope-back-visible {
  opacity: 1 !important;
  pointer-events: auto !important;
  z-index: 2 !important;
  /* Don't use transform: unset - let animation control transform */
  animation: envelopeBackFlip 0.8s ease-in-out forwards !important;
  animation-delay: 0.4s !important;
}

.inventory-display .envelope-front.envelope-front-reset {
  opacity: 1 !important;
  visibility: visible !important;
  display: block !important;
  width: 100% !important;
  transform: rotate(-1deg) rotateY(0deg) !important;
  animation: none !important;
}

/* Allow flip animations to override reset classes - match working envelope.css */
.inventory-display .envelope-front.flipping {
  animation: envelopeFlip 0.8s ease-in-out forwards !important;
  /* Lower z-index so back can show through as it flips */
  z-index: 0 !important;
}

.inventory-display .envelope-front.flipping-back {
  animation: envelopeFrontFlipBack 0.8s ease-in-out forwards !important;
  animation-delay: 0.4s !important;
  transform: rotate(-1deg) rotateY(90deg);
}

.inventory-display .envelope-back.flipping-back {
  animation: envelopeFlipBack 0.8s ease-in-out forwards !important;
}

/* Override animation: none from envelope-back-visible class in components.css */
/* Must have higher specificity than .envelope-back-visible in components.css */
.inventory-display .envelope-back.visible.envelope-back-visible {
  /* Override the animation: none from components.css - this must come after components.css loads */
  animation: envelopeBackFlip 0.8s ease-in-out forwards !important;
  animation-delay: 0.4s !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  z-index: 2 !important;
  visibility: visible !important;
  /* Don't set transform with !important - let animation control it */
}

.inventory-display .envelope-back.envelope-back-visible {
  /* Override animation: none from components.css when used alone in inventory */
  animation: envelopeBackFlip 0.8s ease-in-out forwards !important;
  animation-delay: 0.4s !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  z-index: 2 !important;
  visibility: visible !important;
  /* Don't set transform with !important - let animation control it */
}

.inventory-display .envelope-back.visible {
  opacity: 1 !important;
  pointer-events: auto !important;
  z-index: 2 !important;
  animation: envelopeBackFlip 0.8s ease-in-out forwards !important;
  animation-delay: 0.4s !important;
  /* Don't set transform with !important - let animation control it */
  /* Animation will start from -90deg and rotate to 0deg */
  visibility: visible !important;
}

.inventory-display .envelope-front.envelope-front-hidden {
  transform: rotate(-1deg) rotateY(90deg) !important;
  transition: opacity 0.3s ease, transform 0.8s ease !important;
}

.inventory-display .envelope-front.hidden {
  opacity: 0 !important;
  pointer-events: none !important;
}

.inventory-display .envelope-body {
  width: 100% !important;
  height: 0 !important;
  padding-bottom: 60% !important;
  position: relative;
}

/* Tighter typography for envelope in inventory */
.inventory-display .envelope-body .main-title {
  font-size: 1.2rem !important;
}

.inventory-display .envelope-receiver .address-label,
.inventory-display .envelope-sender .address-label {
  font-size: 0.9rem !important;
}

.inventory-display .envelope-receiver .address-name {
  font-size: 1.6rem !important;
}

.inventory-display .envelope-sender .address-name {
  font-size: 1.3rem !important;
}

/* Smaller stamp in inventory */
.inventory-display .envelope-stamp {
  width: 70px !important;
  height: 70px !important;
  font-size: 2.8rem !important;
}

/* Message section with card in inventory */
.inventory-display .message-section {
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
  width: 100%;
  max-width: 100%;
  padding: 1rem;
}

.inventory-display .message-section .card {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(5deg);
  z-index: 100;
  pointer-events: auto;
}

/* Hide gift card when viewing letter in inventory */
.inventory-display .message-section.letter-clone-reset #gift-card {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
}

/* Gift card display in inventory - should look same as outside */
.inventory-display .card {
  /* Maintain aspect ratio and structure from base .card styles */
  position: relative !important;
  max-width: 500px;
  width: 100%;
  margin: auto;
  aspect-ratio: 1.586 / 1 !important; /* Credit card aspect ratio */
  padding: 2.5rem !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden;
  height: auto;
  align-self: center;
}

.inventory-display .card .card-content {
  /* margin-top: auto is inherited from base .card-content */
  /* This pushes content to bottom of card */
  position: static;
  margin-top: auto;
}

.inventory-display .card .card-logo {
  /* Match base card-logo position exactly - same as outside inventory */
  position: absolute !important;
  top: 1rem !important;
  right: 1rem !important;
  font-size: 2.5rem;
  z-index: 3;
}

.inventory-flip-button-wrapper {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 1000;
  pointer-events: auto;
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: flex-end;
}

.inventory-visible {
  display: flex !important;
  flex-direction: column;
}

.inventory-visible-flex {
  display: flex !important;
}

.inventory-hidden {
  display: none !important;
}

.inventory-controls-visible {
  display: flex !important;
}

.inventory-controls-hidden {
  display: none !important;
}

.flip-button-visible {
  display: flex !important;
}

.flip-button-hidden {
  display: none !important;
}

.inventory-rotation {
  transform: scale(var(--rotation-scale, 0.7))
    rotate(var(--rotation-angle, 0deg)) !important;
}
