/* ========================================
   LAYOUT & CONTAINER
   ======================================== */
.nft-marketplace {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

.marketplace-header {
    text-align: center;
    margin-bottom: 3rem;
}

.marketplace-header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--primary-color), #667eea);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.marketplace-subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.nft-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 2rem;
    margin-top: 2rem;
    container-type: inline-size;
}

/* ========================================
   NFT CARD
   ======================================== */
.nft-card {
    background: var(--bg-glass, rgba(241, 243, 244, 0.5));
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(93, 93, 93, 0.2);
    border-radius: var(--border-radius, 16px);
    padding: 0;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    animation: fadeInUp 0.6s ease-out forwards;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    min-width: 0;
    container-type: inline-size;
}

.nft-grid .nft-card {
    padding: 0.5rem;
}

.nft-listing-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 15px;
    background: var(--bg-glass);
    border-top-left-radius: 16px!important;
    border-top-right-radius: 16px!important;
    border-bottom: 1px solid rgba(29, 155, 255, 0.2);
    font-size: 0.6rem;
    color: var(--text-secondary);
    line-height: 1.2;
    margin-bottom: 0.5rem;
    border-radius: 5px;
    flex-wrap: nowrap;
    min-width: 0;
}

.nft-listing-info-left {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    flex: 1;
    order: 1;
}

.nft-listing-icon {
    color: rgba(29, 155, 255, 0.8);
    flex-shrink: 0;
    width: 16px;
    height: 16px;
}

.nft-listing-text {
    font-weight: 500;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex-shrink: 1;
}

.nft-serial-number {
    cursor: pointer;
    user-select: none;
    transition: opacity 0.2s ease;
}

.nft-serial-number:hover {
    opacity: 0.8;
    text-decoration: underline;
}

.nft-listing-timestamp {
    color: var(--text-muted);
    font-size: 12px;
    white-space: nowrap;
    margin-left: auto;
    order: 2;
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Dark mode styles for listing header */
html.dark .nft-listing-header,
html[data-theme="dark"] .nft-listing-header {
    background: rgba(29, 155, 255, 0.15);
    border-bottom: 1px solid rgba(29, 155, 255, 0.3);
}

html.dark .nft-listing-icon,
html[data-theme="dark"] .nft-listing-icon {
    color: rgba(96, 165, 250, 0.9);
}

html.dark .nft-listing-text,
html[data-theme="dark"] .nft-listing-text {
    color: rgba(96, 165, 250, 1);
}

.nft-card > .nft-image-container,
.nft-card > .nft-info,
.nft-card > .nft-footer {
    padding: 0 1.5rem;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

.nft-card > .nft-image-container {
    padding-top: 1.5rem;
    padding-bottom: 1rem;
    margin: 0;
}

.nft-card > .nft-footer {
    padding-bottom: 1.5rem;
    margin-top: auto;
}

/* Hover Shine Effect */
.nft-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(29, 155, 255, 0.1), transparent);
    transition: left 0.6s ease;
    pointer-events: none;
    z-index: 1;
}

.nft-card:hover::before {
    left: 100%;
}

.nft-card:hover {
    transform: translateY(-8px);
    border-color: var(--primary-color);
    box-shadow: 0 12px 32px rgba(29, 155, 255, 0.2);
}

/* ========================================
   RESPONSIVE SVG IMAGE — FINAL FIX
   ======================================== */
.nft-image-container {
    width: 100%;
    margin: 0 auto;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-grow: 0;
    flex-shrink: 0;
    min-height: 200px;
    aspect-ratio: 1 / 1; /* Forces square */
    overflow: hidden;
    max-width: 400px;
    max-height: 400px;
}

.nft-card .nft-image-container {
    margin: 0 auto;
}

/* SVG is injected directly — no .svg-wrapper needed */
.nft-image-container svg {
    width: 100% !important;
    height: 100% !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-width: 100% !important;
    max-height: 100% !important;
    display: block;
    object-fit: contain;
    border-radius: 8px;
}

/* SVG is injected directly — no .svg-wrapper needed */
.nft-image-container img {
    width: 100% !important;
    height: 100% !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-width: 100% !important;
    max-height: 100% !important;
    display: block;
    object-fit: contain;
    border-radius: 8px;
}

/* Images inside SVG (for JPG/PNG embedded in SVG) - viewBox handles scaling */
.nft-image-container svg image {
    /* SVG viewBox and preserveAspectRatio handle the scaling */
}

/* Optional: Debug borders (REMOVE IN PRODUCTION) */
/*
.nft-image-container { border: 3px solid red; }
.nft-image-container svg { border: 3px solid lime; }
*/

/* ========================================
   INFO & FOOTER
   ======================================== */
.nft-note {
    font-size: 0.9rem;
    text-align: left;
    color: var(--text-primary);
    margin: 0;
    padding: 12px;
    background: var(--bg-glass);
    border-radius: 6px;
    border-left: 4px solid #007bff;
}

.nft-info {
    margin: 1rem 0;
    flex-grow: 0;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.nft-name {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    min-height: 3em;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nft-description {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    line-height: 1.5;
}

.nft-footer {
    display: flex;
    flex-direction: column;
    gap: 0.7em;
    padding: 0;
    min-height: auto;
    width: 100%;
    box-sizing: border-box;
}
.nft-footer-row { 
    display: flex; 
    width: 100%; 
    justify-content: space-between; 
    align-items: center; 
    gap: clamp(0.3em, 1.5vw, 0.6em); 
    flex-wrap: wrap;
    min-width: 0;
    font-size: clamp(0.75rem, 2.5vw, 1rem);
}
.nft-footer-row .qty-label, .nft-footer-row .qty-value { 
    font-size: 1em; 
    font-weight: 600; 
    min-width: 0;
    flex: 0 1 auto;
    white-space: nowrap;
}
.nft-footer .nft-price { 
    margin-left: 0; 
    min-width: 0;
    flex: 0 1 auto;
    font-size: 1em;
    white-space: nowrap;
}
.nft-genesis-label {
    font-size: 1em;
    font-weight: 700;
    color: var(--primary-color);
    white-space: nowrap;
    min-width: 0;
    flex: 0 1 auto;
}
.nft-qtyprice {
    display: flex;
    align-items: center;
    gap: 0.4em;
}

.nft-quantity {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0;
    background: none;
    border-radius: 0;
    font-size: 0.93rem;
    color: var(--text-primary);
}
.nft-quantity .qty-label,
.nft-quantity .qty-value {
    font-size: 0.93rem;
    font-weight: 500;
    margin: 0 0.1em;
    color: var(--primary-color);
}
.nft-price { margin-left: 1.1em; font-size: 1em; font-weight: 700; }

/* ========================================
   PURCHASE BUTTON
   ======================================== */
.purchase-btn {
    position: static;
    margin-left: clamp(0.3em, 1.5vw, 0.7em);
    font-size: clamp(0.7rem, 2.2vw, 0.93rem);
    padding: clamp(0.4rem, 1.2vw, 0.6rem) clamp(0.8em, 2.5vw, 1.2em);
    min-width: clamp(60px, 15vw, 80px);
    flex-shrink: 1;
    width: auto;
    max-width: 100%;
    background: var(--button-primary, #1d9bff);
    color: #fff;
    border: none;
    border-radius: var(--border-radius);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(29, 155, 255, 0.3);
    white-space: nowrap;
    z-index: 10;
}

.purchase-btn:hover:not(:disabled) {
    background: var(--button-primary-hover, #0d8bef);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(29, 155, 255, 0.4);
}

.purchase-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.purchase-btn.loading {
    pointer-events: none;
}

.purchase-btn.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin: -8px;
    border: 2px solid #fff;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.claim-btn {
    position: static;
    margin-left: clamp(0.3em, 1.5vw, 0.7em);
    font-size: clamp(0.7rem, 2.2vw, 0.93rem);
    padding: clamp(0.4rem, 1.2vw, 0.6rem) clamp(0.8em, 2.5vw, 1.2em);
    min-width: clamp(60px, 15vw, 80px);
    flex-shrink: 1;
    width: auto;
    max-width: 100%;
    background: var(--button-primary, #1d9bff);
    color: #fff;
    border: none;
    border-radius: var(--border-radius);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(29, 155, 255, 0.3);
    white-space: nowrap;
    z-index: 10;
}

.claim-btn:hover:not(:disabled) {
    background: var(--button-primary-hover, #0d8bef);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(29, 155, 255, 0.4);
}

.claim-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.claim-btn.loading {
    pointer-events: none;
}

.claim-btn.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin: -8px;
    border: 2px solid #fff;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.claim-disabled {
    margin-left: 0.7em;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-style: italic;
    white-space: nowrap;
}

.owned-badge {
    font-size: 0.85em;
    font-weight: 600;
    color: var(--primary-color);
    white-space: nowrap;
    padding: 0.2rem 0.5rem;
    background: rgba(29, 155, 255, 0.1);
    border-radius: 4px;
}

@media (max-width: 600px) {
    .claim-btn {
        width: 100%;
        margin-left: 0;
    }
    .nft-footer-row .claim-btn { width: 100%; margin:0.8em 0 0 0; order: 2; }
}

.sold-out {
    position: absolute;
    top: 1rem;
    right: 1rem;
    padding: 0.5rem 1rem;
    background: rgba(255, 0, 0, 0.1);
    color: #ff4444;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    z-index: 10;
    pointer-events: none;
}

/* ========================================
   ANIMATIONS
   ======================================== */
.star { 
    animation: twinkle linear infinite;
    transform-origin: center;
}
.s1 { animation-delay: 0s; animation-duration: 2.3s; }
.s2 { animation-delay: 0.4s; animation-duration: 3.1s; }
.s3 { animation-delay: 0.8s; animation-duration: 2.7s; }
.s4 { animation-delay: 1.2s; animation-duration: 3.4s; }
.s5 { animation-delay: 0.6s; animation-duration: 2.9s; }
.s6 { animation-delay: 1.0s; animation-duration: 3.2s; }
.s7 { animation-delay: 1.4s; animation-duration: 2.5s; }
.s8 { animation-delay: 0.2s; animation-duration: 3.6s; }

@keyframes twinkle {
    0%, 100% { opacity: 0.3; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.5); }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ========================================
   RESPONSIVE BREAKPOINTS
   ======================================== */
/* Responsive text sizing for multiple NFT columns - scales with container */
@media (min-width: 769px) {
    .nft-grid .nft-footer-row {
        font-size: clamp(0.7rem, 1.5vw, 0.9rem);
    }
}

@media (min-width: 1025px) {
    .nft-grid .nft-footer-row {
        font-size: clamp(0.65rem, 1.2vw, 0.85rem);
    }
}

@media (max-width: 600px) {
    .nft-listing-header {
        font-size: 0.65rem;
        padding: 0.5rem 10px;
    }
    
    .nft-listing-text {
        font-size: 0.65rem;
    }
    
    .nft-listing-timestamp {
        font-size: 10px;
    }
    
    .nft-footer {
        flex-direction: column;
        align-items: stretch;
        gap: 0.7em;
    }
    .nft-footer-row {
        font-size: 1em;
        width: 100%;
        justify-content: space-between;
        flex-wrap: nowrap;
    }
    .purchase-btn, .claim-btn {
        width: auto;
        min-width: 100px;
        margin-left: 0;
    }
    .nft-qtyprice {
        justify-content: flex-start;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .nft-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
    .nft-image-container { padding: 0.5rem; }
    .nft-name { font-size: 1.1rem; }
    .nft-price { font-size: 1rem; }
}

.nft-footer-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  gap: 0.6em;
  flex-wrap: nowrap;
}
.nft-footer-row .nft-left {
  display: flex;
  align-items: center;
  gap: clamp(0.2em, 1vw, 0.4em);
  font-weight: 600;
  white-space: nowrap;
  min-width: 0;
  flex: 0 1 auto;
  font-size: 1em;
}
.nft-footer-row .nft-price {
  font-size: 1em;
  font-weight: 700;
  white-space: nowrap;
  min-width: 0;
  flex: 0 1 auto;
}
.nft-footer-row .nft-genesis-label {
  flex: 0 1 auto;
  min-width: 0;
}
.nft-footer-row .purchase-btn,
.nft-footer-row .claim-btn {
  min-width: clamp(60px, 15vw, 80px);
  width: auto;
  max-width: 100%;
  margin-left: auto;
  white-space: nowrap;
  flex: 0 0 auto;
  flex-basis: clamp(60px, 20%, 120px);
  font-size: 1em;
  padding: clamp(0.4rem, 1.2vw, 0.6rem) clamp(0.8em, 2.5vw, 1.2em);
  order: 10;
}

/* Fallback for browsers without container query support - use flex-basis to control wrapping */
.nft-footer-row .nft-left,
.nft-footer-row .nft-price {
  flex-basis: auto;
  min-width: fit-content;
}
/* When container is too narrow, stack button on new line */
@container (max-width: 320px) {
  .nft-footer-row {
    flex-wrap: wrap;
    gap: 0.5em;
  }
  .nft-footer-row .nft-left {
    flex: 0 0 auto;
    order: 1;
  }
  .nft-footer-row .nft-price {
    flex: 0 0 auto;
    margin-left: auto;
    order: 2;
  }
  .nft-footer-row .nft-genesis-label {
    flex: 0 0 auto;
    order: 1;
  }
  .nft-footer-row .purchase-btn,
  .nft-footer-row .claim-btn {
    width: 100%;
    margin-left: 0;
    order: 10;
    flex-basis: 100%;
  }
}

@media (max-width:600px) {
  .nft-footer-row {
    gap: 0.5em;
  }
  /* Only wrap on very small screens */
  @container (max-width: 280px) {
    .nft-footer-row {
      flex-wrap: wrap;
    }
    .nft-footer-row .nft-left {
      flex: 0 0 auto;
      order: 1;
    }
    .nft-footer-row .nft-price {
      flex: 0 0 auto;
      margin-left: auto;
      order: 2;
    }
    .nft-footer-row .nft-genesis-label {
      flex: 0 0 auto;
      order: 1;
    }
    .nft-footer-row .purchase-btn,
    .nft-footer-row .claim-btn {
      width: 100%;
      margin-left: 0;
      order: 10;
      flex-basis: 100%;
    }
  }
}